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

How to move NSD_OnBack function from the section in NSIS

我正在写一个 NSIS 脚本,在这个脚本中使用一些部分来执行 EXE 文件。根据输出的不同,我需要从该部分返回到其他自定义页面,但这里 nsis 正在移动到另一个部分,即使保留 NSD_OnBack 函数或只是调用特定函数

我试过以下2种方法。 ${NSD_OnBack} "callbackfunction" 调用回调函数

//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 
MessageBox MB_OK|MB_ICONSTOP "Validation_Output : in 1 "
Push 
Push "true"
Call StrContains
Pop 
${If}  == "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 [=11=] $HWNDPARENT 2
${IF} $portalname == "centralised"
${IF} $username == ""
    call CentralisedPage
${ENDIF}
${ELSE}
${IF} $username == ""
    call SetCustom
   ${ENDIF}
${ENDIF}
Functionend

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

${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 [=10=] $hWndParent 1
SendMessage [=10=] ${WM_SETTEXT} "" "STR:C&ontinue"
GetDlgItem [=10=] $hWndParent 3
ShowWindow [=10=] 0 ; Hide back
GetDlgItem [=10=] $hWndParent 2
EnableWindow [=10=] 0 ; Disable cancel
!insertmacro MUI_HEADER_TEXT "Blah" "Blah blah blah"
nsDialogs::Create 1018
Pop [=10=]
${NSD_CreateLabel} 0 0 100% 12u "Enter blah blah before you can enter the 2nd stage"
Pop [=10=]
nsDialogs::Show
FunctionEnd