使用!searchparse
,!searchreplace
和!define /math
阅读在编译时/操控版本号:
!searchparse /file "c:\some\path\version.h" `#define APPLICATION_VERSION "` VERSION `"`
下一个示例使用的是临时文件,以便它可以在没有外部的依赖关系进行测试:
!tempfile testhdr
!appendfile "${testhdr}" "#ifndef VERSION_H$\n"
!appendfile "${testhdr}" "#define VERSION_H$\n"
!appendfile "${testhdr}" '#define APPLICATION_VERSION "1.2.3"$\n'
!appendfile "${testhdr}" "#endif$\n"
!searchparse /file "${testhdr}" `#define APPLICATION_VERSION "` VER_MAJOR `.` VER_MINOR `.` VER_BUILD `"`
!searchparse /file "${testhdr}" `#define APPLICATION_VERSION "` VER_STRING `"`
!delfile "${testhdr}" ; Cleanup
!warning "${VER_MAJOR}, ${VER_MINOR}, ${VER_BUILD}"
!error "${VER_STRING}"
也可以使用既是有效的C也是NSIS代码的定义来编写标题:
#define /*
!define /**/ \
FOO "Bar"
此代码似乎创建了一个临时文件...您能提供一个从现有文件中读取文本的例子,就像我的问题一样吗? – bdesham 2014-11-05 13:26:55
这只是为了让这个例子在没有外部文件的机器上工作,只需用'!searchparse/file“c:\ foo \ bar \ version.h”'替换'!searchparse/file“$ {testhdr}删除所有与testhdr相关的代码... – Anders 2014-11-05 13:29:08