问题
I am working on a script that is installing my application made in electron and so far all seems to be working fine. There is one problem however, i was able to add new custom page, but it is added before the install is taking place. It is a problem because this page contains two input fields which user must fill and then the provided data is stored in directory where app is installed. But because app is installed after this step, directory gets overwritten and file is gone. This is the code:
!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
So yes the best would be to have this page after the installation, not before. Thank you for all the directions, i am totally new to NSIS so i have no clue how to accomplish this.
回答1:
Pages are displayed in the same order as they appear in your source file so you can just do:
Page Directory
Page InstFiles
Page Custom MyPage
Ideally you should collect the required information before the installation step (InstFiles
) and you are almost there already. Your custom page is storing the information in global variables, all you have to do is to move the File*
operations to a Section
. If you do it this way then your custom page can appear any time before the InstFiles
page.
来源:https://stackoverflow.com/questions/54363814/create-custom-page-after-the-install-is-complete