创建自定义页面,安装完成后

create custom page, after the install is complete

我正在编写一个脚本来安装我用 electron 制作的应用程序,到目前为止一切似乎都运行良好。但是有一个问题,我能够添加新的自定义页面,但它是在安装之前添加的。这是一个问题,因为此页面包含两个用户必须填写的输入字段,然后提供的数据存储在安装应用程序的目录中。但是因为在这一步之后安装了应用程序,所以目录被覆盖并且文件消失了。这是代码:

!include nsDialogs.nsh
!include LogicLib.nsh

XPStyle on

Var Dialog
Var UserLabel
Var UserText
Var UserState
Var PassLabel
Var PassText
Var PassState

Page custom nsDialogsPage nsDialogsPageLeave

Function nsDialogsPage

    nsDialogs::Create 1018
    Pop $Dialog

    ${If} $Dialog == error
        Abort
    ${EndIf}

    ${NSD_CreateLabel} 0 0 100% 12u "Username:"
    Pop $UserLabel

    ${NSD_CreateText} 0 13u 100% 12u $UserState
    Pop $UserText

    ${NSD_CreateLabel} 0 39u 100% 12u "Password:"
    Pop $PassLabel

    ${NSD_CreatePassword} 0 52u 100% 12u $PassState
    Pop $PassText

    nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave

    ${NSD_GetText} $UserText $UserState
    ${NSD_GetText} $PassText $PassState

    ${If} $UserState == ""
        MessageBox MB_OK "Username is missing."
        Abort
    ${EndIf}

    ${If} $PassState == ""
        MessageBox MB_OK "Password is missing."
        Abort
    ${EndIf}

    StrCpy  $UserState
    StrCpy  $PassState

    FileOpen  $INSTDIR\credentials.txt w
    FileWrite  ":"
    FileClose 
    SetFileAttributes $INSTDIR\credentials.txt HIDDEN|READONLY

FunctionEnd

Section
SectionEnd

所以是的,最好是在安装之后而不是之前有这个页面。感谢您提供的所有指导,我是 NSIS 的新手,所以我不知道如何完成此操作。

页面的显示顺序与它们在源文件中的显示顺序相同,因此您只需执行以下操作:

Page Directory
Page InstFiles
Page Custom MyPage

理想情况下,您应该在安装步骤 (InstFiles) 之前收集所需的信息,并且您已经快完成了。您的自定义页面将信息存储在全局变量中,您所要做的就是将 File* 操作移动到 Section。如果您这样做,那么您的自定义页面可以随时出现在 InstFiles 页面之前。

安装后有customPageAfterChangeDir macros you can change to insert page before install and customFinishPage macros个。 例如 installer.nsh

!include nsDialogs.nsh

!macro customPageAfterChangeDir
Page custom customPageCreator customPageLeave "Custom page caption"

Var Dialog

Function customPageCreator
    nsDialogs::Create 1018
    Pop $Dialog
    
    ${If} $Dialog == error
        Abort
    ${EndIf} 
    
    MessageBox MB_OK "customPageCreator"

    nsDialogs::Show
FunctionEnd

Function customPageLeave
    MessageBox MB_OK "customPageLeave"
FunctionEnd
!macroend