[译]RCStamp-将构建计数等添加到您的.rc文件
By robot-v1.0
本文链接 https://www.kyfws.com/applications/rcstamp-add-build-counts-and-more-to-your-rc-files-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2314 个词 阅读量 0[译]RCStamp-将构建计数等添加到您的.rc文件
原文地址:https://www.codeproject.com/Articles/2180/RCStamp-add-build-counts-and-more-to-your-rc-files
原文作者:peterchen
译文由本站 robot-v1.0 翻译
前言
RCStamp is a flexible command line tool to modify the FILEVERSION entries in a .rc Resource script (source included)
RCStamp是一种灵活的命令行工具,用于修改.rc资源脚本(包括源代码)中的FILEVERSION条目.
介绍(Introduction)
Windows中的文件版本号由四个位置组成,每个位置16位,例如6.0.2600.0是我的版本(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(iexplore.exe).通常,根据模块的功能,将前两个位置用作" major.minor"版本,第三个位置用于增量构建计数,第四个位置用于特殊构建. (您已经知道所有这些,不是吗?)(. 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的出现是出于在十二个二进制文件上管理相当复杂的版本控制方案的需要.它可以修改(RCStamp grew out of the necessity to manage a rather complex versioning scheme on a dozen of binaries. It can modify the) FILEVERSION
条目和" 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 *.*.+.*
这将增加第三个位置,而所有其他位置保持不变.当您将其作为自定义生成步骤集成到Visual Studio项目中时,会得到一个简单的自动生成计数器.(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
将增加第二个位置(次要版本),将第三个位置设置为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) |
n | 将位置设置为数字(set the position to the number)n(decimal) |
+n | 用数字递增位置(increment position by the number)n(decimal) |
- | 将位置减一(如果需要)(decrement position by one (if you ever need it)) |
-n | 通过数字减少位置(decrement position by the number)n(仍然是十进制,并且已经警告您)((still decimal, and you have been warned)) |
其他命令行选项:(Additonal command line options:)
-n(-n) | 不要修改" FileVersion"字符串值(don’t modify the “FileVersion” string value) |
---|---|
-rRESID | 仅修改具有资源ID RESID的版本资源(默认值:修改所有资源)(modify only the version resource with the resource id RESID (Default: modify all resources)) |
-v | 详细(回显修改后的值)(Verbose (echo the modified values)) |
-l | 处理列表文件而不是资源(请参见下文)(Process a list file instead of a resource (see below)) |
列出文件(List Files)
rcstamp @files.txt *.*.+.*
files.txt(files.txt)```text 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-自我意识开关(*-l - the Self-Awareness switch*)
### 返回值(*Return Values*)
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*)
源代码非常简单,它不依赖任何库(VC运行时除外).(*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*)
这是一个晚上(甚至一个晚上)-我没有测试所有内容(例如'-'格式规范和-l选项),存在一些潜在的缓冲区超载以及内存不足的情况它看起来很难看.文件解析是本地生成的,它并不能真正"理解" .rc文件.它只是使用(*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` .它与Visual Studio生成的.rc文件相当稳定,但是在特殊情况下它可能会失败(我什至没有深入研究.rc文档,所以我不知道允许什么).(*. 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.*)
## 许可
本文以及所有相关的源代码和文件均已获得[The Code Project Open License (CPOL)](http://www.codeproject.com/info/cpol10.aspx)的许可。
C++
VC6
WinXP
Windows
Win2K
Visual-Studio
Dev
新闻
翻译