Reading variables from file unseen in sections.
Hello, for some time already im using NSIS. Since now i used only hardcodded method for names and paths for the installation. Now i wanted to make universal installtion with config file, for names in my installation file. Sadly i got big issue with some variables.
Thats what i do :
MainFile.nsh
Name $AppName
!define APP_NAME $(^Name)
!define COMPANYNAME $CompanyName
Function .onInit
ClearErrors
Delete $TEMP\Company\install.log
InitPluginsDir
Push $R1
File /oname=$PLUGINSDIR\spltmp.bmp "${NSISDIR}\Contrib\Graphics\Header\splash.bmp"
advsplash::show 1000 600 400 -1 $PLUGINSDIR\spltmp
Pop $R1
Pop $R1
!insertmacro MULTIUSER_INIT
Iffileexists "$EXEDIR\setup.ini" 0 onInitNoFile
!insertmacro "ReadSetupINI"
CreateDirectory "$INSTDIR\$(^Name)"
!insertmacro Logger "INFO" "Installation started, reading setup.ini"
Iferrors 0 onInitSetLang
!insertmacro Logger "INFO" "Setup.ini read cause an error."
Goto onInitSetLang
onInitNoFile:
!insertmacro Logger "ERROR" "Setup.ini file doesn't exist loading default values"
onInitSetLang:
${SetLanguage} $Lang
StrCpy $LiczSerial "1"
!insertmacro Logger "INFO" "Language has been set up to $Lang($LANGUAGE)"
!insertmacro Logger "INFO" "Initialisation complete, proceed with user interface."
FunctionEnd
Thats where i want to read setup.ini, macroes(shorten) :
!define ReadSetupini "!insertmacro ReadSetupini"
!macro ReadSetupini
Clearerrors
${ReadSetupKey} $R0 "Startup" "CompanyName" "CompanyName"
${ReadSetupKey} $R0 "Startup" "Appname" "AppName"
${ReadSetupKey} $R0 "Startup" "ProductGUID" "ProductGUID"
${ReadSetupKey} $R0 "Languages" "Default" "Lang"
!macroend
!define ReadSetupKey "!insertmacro ReadSetupKey"
!macro ReadSetupKey Var Sect Key Def
ClearErrors
ReadINIStr ${Var} ${SETUP_INI} ${Sect} ${Key}
Var /GLOBAL ${Def}
StrCpy $${Def} "${Var}"
StrCmpS "${Key}" "CompanyName" "${Key}jump" 0
!insertmacro Logger "INFO" "Setup.ini: Definition ${Def} is set to ${Var}"
Goto "${Key}jumpend"
${Key}jump:
StrCmpS $CompanyName "" 0 +2
StrCpy $CompanyName "Ontia"
CreateDirectory $TEMP\$CompanyName
!insertmacro Logger "INFO" "Setup.ini: Definition of ${Def} wasn't set up properly, using default value"
${Key}jumpend:
!macroend
For what i see, when i copy $AppName into (^Name) i can use it anywhere. However, when i get $CompanyName from a file i can use it only in .onInit. When i get into first Section and then i call Macro Logger, it shows that $CompanyName is empty(returns $CompanyName while using MessageBox)
!define Logger "!insertmacro Logger"
!macro Logger Type Message
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
nsislog::log "$TEMP\${COMPANYNAME}\install.log" "$4:$5:$6 ${Type} ${Message}"
!macroend
whatever i use ${CompanyName} or $CompanyName its empty and returns only those ${x} / $x
If you ask why i did this that way, i need to make about 5 different installers, very similiar but i need them to read from file different values, and ReadSetupINI make it easier to use then setting variables inside MainFile.nsh.
I hope that i shown clearly what i need :)