在 IF ELSE 块中有 InstallDir [英] Having InstallDir within IF ELSE block

查看:41
本文介绍了在 IF ELSE 块中有 InstallDir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从

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

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

我收到以下错误:-

!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

有没有办法在 if else 块中设置 InstallDir 的值?

Is there way I can set the value for InstallDir, within if else block?

推荐答案

如果你需要一个动态的 $InstDir 你根本不应该使用 InstallDir 而应该在 .onInit 中设置 $InstDir:

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

您当前的 if else 块没有任何意义,因为您选择的是 x64 上的 32 位程序文件和 x86 上的 64 位程序文件!在 x86 上使用 $PROGRAMFILES64 是可以的,所以如果你总是想要真正的"程序文件,你可以在所有平台上使用 $PROGRAMFILES64...

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...

这篇关于在 IF ELSE 块中有 InstallDir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆