I want to create a checkbox in NSIS at the end of the installation process, when checked, it will lead the user to a custom page that has a bunch of radioboxes that lead the user to another custom page (depending on the choice) and so on.
I know how to create a custom page using nsDialogs, but I can't figure out the logic behind multiple optional custom pages. Any help is appreciated.
Alternatively, is there a way to create multiple checkbox/radiobox groups that are disabled by default (except the first one) and only activated when the user selects a box in a group before it?
Pages are skipped by calling Abort in the page Pre-callback. Then all you have to do is keep track of which page you want to show and which you want to skip:
!include nsDialogs.nsh
!include LogicLib.nsh
Section "Do custom page thing" SID_DOCUSTOMPAGES
SectionEnd
Page Components
Page InstFiles
Page Custom Cust1Pre Cust2Next
Page Custom CustAPre
Page Custom CustBPre
Var WantedPage
Function Cust1Pre
${IfNot} ${SectionIsSelected} ${SID_DOCUSTOMPAGES}
StrCpy $WantedPage ""
Abort
${EndIf}
nsDialogs::Create 1018
Pop $0
${NSD_CreateRadioButton} 0 30u 100% 10u "Page A"
Pop $1
${NSD_Check} $1
${NSD_CreateRadioButton} 0 40u 100% 10u "Page B"
Pop $2
nsDialogs::Show
FunctionEnd
Function Cust2Next
${NSD_GetState} $1 $0
${If} $0 <> ${BST_UNCHECKED}
StrCpy $WantedPage A
${Else}
StrCpy $WantedPage B
${EndIf}
FunctionEnd
Function CustAPre
${IfNotThen} $WantedPage == A ${|} Abort ${|}
GetDlgItem $0 $hWndParent 1
SendMessage $0 ${WM_SETTEXT} "" "STR:$(^CloseBtn)" ; Change button text since page B is skipped and we are now the last page
nsDialogs::Create 1018
Pop $0
${NSD_CreateButton} 0 30u 100% 10u "Page A"
Pop $0
nsDialogs::Show
FunctionEnd
Function CustBPre
${IfNotThen} $WantedPage == B ${|} Abort ${|}
nsDialogs::Create 1018
Pop $0
${NSD_CreateButton} 0 30u 100% 10u "Page B"
Pop $0
nsDialogs::Show
FunctionEnd
You can get rid of the WM_SETTEXT workaround by having a single page that is "A" or "B":
!include nsDialogs.nsh
!include LogicLib.nsh
Section "Do custom page thing" SID_DOCUSTOMPAGES
SectionEnd
Page Components
Page InstFiles
Page Custom Cust1Pre Cust2Next
Page Custom CustAOrBPre
Var WantedPage
Function Cust1Pre
${IfNot} ${SectionIsSelected} ${SID_DOCUSTOMPAGES}
StrCpy $WantedPage ""
Abort
${EndIf}
nsDialogs::Create 1018
Pop $0
${NSD_CreateRadioButton} 0 30u 100% 10u "Page A"
Pop $1
${NSD_Check} $1
${NSD_CreateRadioButton} 0 40u 100% 10u "Page B"
Pop $2
nsDialogs::Show
FunctionEnd
Function Cust2Next
${NSD_GetState} $1 $0
${If} $0 <> ${BST_UNCHECKED}
StrCpy $WantedPage A
${Else}
StrCpy $WantedPage B
${EndIf}
FunctionEnd
Function CustAPre
nsDialogs::Create 1018
Pop $0
${NSD_CreateButton} 0 30u 100% 10u "Page A"
Pop $0
nsDialogs::Show
FunctionEnd
Function CustBPre
nsDialogs::Create 1018
Pop $0
${NSD_CreateButton} 0 30u 100% 10u "Page B"
Pop $0
nsDialogs::Show
FunctionEnd
Function CustAOrBPre
${If} $WantedPage == A
Call CustAPre
${Else}
Call CustBPre
${EndIf}
FunctionEnd
Having just a single page with disabled options is of course better:
!include nsDialogs.nsh
!include LogicLib.nsh
Page InstFiles
Page Custom CustPre
Function CustPre
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckBox} 10 30u 100% 10u "Enable other stuff"
Pop $0
${NSD_OnClick} $0 OnCheckChange
${NSD_CreateRadioButton} 10 50u 100% 10u "Foo"
Pop $1
${NSD_AddStyle} $1 ${WS_GROUP}
${NSD_Check} $1
${NSD_CreateRadioButton} 10 70u 100% 10u "Bar"
Pop $2
${NSD_RemoveStyle} $2 ${WS_TABSTOP}
Push $0
Call OnCheckChange ; Enforce state
nsDialogs::Show
FunctionEnd
!macro SetRadiosEnabled state
EnableWindow $1 ${state}
EnableWindow $2 ${state}
!macroend
Function OnCheckChange
Pop $0
${NSD_GetState} $0 $0
${If} $0 <> ${BST_UNCHECKED}
!insertmacro SetRadiosEnabled 1
${Else}
!insertmacro SetRadiosEnabled 0
${EndIf}
FunctionEnd
Related
I use the MUI_PAGE_INSTFILES. And this page has normally a finish-button, but I have a custom page after it. But I want that you could still finish the installer before the custom page and the next page is only optional. I could also show more code if wished.
!include "MUI2.nsh"
!insertmacro MUI_PAGE_LICENSE $(license)
!insertmacro MUI_PAGE_INSTFILES
Page custom TestSettings
At the moment I have a previous-, next- and cancel-button at the instfile page. But I want a prev-, next- and finish-button.
NSIS was never designed to support this but with the ButtonEvent plug-in you can make it work. I'm just not sure if it makes sense because if the last page is important then some users might skip the page by accident because they are not paying attention.
!include MUI2.nsh
!insertmacro MUI_PAGE_LICENSE $(license)
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstFilesLeave
!insertmacro MUI_PAGE_INSTFILES
Page custom TestSettings
!insertmacro MUI_LANGUAGE English
!include WinMessages.nsh
!include nsDialogs.nsh
Function InstFilesLeave
GetDlgItem $0 $hWndParent 2
ShowWindow $0 0
System::Call 'USER32::GetWindowRect(pr0,#r1)' ; NSIS 3+
System::Call 'USER32::MapWindowPoints(p0,p $hWndParent, p $1, i 2)'
System::Call '*$1(i.r2,i.r3,i.r4,i.r5)'
IntOp $4 $4 - $2
IntOp $5 $5 - $3
!define IDC_MYFINISHBTN 1337
System::Call 'USER32::CreateWindowEx(i 0, t "BUTTON", t "&Finish", i ${DEFAULT_STYLES}|${WS_TABSTOP}, ir2, ir3, i r4, i r5, p $hWndParent, p ${IDC_MYFINISHBTN}, p 0, p 0)p.r1'
SendMessage $0 ${WM_GETFONT} "" "" $0
SendMessage $1 ${WM_SETFONT} $0 1
GetFunctionAddress $0 OnFinishButton
ButtonEvent::AddEventHandler ${IDC_MYFINISHBTN} $0
FunctionEnd
Var JustFinish
Function OnFinishButton
StrCpy $JustFinish 1
SendMessage $hWndParent ${WM_COMMAND} 1 ""
FunctionEnd
Function TestSettings
StrCmp $JustFinish "" +2
Return
GetDlgItem $0 $hWndParent ${IDC_MYFINISHBTN}
ShowWindow $0 0
GetDlgItem $0 $hWndParent 2
ShowWindow $0 1
!insertmacro MUI_HEADER_TEXT "Configure" "Blah blah blah"
nsDialogs::Create 1018
Pop $0
; ...
nsDialogs::Show
FunctionEnd
If your custom page just contains a couple of checkboxes then you can use the MUI Finish page with custom texts instead.
I have a some different license pages with check box on it. The Next button should be disabled if check box is unchecked. Is there an event that I can use if checkbox state changed? Here is my code of one of this
var Window
var labelDescription
var checkBoxIsUserAgree
Function CreateCustomLicense1
nsDialogs::Create 1018
Pop $Window
GetDlgItem $0 $HWNDPARENT
EnableWindow $0 0
${NSD_CreateLabel} 13u 22u 270u 96u "Description"
Pop $labelDescription
${NSD_CreateCheckBox} 10u 110u 100u 15u "I Agree"
$checkBoxIsUserAgree
FunctionEnd
Function ShowCustomLicence1
Call CreateCustomLicense1
nsDialogs::Show
Function
Function .oncheckBoxIsUserAgreeStateChanged ; what event I can use for track checkbox state changing
EnableWindow $0 1
FunctionEnd
The built-in NSIS license page supports a checkbox and can be used multiple times but if you insist on creating a custom page you just have to add a on* handler:
!include nsDialogs.nsh
Var checkBoxIsUserAgree
Function ShowCustomLicence1
nsDialogs::Create 1018
Pop $1
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 0
${NSD_CreateLabel} 13u 22u 270u 90u "Description"
Pop $1
${NSD_CreateCheckBox} 10u 110u 100u 15u "I Agree"
Pop $checkBoxIsUserAgree
${NSD_OnClick} $checkBoxIsUserAgree oncheckBoxIsUserAgreeStateChanged1
nsDialogs::Show
FunctionEnd
Function oncheckBoxIsUserAgreeStateChanged1
Pop $1 ; Throw away parameter
${NSD_GetState} $checkBoxIsUserAgree $1
EnableWindow $0 $1
FunctionEnd
Page Custom ShowCustomLicence1
Page InstFiles
Can anyone explain to me, why ${NSD_GetState} $Checkbox is not working ?
I lost about 4 hours trying to find out what is wrong. I tried diffrent variants but in THIS script they are not working.
Actualy it is my first attempt to make a nsis installer, so I even dont know where should I look for mistake or I just dont understand the logic of this language.
From Russia with love :)
And sorry for my bad english
!define NAME "Simple LiveUSB installer"
!define FILENAME "USB"
!define VERSION "v0.1"
Name "${NAME} ${VERSION}"
OutFile "${FILENAME}.exe"
SetCompressor LZMA
ShowInstDetails hide
XPStyle on
!include MUI2.nsh
!include FileFunc.nsh
!include nsDialogs.nsh
;!include LogicLib.nsh
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\HEADER2.bmp"
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\media-floppy.ico"
Page custom drivePage
Page custom Var123
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "Russian"
LangString DrivePage_Title ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Title2 ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Text ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Text2 ${LANG_RUSSIAN} "Format"
LangString DrivePage_Input ${LANG_RUSSIAN} "Choose"
Var Label
Var Label2
Var Checkbox
;Var Checkbox_State
Var DestDriveHW
Var DestDrive
# Functions #######################################
Function drivePage
!insertmacro MUI_HEADER_TEXT $(DrivePage_Title) $(DrivePage_Title2)
nsDialogs::Create 1018
${If} $DestDrive == ""
GetDlgItem $6 $HWNDPARENT 1
EnableWindow $6 0
${EndIf}
${NSD_CreateLabel} 0 0 100% 160 $(DrivePage_Text)
Pop $Label
${NSD_CreateLabel} 10 182 100% 15 $(DrivePage_Input)
Pop $Label2
${NSD_CreateDroplist} 10 200 13% 20 ""
Pop $DestDriveHw
${NSD_OnChange} $DestDriveHw db_select.onchange
${GetDrives} "FDD" driveListFiller
${If} $DestDrive != ""
${NSD_CB_SelectString} $DestDriveHw $DestDrive
${EndIf}
${NSD_CreateCheckbox} 80 203 100% 10u $(DrivePage_Text2)
Pop $Checkbox
${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox_State
${EndIf}
nsDialogs::Show
FunctionEnd
Function db_select.onchange
Pop $DestDriveHw
${NSD_GetText} $DestDriveHw $0
StrCpy $DestDrive "$0"
GetDlgItem $6 $HWNDPARENT 1
EnableWindow $6 1
FunctionEnd
Function driveListFiller
SendMessage $DestDriveHw ${CB_ADDSTRING} 0 "STR:$9"
Push 1
FunctionEnd
Function Var123
Pop $Checkbox
MessageBox mb_ok "FIN Checkbox_State=$Checkbox_State Checkbox=$Checkbox"
${NSD_GetState} $Checkbox $0
${If} $0 <> 0
MessageBox mb_ok "Custom checkbox was checked... N=$0"
${EndIf}
${If} $0 == 0
MessageBox mb_ok "Custom checkbox ZERO... N=$0"
${EndIf}
Functionend
# Section #######################################
Section "" main
InitPluginsDir
File /oname=$PLUGINSDIR\syslinux.cfg "${NSISDIR}\plugins\syslinux.cfg"
File /oname=$PLUGINSDIR\syslinux.exe "${NSISDIR}\plugins\syslinux.exe"
File /oname=$PLUGINSDIR\nsExec.dll "${NSISDIR}\plugins\nsExec.dll"
StrCpy $R0 $DestDrive -1
;ExpandEnvStrings $0 %COMSPEC%
;nsExec::Exec '"$0" /c echo. | format $R0 /q /x /v:LiveUSB /fs:fat32'
nsExec::Exec '$PLUGINSDIR\syslinux.exe -maf -d boot\syslinux $R0'
;SendMessage $Checkbox ${BM_GETSTATE} 0 0 $0
;${If} $0 != 0
; MessageBox MB_OK checked!
;${EndIf}
;Pop $Checkbox
;MessageBox mb_ok "FIN Checkbox_State=$Checkbox_State Checkbox=$Checkbox"
;${NSD_GetState} $Checkbox $0
;${If} $0 <> 0
; MessageBox mb_ok "Custom checkbox was checked... N=$0"
;${EndIf}
CopyFiles $PLUGINSDIR\syslinux.cfg "$R0\syslinux.cfg"
SectionEnd
There is so much unrelated code in your example that it is a bit hard to understand what you really want to do.
If you want to retrieve the state of a checkbox on another page then you must save the state because the checkbox control is destroyed when you leave the page.
!include nsDialogs.nsh
Var hwndCheckbox
Var CheckboxState
Page Custom myPageWithCombobox myPageWithComboboxLeaveCallback
Page Custom myPageWithComboState
Function .onInit
StrCpy $CheckboxState ${BST_CHECKED} ; Set the initial state. This is optional but useful if you use $CheckboxState in a section when the installer is silent
FunctionEnd
Function myPageWithCombobox
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckbox} 80 203 100% 10u $(DrivePage_Text2)
Pop $hwndCheckbox
${NSD_SetState} $hwndCheckbox $CheckboxState ; Reuse the existing state so it is correct when the back button is used
nsDialogs::Show
FunctionEnd
Function myPageWithComboboxLeaveCallback
${NSD_GetState} $hwndCheckbox $CheckboxState ; Save the state so we can retrieve it on the next page
FunctionEnd
Function myPageWithComboState
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 160 CheckboxState=$CheckboxState
Pop $0
nsDialogs::Show
FunctionEnd
What I basically want is TeamViewer-like first page for my NSIS installer with the following options:
3 radio buttons for: Run Only; Install for current user; Install for all users (requires restart with admin rights).
A label for license like in TeamViewer (i.e. no actual EULA page, only a link to it in the footer).
A button that can change text, i.e. Accept and Run or Accept and Install.
I cannot figure out how to do it easily in terms of UI and in terms of control flow.
Also I need the ability to restart the installer if user decides to install program for all users (i.e. I guess there should be a detectable command line switch, so that if present installer will automatically assume 3rd install type).
A screenshot of a sample UI as requested:
A sample NSIS template would be greatly appreciated.
Thanks.
...
RequestExecutionLevel user
!include LogicLib.nsh
!include nsDialogs.nsh
!include FileFunc.nsh
!include MUI2.nsh
Var mode
Var modeRadioRun
Var modeRadioInstCU
Var modeRadioInstLM
Function OnRadioChange
GetDlgItem $1 $hwndparent 1 ; Find Install/Next button
${NSD_GetState} $modeRadioRun $0
${If} $0 = ${BST_CHECKED}
${NSD_SetText} $1 "Accept && Run"
${Else}
${NSD_SetText} $1 "Accept && Install"
${EndIf}
FunctionEnd
Function ModePageCreate
!insertmacro MUI_HEADER_TEXT "Welcome to blah" "blah blah"
${GetParameters} $0
ClearErrors
${GetOptions} "$0" "/ELEVATEDINSTALL" $0
${IfNot} ${Errors}
UserInfo::GetAccountType
Pop $0
${If} $0 == "Admin"
StrCpy $mode 1
Abort ; Skip page and start installing
${Else}
MessageBox mb_iconstop "Admin rights required!"
${EndIf}
${EndIf}
nsDialogs::Create 1018
Pop $0
${NSD_CreateRadioButton} 30u 20u 50% 12u "Run"
Pop $modeRadioRun
${NSD_OnClick} $modeRadioRun OnRadioChange
${NSD_CreateRadioButton} 30u 40u 50% 12u "Install for current user"
Pop $modeRadioInstCU
${NSD_OnClick} $modeRadioInstCU OnRadioChange
${NSD_CreateRadioButton} 30u 60u 50% 12u "Install for all users"
Pop $modeRadioInstLM
${NSD_OnClick} $modeRadioInstLM OnRadioChange
${NSD_CreateLink} 20u -14u 50% 12u "License"
Pop $0
${NSD_OnClick} $0 ShowLicense
${NSD_Check} $modeRadioRun
call OnRadioChange ; Trigger button change
nsDialogs::Show
FunctionEnd
Function ModePageLeave
${NSD_GetState} $modeRadioRun $0
${NSD_GetState} $modeRadioInstCU $1
${If} $0 = ${BST_CHECKED}
InitPluginsDir
SetOutPath $pluginsdir
File "myapp.exe"
ExecWait '"$pluginsdir\myapp.exe"'
SetOutPath $temp ; Don't lock $pluginsdir
Quit
${ElseIf} $1 = ${BST_CHECKED}
StrCpy $mode 0
${Else}
StrCpy $mode 1
UserInfo::GetAccountType
Pop $0
${If} $0 != "Admin"
ExecShell "runas" '"$exepath"' "/ELEVATEDINSTALL"
Quit
${EndIf}
${EndIf}
FunctionEnd
Function ShowLicense
ExecShell "" "http://example.com/license"
FunctionEnd
Page Custom ModePageCreate ModePageLeave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
${If} $mode > 0
SetShellVarContext all
StrCpy $InstDir "$ProgramFiles\MyApp"
${Else}
SetShellVarContext current
StrCpy $InstDir "$LocalAppData\Programs\MyApp"
${EndIf}
SetOutPath $InstDir
File myapp.exe
CreateShortcut "$SMPrograms\MyApp.lnk" "$InstDir\myapp.exe"
WriteUninstaller "$InstDir\Uninst.exe"
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyAppGuid" "UninstallString" '"$InstDir\Uninst.exe"'
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyAppGuid" "DisplayName" "MyApp blah blah"
SectionEnd
Section Uninstall
; Todo: Remove files and registry entries (You should write to a .ini in $InstDir so you know if it was a per user or machine install)
RMDir "$InstDir"
SectionEnd
You might want to edit the base UI to make the install button larger with Resource Hacker (on one of the files in NSIS\Contrib\UIs) and in the script use ChangeUI to apply.
I have written a custom page where i want to change the label text on the fly .I tried following code but some how I could not bale to change the text .
Function Maintainance
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "The $CurrentVersion complete installation folder is available at the below link"
Pop $Label
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 1006
SendMessage $1 ${WM_SETTEXT} 0 "STR:new value 111111"
nsDialogs::Show
FunctionEnd
Any pointer on this will be a help.
The custom page is not visible until you call nsDialogs::Show. Any dynamic action has to happen after that with a timer or in response to a user action:
Page Custom MyPageCreate
Page InstFiles
!include nsDialogs.nsh
var mylabel
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 12u "Hello"
Pop $mylabel
${NSD_CreateButton} 0 50% 50% 12u "Change"
Pop $0
${NSD_OnClick} $0 ChangeIt
nsDialogs::Show
FunctionEnd
Function ChangeIt
System::Call kernel32::GetTickCount()i.r0
SendMessage $mylabel ${WM_SETTEXT} 0 "STR:World! $0"
FunctionEnd