Archive: Reading config values in NSIS 2.07 and above?


Reading config values in NSIS 2.07 and above?
I am looking to read in values from a configuration file and assign these values to a particular variable. I was having a look at the ConfigRead function here, which can be used for NSIS 2.07 and below. However I'm using v2.16, so I was wondering is there an equivalent function for this later version, or what needs changed in the ConfigRead function to make it compatible with 2.16?

Thanks in advance.


That would mean that it was tested for v2.07, but that doesn't mean that it doesn't work on v2.16. Have you tried it?

There have been no big changes to the NSIS base code that this function uses. There hardly ever is, so that we can upgrade NSIS and not have to worry about updating our scripts as well.

That said, what does the format of this configuration file look like? This function works without section headers, but for those INI files with section headers, you can use ReadINIStr.

-Stu


Originally posted by Afrow UK
That would mean that it has tested for v2.07, but that doesn't mean that it doesn't work on v2.16. Have you tried it?

There have been no big changes to the NSIS base code that this function uses. There hardly ever is, so that we can upgrade NSIS and not have to worry about updating our scripts as well.

That said, what does the format of this configuration file look like? This function works without section headers, but for those INI files with section headers, you can use ReadINIStr.

-Stu
The name of the config file is 'services.properties' and the value within the file is a database username as follows:

global.database.username=my_username


Therefore I have the ConfigRead function within my script and I call it like this:

${ConfigRead} "D:\app\services.properties" "global.database.username=" $var_FL_DB_USERNAME


But when I compile the script I get the following error:

Invalid command: ${ConfigRead}
Error in script "D:\projects\Installer\Install.nsi" on line 149 -- aborting creation process


Any ideas?

Make sure you put the script code above where you call the function in your script.

-Stu


ConfigRead is in TextFunc.nsh, which is in NSIS 2.16.

RTFM "Appendix E: Useful Headers".


Originally posted by Afrow UK
Make sure you put the script code above where you call the function in your script.

-Stu
Brilliant Stu, that was it! Thank you so much!