如何从NSIS中的部分移动NSD_OnBack函数

时间:2019-01-22 07:58:42

标签: nsis

我正在编写NSIS脚本,其中使用一些部分来执行EXE文件。根据输出,我需要从该部分返回其他自定义页面,但是即使保留NSD_OnBack函数或仅调用特定函数,nsis仍将移至另一部分。

我尝试了以下2种方法。 $ {NSD_OnBack}“回调函数” 调用回调函数

//Section started
Section "validation" VALIDATION
DetailPrint "Executing Validation"
File "Folder_name\Validation.exe"
nsExec::Exec '"$INSTDIR\Validation.exe" $arg1 $arg2 $arg3'
IfFileExists "$INSTDIR\Output.txt" pass fail
pass:
FileOpen $chk "$INSTDIR\Output.txt" r
FileRead $chk $1
MessageBox MB_OK|MB_ICONSTOP "Validation_Output : in 1 $1"
Push $1
Push "true"
Call StrContains
Pop $3
${If} $3 == "true"
call someotherfunction
${ELSE}
goto fail
${ENDIF}
FileClose $chk
Delete $chk
fail:
MessageBox MB_OK|MB_ICONSTOP "fail"
//Here this call is not working 
${NSD_OnBack} "callbackfunction"
SectionEnd


Function callbackfunction
GetDlgItem $0 $HWNDPARENT 2
${IF} $portalname == "centralised"
${IF} $username == ""
    call CentralisedPage
${ENDIF}
${ELSE}
${IF} $username == ""
    call SetCustom
   ${ENDIF}
${ENDIF}
Functionend

我希望根据EXE结果移动其他页面。

1 个答案:

答案 0 :(得分:0)

${NSD_OnBack}callback for nsDialogs的自定义页面,当用户按下该页面上的“后退”按钮时将调用它,这与此处无关。

理想情况下,您应该在进入InstFiles页面之前收集所有信息,但是如果您不能这样做,那么我建议您根据需要在InstFiles页面之后显示一个自定义页面。

如果您绝对需要多次执行节,则可以使用多个InstFiles页面:

!include LogicLib.nsh
!include WinMessages.nsh
!include nsDialogs.nsh
!include Sections.nsh
!include MUI2.nsh

!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE Init1stStage
!insertmacro MUI_PAGE_INSTFILES
Page Custom MyCustomPageCreate
!define MUI_PAGE_CUSTOMFUNCTION_PRE Init2ndStage
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English

Var Needs2ndStage

Section "1st stage" SID_1
DetailPrint "1st stage"
MessageBox mb_yesno "Needs 2nd stage?" IDNO nope
    StrCpy $Needs2ndStage 1
nope:
SectionEnd

Section "-2nd stage" SID_2
DetailPrint "2nd stage"
SectionEnd

Function Init1stStage
!insertmacro UnselectSection ${SID_2}
FunctionEnd

Function Init2ndStage
!insertmacro UnselectSection ${SID_1}
${IfThen} $Needs2ndStage = 0 ${|} Abort ${|}
FunctionEnd

Function MyCustomPageCreate
${IfThen} $Needs2ndStage = 0 ${|} Abort ${|}
!insertmacro SelectSection ${SID_2}
GetDlgItem $0 $hWndParent 1
SendMessage $0 ${WM_SETTEXT} "" "STR:C&ontinue"
GetDlgItem $0 $hWndParent 3
ShowWindow $0 0 ; Hide back
GetDlgItem $0 $hWndParent 2
EnableWindow $0 0 ; Disable cancel
!insertmacro MUI_HEADER_TEXT "Blah" "Blah blah blah"
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 12u "Enter blah blah before you can enter the 2nd stage"
Pop $0
nsDialogs::Show
FunctionEnd