使用!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