如何在NSIS安装程序脚本中捕获没有gotos/labels的YESNOCANCEL MessageBox的结果? [英] How do I capture the results of a YESNOCANCEL MessageBox without gotos/labels in NSIS installer scripting?

查看:226
本文介绍了如何在NSIS安装程序脚本中捕获没有gotos/labels的YESNOCANCEL MessageBox的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在NSIS安装程序脚本中将YESNOCANCEL MessageBox与LogicLib.nsh中的IF逻辑结合使用,以避免必须使用标签和gotos.

I would like to know how to use a YESNOCANCEL MessageBox in conjunction with IF logic from LogicLib.nsh in NSIS installer scripting to avoid having to use labels and gotos.

有没有办法在某种变量中捕获MessageBox的结果?

Is there any way to capture the result of a MessageBox in a variable of some kind?

此外,我知道还有比NSIS更好的东西,但是目前无法使用其他东西. =(

Also, I know there are better things than NSIS out there, but using something else isn't a possibility at this point. =(

请注意以下代码中的{WHAT GOES HERE??}.如果这只是一个If ... Else ...就可以了.

Note the {WHAT GOES HERE??} in the below code. If this was just an If...Else... it would work fine.

感谢您的帮助

${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}  

更新: 我也找到了这个示例,但是我不确定${||}的作用或对我的帮助.

Update: I also found this example, but I am not sure what ${||} does or how it might help me.

  ; 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}  

推荐答案

${|}结尾的行表示if条件块,如果条件为true,则执行一条指令:

A line ending in ${|} indicates a if block that executes a single instruction if the condition is true:

${IfThen} $Instdir == $Temp ${|} MessageBox mb_ok "$$InstDir equals $$Temp" ${|}

这只是以下内容的简写语法:

This is just shorthand syntax for:

${If} $Instdir == $Temp 
    MessageBox mb_ok "$$InstDir equals $$Temp" 
${EndIf}

IfCmd宏在内部使用${IfThen} ${Cmd},而${||}是用于结束由IfCmd开始的字符串引用的黑客,所以:

The IfCmd macro uses ${IfThen} ${Cmd} internally and ${||} is a hack to end the string quote started by IfCmd, so:

${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和标签混合使用,但这是丑陋的恕我直言:

You can even mix ifthen and labels, but this is ugly IMHO:

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}语法)

(It is better to just use labels with MessageBox for YESNOCANCEL and ABORTRETRYIGNORE, for YESNO, OKCANCEL etc. that execute different code for both choices, use the ${If} ${Cmd} 'MessageBox ..' .. ${Else} .. ${EndIf} syntax)

这篇关于如何在NSIS安装程序脚本中捕获没有gotos/labels的YESNOCANCEL MessageBox的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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