【问题标题】:create custom page, after the install is complete创建自定义页面,安装完成后
【发布时间】:2019-06-19 04:50:59
【问题描述】:

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

!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 完全陌生,所以我不知道如何完成。

【问题讨论】:

  • 您的示例代码缺少所有其他页面行,您的问题是关于页面顺序!
  • 我试图放置其他页面,但随后它们被执行了两次,例如,如果您放置Page InstFiles,它将安装应用程序,然后再次触发默认安装程序并再次安装,可能是这样配置的在电子制造商中,我不知道为什么会这样。

标签: nsis electron-builder


【解决方案1】:

页面的显示顺序与它们在源文件中的显示顺序相同,因此您可以这样做:

Page Directory
Page InstFiles
Page Custom MyPage

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

【讨论】:

  • 啊我试过了,但是如果我这样做,这个安装程序会执行两次安装,由于某种原因,在自定义 MyPage 之后它再次运行默认安装程序,我想它与 electron-builder 编译它有关。
  • 有可能,我不知道 electron-builder 是如何工作的。然后你必须接受我的另一个建议,在不同的时间把收集和写作分成两个不同的步骤。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2018-11-20
    • 2012-10-05
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多