The presence of InstallDir in the IF ELSE block

I am trying to get the following code from

; The default installation directory InstallDir $PROGRAMFILES\${PRODUCT_NAME} 

to

 !include x64.nsh ${If} ${RunningX64} ; The default installation directory InstallDir $PROGRAMFILES\${PRODUCT_NAME} ${Else} ; The default installation directory InstallDir $PROGRAMFILES64\${PRODUCT_NAME} ${EndIf} 

I get the following error: -

 !insertmacro: _If Error: Can't add entry, no section or function is open! Error in macro _RunningX64 on macroline 2 Error in macro _If on macroline 9 Error in script "C:\Users\yccheok\Desktop\mysoftware.nsi" on line 17 -- aborting creation process 

Is there a way to set the value for InstallDir inside an if else block?

+6
source share
1 answer

If you need dynamic $ InstDir, you should not use InstallDir at all, but install $ InstDir in .onInit:

 Installdir "" !include LogicLib.nsh !include x64.nsh Function .onInit ${If} $InstDir == "" ; /D= was not used on the command line ${If} ${RunningX64} StrCpy $InstDir "c:\foo" ${Else} StrCpy $InstDir "c:\bar" ${EndIf} ${EndIf} FunctionEnd 

Your current if else block makes no sense, because you select 32-bit program files on x64 and 64-bit program files on x86! It is normal to use $ PROGRAMFILES64 on x86, so if you always want "real" program files, you can use $ PROGRAMFILES64 for all platforms ...

+9
source

Source: https://habr.com/ru/post/902531/


All Articles