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

时间:2019-01-25 10:52:25

标签: nsis electron-builder

我正在处理一个脚本,该脚本正在安装用电子制作的应用程序,到目前为止,一切似乎都工作正常。但是,有一个问题,我能够添加新的自定义页面,但是它是在安装之前添加的。这是一个问题,因为此页面包含两个输入字段,用户必须填写这些输入字段,然后将提供的数据存储在安装了app的目录中。但是由于在此步骤之后安装了应用程序,因此目录将被覆盖并且文件消失了。这是代码:

!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 $1 $UserState
    StrCpy $2 $PassState

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

FunctionEnd

Section
SectionEnd

是的,最好的做法是在安装后而不是之前安装此页面。谢谢您的全方位指导,我是NSIS的新手,所以我不知道如何实现这一目标。

2 个答案:

答案 0 :(得分:1)

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

Page Directory
Page InstFiles
Page Custom MyPage

理想情况下,您应该在安装步骤(InstFiles)之前收集所需的信息,并且您已经快要准备好了。您的自定义页面将信息存储在全局变量中,您要做的就是将File*操作移至Section。如果您采用这种方式,则您的自定义页面可以在InstFiles页面之前的任何时间出现。

答案 1 :(得分:0)

安装前有customPageAfterChangeDir macros可以更改为插入页面,安装后有customFinishPage macros。 示例 if 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
相关问题