How do I have a function in NSIS called just while compiling the script?
Question
I want to call a function (which calculates my version number) when my NSIS script is compiling, but not while it's executing. Is this possible? It uses nsExec
and basic string manipulation functions.
Solution 2
Sweet! It's possible: see http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time
The basic idea is:
- Compile a separate script that generates an executable
- Run the executable (via
!system
, at compile time) in your main script - and this generates a text file (which!define
s whatever you need) !include
the text file in your main script
and presto! You've got some stuff generated at compile time in your script.
OTHER TIPS
You could do this:
!system '"calculate_version.exe" "tempfile.tmp"'
!searchparse /file "tempfile.tmp" `APP_VERSION=` APPVERSION
What this does: calls calculate_version.exe (this could be a simple NSIS script which calls your function). This executable should output the version number to tempfile.tmp. The format of the version doesn't matter; in this example I've chosen "APP_VERSION=something" (this could be written using WriteINIStr
).
In the next line, we open the temp file and search it for the line we wrote; then we set ${APPVERSION} to whatever we find there.