Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having InstallDir within IF ELSE block

Tags:

nsis

I try to have 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 way I can set the value for InstallDir, within if else block?

like image 516
Cheok Yan Cheng Avatar asked Nov 28 '11 10:11

Cheok Yan Cheng


1 Answers

If you need a dynamic $InstDir you should not use InstallDir at all but set $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 does not make any sense because you are selecting the 32 bit program files on x64 and the 64 bit program files on x86! It is OK to use $PROGRAMFILES64 on x86 so if you always want the "real" program files you can use $PROGRAMFILES64 for all platforms...

like image 74
Anders Avatar answered Sep 25 '22 09:09

Anders