开发者

How do I capture the results of a YESNOCANCEL MessageBox without gotos/labels in NSIS installer scripting?

I would like to know how to use a YESNOCANCEL MessageBox in conjunction with IF logic from LogicLib.nsh in NSIS installer scrip开发者_如何学Pythonting to avoid having to use labels and gotos.

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

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

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

Thanks for the help

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


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}

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

is shorthand for:

${If} ${Cmd} 'MessageBox MB_YESNO "yes" IDYES' ;notice the quotes here
    MessageBox mb_ok choice=IDYES
${EndIf}

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:

(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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜