Skip to content

Instantly share code, notes, and snippets.

@njmube
Forked from johncf/mui2-custompage-nsd.nsi
Created December 28, 2020 21:41
Show Gist options
  • Save njmube/3a59fe95e02efe30be231db0fcad3ccc to your computer and use it in GitHub Desktop.
Save njmube/3a59fe95e02efe30be231db0fcad3ccc to your computer and use it in GitHub Desktop.
NSIS Example using MUI2 with a custom page built with NsDialogs.
!include nsDialogs.nsh
!include LogicLib.nsh
!include MUI2.nsh
Name nsDialogs
OutFile nsDialogs.exe
RequestExecutionLevel user
ShowInstDetails show
Var Dialog
Var TextUser
Var TextPass
Var TextDbName
Var TextPgDir
Page custom pgPageCreate pgPageLeave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function pgPageCreate
!insertmacro MUI_HEADER_TEXT "Database Settings" "Provide PostgreSQL config and install directory."
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateGroupBox} 10% 10u 80% 62u "PostgreSQL Database Settings"
Pop $0
${NSD_CreateLabel} 20% 26u 20% 10u "Username:"
Pop $0
${NSD_CreateText} 40% 24u 40% 12u "postgres"
Pop $TextUser
${NSD_CreateLabel} 20% 40u 20% 10u "Password:"
Pop $0
${NSD_CreatePassword} 40% 38u 40% 12u ""
Pop $TextPass
${NSD_CreateLabel} 20% 54u 20% 10u "New Database:"
Pop $0
${NSD_CreateText} 40% 52u 40% 12u "mydb"
Pop $TextDbName
${NSD_CreateGroupBox} 5% 86u 90% 34u "PostgreSQL Install Path"
Pop $0
${NSD_CreateDirRequest} 15% 100u 49% 12u "$PROGRAMFILES64\PostgreSQL\10"
Pop $TextPgDir
${NSD_CreateBrowseButton} 65% 100u 20% 12u "Browse..."
Pop $0
${NSD_OnClick} $0 OnDirBrowse
nsDialogs::Show
FunctionEnd
Function OnDirBrowse
${NSD_GetText} $TextPgDir $0
nsDialogs::SelectFolderDialog "Select Postgres Directory" "$0"
Pop $0
${If} $0 != error
${NSD_SetText} $TextPgDir "$0"
${EndIf}
FunctionEnd
Function PgPageLeave
${NSD_GetText} $TextUser $0
${NSD_GetText} $TextPass $1
${NSD_GetText} $TextDbName $2
${NSD_GetText} $TextPgDir $3
MessageBox MB_OK "User: $0, Pass: $1, Db: $2, PgDir: $3"
FunctionEnd
Section
DetailPrint "Hello, World!"
SectionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment