Reputation: 2941
I want to read some values from a file (config.json) into some variables when I compile my nsis script. How can I possibly do that?
Thanks in advance.
Upvotes: 4
Views: 2900
Reputation: 81
You may use the !searchparse command with the /file switch.
Example :
# search filename.cpp for a line '#define APP_VERSION "2.5"' and set ${VER_MAJOR} to 2, ${VER_MINOR} to 5.
!searchparse /file filename.cpp `#define APP_VERSION "` VER_MAJOR `.` VER_MINOR `"`
Upvotes: 1
Reputation: 4048
If you just need to parse your json file on runtime, you can use !define
with the /file
option:
!define /file OPTIONS json.txt
It will define OPTIONS with the content of json.txt.
If you want to utilize your json file in compile time to alter the generated exe, then you need some kind of precompiler, which is what you're actually doing.
Upvotes: 1
Reputation: 6516
You can use !define
to pass some value which can be used in compile time. For example lets imagine that you have got this code in you nsis source file:
!define PATHTOFILE "C:\thisfilewillbedeleted.ext"
Delete $PATHTOFILE
If you want to change this walue on compile time you can call nsis in this way:
makensis /DPATHTOFILE="C:\otherfiletodelete.ext"
[EDIT]
If you got *.json file which is generated using external tool and you must use this kind of file I will suggest you to use some building system, for example ant
. You can create build.xml
which read, parse data from json file and then write those data to *.nsh
file. I think it will be better and cleaner than do it all in nsis script.
Upvotes: 1
Reputation: 11465
The !include
command can include any file (at compile time) at the point where it is placed in the nsis script. But the included file must be compliant with the nsis syntax (e.g. it should !define
some values).
The !execute
command could help you: if you need absolutely to process a json file you could code a third-party batch command file to pre-process the json file and translate it into a suitable nsis file.
Upvotes: 6