Skip to content

Instantly share code, notes, and snippets.

@johncf
Last active September 5, 2024 06:49
Show Gist options
  • Save johncf/e8f2fc74bec337ddaba30399907d9d9a to your computer and use it in GitHub Desktop.
Save johncf/e8f2fc74bec337ddaba30399907d9d9a 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
@johncf
Copy link
Author

johncf commented Jan 4, 2018

Screenshot

@jbianchini
Copy link

jbianchini commented Nov 19, 2018

Hi
How do you do to use the Var variables in a section? For example, i want to use the TextUser variable to set the database username at the Database section... something like:

Section 'DataBase' 
    ExecWait '"$PROGRAMFILES\MySQL\MySQLInstallerConsole.exe" community install 
     username=root;  <--- the TextUser information
      password=pass;'
SectionEnd

Thanks

@shahareldad
Copy link

Hi
How do you do to use the Var variables in a section? For example, i want to use the TextUser variable to set the database username at the Database section... something like:

Section 'DataBase' 
    ExecWait '"$PROGRAMFILES\MySQL\MySQLInstallerConsole.exe" community install 
     username=root;  <--- the TextUser information
      password=pass;'
SectionEnd

Thanks

You can see in PgPageLeave that $TextUser is assign to $0.
In a section you simply call $0 to use the value.

@Ladvace
Copy link

Ladvace commented Apr 16, 2020

is there anyway to customize also other page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment