Click here to Skip to main content
15,880,503 members
Articles / Programming Languages / C++
Article

RCStamp - add build counts and more to your .rc files

Rate me:
Please Sign up or sign in to vote.
4.87/5 (22 votes)
23 Apr 2002CPOL3 min read 143.6K   2.6K   45   33
RCStamp is a flexible command line tool to modify the FILEVERSION entries in a .rc Resource script (source included)

Introduction

File Version numbers in Windows consist of four positions with 16 bits each, e.g. 6.0.2600.0 is the version of my iexplore.exe. Typically you use the first two positions as "major.minor" version, based on the features of the module, the third position for an incremental build count, and the fourth for special builds. (You already knew all this, didn't you?)

RCStamp grew out of the necessity to manage a rather complex versioning scheme on a dozen of binaries. It can modify the FILEVERSION entry and the "FileVersion" string entry in a VERSIONINFO resource. It uses a format string that can affect the four positions of the version number individually. A typical call looks like this:

rcstamp myproject.rc *.*.+.*

This would increment the third position, and leave all others unmodified. You get a simple automatic build counter when you integrate this as custom build step into your Visual Studio project.

A more complex call:

rcstamp myproject.rc *.+.0.+1000

would increment the second position (minor version), set the third position to 0, and increment the fourth by 1000.

Command line options:

rcstamp file <format> [<options>...]
rcstamp @file [<format>] [<options>...]

Format options:

*leave position as-is
+increment position by one
nset the position to the number n (decimal)
+nincrement position by the number n (decimal)
-decrement position by one (if you ever need it)
-ndecrement position by the number n (still decimal, and you have been warned)

Additonal command line options:

-ndon't modify the "FileVersion" string value
-rRESIDmodify only the version resource with the resource id RESID (Default: modify all resources)
-vVerbose (echo the modified values)
-lProcess a list file instead of a resource (see below)

List Files

For batch processing, you can specify a text file containing a list of file names, like this:
rcstamp @files.txt *.*.+.*
files.txt could look like this:
c:\sources\hamlet\hamlet.rc
c:\sources\ophelia\ophelia.rc=*.*.0.+
c:\sources\laertes\laertes.rc

You can add a format for an individual file (separated by a '=') to override the format specified at the command line.

-l - the Self-Awareness switch

The -l option allows to modify a list file like the one above, instead of a resource script. This is far from useful, since all special formattings will be rendered as 0, and I suspect a bug there. But it's a perfect example of the useless features you spend late hours with.

Return Values

Since it's intended for batching, there are some errorlevel's to evaluate:
ERRORLEVEL 3 : invalidarguments
ERRORLEVEL 1 : an error occured when processing at least
      one file (error message written to stderr)
ERRORLEVEL 0 : everything's fine

Source

The sources are pretty straightforward, it doesn't rely on any library (besides the VC runtime). main() clobbers the command line, and then processes either the specified file, or opens the file list and processes each of the files. ParseArg() will analyze one command line parameter at a time, and store it's findings in global variables. ProcessFile() will process a single file according to the options set. CalcNewVersion() calculates the new file version from a string containing the old one and a format specifier.

The files are read with std::ifstream line-by-line, The modified text is collected in a std::string, and then the entire file is overwritten.

Issues

This is a one-nighter (a half-nighter, even) - I didn't test everything (e.g. the '-' format specification, and the -l option), there are some potential buffer overruns and when you run out of memory it will look ugly. The file parsing is homegrown, it doesn't really "understand" the .rc file; it just looks for certain tokens, using of strdup and strtok. it is fairly stable with the .rc files produced by Visual Studio, but it might fail in exotic cases (I didn't even dive into the .rc documentation so I don't know what is allowed).

Oh, and you might already have guessed - you can't decrement the first position, since the leading '-' is interpreted as option. Since this tool is in daily use (I use it now for the daily builds at work, and for preparing releases) I for sure will fix the bugs that appear in the features I need. Beyond that, it's up to you - at least, up to your persuasion skills.

Enjoy.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Klippel
Germany Germany
Peter is tired of being called "Mr. Chen", even so certain individuals insist on it. No, he's not chinese.

Peter has seen lots of boxes you youngsters wouldn't even accept as calculators. He is proud of having visited the insides of a 16 Bit Machine.

In his spare time he ponders new ways of turning groceries into biohazards, or tries to coax South American officials to add some stamps to his passport.

Beyond these trivialities Peter works for Klippel[^], a small german company that wants to make mankind happier by selling them novel loudspeaker measurement equipment.


Where are you from?[^]



Please, if you are using one of my articles for anything, just leave me a comment. Seeing that this stuff is actually useful to someone is what keeps me posting and updating them.
Should you happen to not like it, tell me, too

Comments and Discussions

 
GeneralRe: Naming output files according to version/build numbers Pin
peterchen5-May-05 11:34
peterchen5-May-05 11:34 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner5-May-05 12:20
Beau Skinner5-May-05 12:20 
GeneralRe: Naming output files according to version/build numbers Pin
peterchen5-May-05 12:30
peterchen5-May-05 12:30 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner6-May-05 23:22
Beau Skinner6-May-05 23:22 
GeneralRe: Naming output files according to version/build numbers Pin
peterchen7-May-05 1:13
peterchen7-May-05 1:13 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner7-May-05 12:58
Beau Skinner7-May-05 12:58 
GeneralRe: Naming output files according to version/build numbers Pin
Beau Skinner6-May-05 23:04
Beau Skinner6-May-05 23:04 
GeneralFormat differences... Pin
rbid26-Nov-04 23:50
rbid26-Nov-04 23:50 
GeneralRe: Format differences... Pin
peterchen27-Nov-04 22:55
peterchen27-Nov-04 22:55 
GeneralRCStamp appends empty lines at the end of the target file Pin
Thomas Haase17-Mar-04 23:20
Thomas Haase17-Mar-04 23:20 
Generalfix Pin
peterchen16-Apr-04 14:05
peterchen16-Apr-04 14:05 
GeneralImprovement Pin
Anonymous16-Aug-02 23:14
Anonymous16-Aug-02 23:14 
GeneralRe: Improvement Pin
Ddub8-Mar-03 15:25
Ddub8-Mar-03 15:25 
GeneralRe: Improvement Pin
Suhn11-Feb-06 9:40
Suhn11-Feb-06 9:40 
GeneralRe: Improvement Pin
advance51218-Jun-09 3:21
advance51218-Jun-09 3:21 
GeneralA question Pin
User 988524-Apr-02 11:53
User 988524-Apr-02 11:53 
GeneralRe: Integrating as Auto-Build counter in VC++ 6 Pin
peterchen25-Apr-02 2:18
peterchen25-Apr-02 2:18 
GeneralA question Pin
Ddub8-Mar-03 15:32
Ddub8-Mar-03 15:32 
Generalnice but.... Pin
Mario M.24-Apr-02 11:06
Mario M.24-Apr-02 11:06 
GeneralRe: nice but.... Pin
peterchen24-Apr-02 11:48
peterchen24-Apr-02 11:48 
GeneralRe: nice but.... Pin
Mario M.24-Apr-02 13:52
Mario M.24-Apr-02 13:52 
GeneralRe: nice but.... Pin
peterchen25-Apr-02 2:20
peterchen25-Apr-02 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.