我想知道如何在NSIS安装程序脚本中使用YESNOCANCEL MessageBox和LogicLib.nsh的IF逻辑,以避免使用标签和gotos。
有没有办法在某种变量中捕获MessageBox的结果?
另外,我知道有比NSIS更好的东西,但是在这一点上使用别的东西是不可能的。 =(
请注意以下代码中的{WHAT GOES HERE??}
。如果这只是一个If ... Else ......它会正常工作。
感谢您的帮助
${If} ${Cmd} `MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION
"PROGRAM X is already installed. Click YES to remove the installed version
found in C:\Program Files(x86). Click NO to skip uninstall and choose a
different install location (not recommended) or CANCEL to terminate
the installer." IDYES`
MessageBox MB_OK "Yes was clicked"
${ElseIf} {WHAT GOES HERE??}
MessageBox MB_OK "No was clicked"
${Else}
MessageBox MB_OK "Cancel was clicked"
${EndIf}
更新:
我也找到了这个例子,但我不确定${||}
做了什么或它对我有什么帮助。
; ifcmd..||..| and if/unless cmd
StrCpy $R2 ""
${IfCmd} MessageBox MB_YESNO "Please click Yes" IDYES ${||} StrCpy $R2 $R2A ${|}
${Unless} ${Cmd} `MessageBox MB_YESNO|MB_DEFBUTTON2 "Please click No" IDYES`
StrCpy $R2 $R2B
${EndUnless}
${If} $R2 == "AB"
DetailPrint "PASSED IfCmd/If Cmd test"
${Else}
DetailPrint "FAILED IfCmd/If Cmd test"
${EndIf}
答案 0 :(得分:7)
以${|}
结尾的行表示如果条件为真,则执行单个指令的if块:
${IfThen} $Instdir == $Temp ${|} MessageBox mb_ok "$$InstDir equals $$Temp" ${|}
这只是以下的简写语法:
${If} $Instdir == $Temp
MessageBox mb_ok "$$InstDir equals $$Temp"
${EndIf}
IfCmd宏在内部使用${IfThen} ${Cmd}
,${||}
是一个黑客来结束由IfCmd启动的字符串引用,所以:
${IfCmd} MessageBox MB_YESNO "click yes" IDYES ${||} MessageBox mb_ok choice=IDYES ${|}
是:
的简写${If} ${Cmd} 'MessageBox MB_YESNO "yes" IDYES' ;notice the quotes here
MessageBox mb_ok choice=IDYES
${EndIf}
你甚至可以混合ifthen和标签,但这是丑陋的恕我直言:
StrCpy $0 "Cancel"
${IfCmd} MessageBox MB_YESNOCANCEL "Mr. Powers?" IDYES yes IDNO ${||} StrCpy $0 "NO?!" ${|}
MessageBox mb_iconstop $0 ;Cancel or NO
goto end
yes:
MessageBox mb_ok "Yeah baby yeah!"
end:
(最好只使用带有MessageBox的标签用于YESNOCANCEL和ABORTRETRYIGNORE,对于YESNO,OKCANCEL等执行两种选择的不同代码,使用$ {If} $ {Cmd}'MessageBox ..'.. $ {Else} .. $ {EndIf}语法)