Insert Custom Page between 2 sections in NSIS - nsis

(I am sorry I couldn't come up with a better title)
I have the following partial-code:
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
Page Custom nsDialogsPage nsDialogsPageLeave
section Section1
#do something
sectionEnd
section Section2
#do something else
sectionEnd
Function nsDialogsPage
#do something
FunctionEnd
Function nsDialogsPageLeave
#do something else
FunctionEnd
But, now I want the Custom Page to show up after Section1 and before Section2 (I Enter some info in the custom page which is used in Section2). How should I go about this ? (I can always put the Custom Page before MUI_PAGE_INSTFILES, but that looks rather odd for the user.)

All sections are executed on the instfiles page, it is however possible to have multiple instfiles pages. To prevent all sections from executing twice you need to turn the correct sections on/off with the helper macros in sections.nsh or store some state in a global variable and put all the sections code inside a if block, ex:${If} $installstep = 0. You might also need to use SetAutoClose...

I used a PRE Function to select/unselect sections:
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE checkSkipSection
!insertmacro MUI_PAGE_INSTFILES
Page Custom nsDialogsPage nsDialogsPageLeave
!define MUI_PAGE_CUSTOMFUNCTION_PRE checkSkipSection
!insertmacro MUI_PAGE_INSTFILES
Var SkipSection
section Section1
#do something
StrCpy $SkipSection 1
sectionEnd
section Section2
#do something else
sectionEnd
Function nsDialogsPage
#do something
FunctionEnd
Function nsDialogsPageLeave
#do something else
FunctionEnd
Function checkSkipSection
${If} $SkipSection = ""
SectionSetFlags ${Section1} ${SF_SELECTED}
SectionSetFlags ${Section2} 0
${ElseIf} $SkipSection = 1
SectionSetFlags ${Section2} ${SF_SELECTED}
SectionSetFlags ${Section1} 0
${EndIf}
FunctionEnd
So in the 1st MUI_PAGE_INSTFILES, only Section1 is run, while Section2 is run in the 2nd MUI_PAGE_INSTFILES page.

Related

NSIS Selections Page

I was originally going to ask how to do several of the features I how have working in the set file. so I have 2 questions now. Patting myself on the back since I figured out everything else:)
Ok so here is what I would like:
Is it possible to have the list taller so no scrolling? also
Can we have the title be just that and no checkbox? (They are radio-buttons and the title is the grouping of them)
How could I go about creating the same thing just in a custom page so I have control over the elements? (including the mouse move over feature of components page)
Thanks for looking and hope you can help me code it out.
Code: (And yes I know the !included's are not all needed in the test buy my app does so I just left it) Also the verification and a few other settings are not finished, I was just getting some examples to work.)
!include WinVer.nsh
!include LogicLib.nsh
!include x64.nsh
!include FileFunc.nsh
!include MUI.nsh
!include WinMessages.nsh
!include InstallOptions.nsh
!include Sections.nsh
!define MUI_COMPONENTSPAGE_TEXT_TOP "Please select the options that best match your setup and preferances."
!define MUI_COMPONENTSPAGE_TEXT_COMPLIST " "
!define MUI_PAGE_HEADER_TEXT "Setup Options"
!define MUI_PAGE_HEADER_SUBTEXT " "
!define MUI_COMPONENTSPAGE_smallDESC
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
SectionGroup /e "!Sets" SetsTitle #Section Should be Radio Buttons
Section "Set 1" Set1
SectionEnd
Section /o "Set 2" Set2
SectionEnd
Section /o "Skip" SetSkip
SectionEnd
SectionGroupEnd
SubSection /e "!Setup" SetupTitle #Section Should be Radio Buttons
Section "Setup 1" setup1
SectionEnd
Section /o "Setup 2" setup2
SectionEnd
Section /o "None" setupNone
SectionEnd
SubSectionEnd
SubSection /e "!AutoLoad" ALTitle #Section Should be Radio Buttons
Section "Yes" ALYes
SectionEnd
Section /o "No" ALNo
SectionEnd
SubSectionEnd
SubSection /e "!Disable Feature" DFTitle #Section Should be Check Boxes
Section "Feature 1" DAF1
SectionEnd
Section "Feature 2" DAF2
SectionEnd
SubSectionEnd
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SetsTitle} "Sets Description"
!insertmacro MUI_DESCRIPTION_TEXT ${Set1} "Set1 Description"
!insertmacro MUI_DESCRIPTION_TEXT ${Set2} "Set2 Description"
!insertmacro MUI_DESCRIPTION_TEXT ${SetSkip} "SetNone Description"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Section -InstallSelectedOptions
${If} ${SectionIsSelected} ${set1}
MessageBox MB_OK|MB_USERICON|MB_TOPMOST "set1"
${endif}
${If} ${SectionIsSelected} ${set2}
MessageBox MB_OK|MB_USERICON|MB_TOPMOST "set2"
${endif}
${If} ${SectionIsSelected} ${setskip}
MessageBox MB_OK|MB_USERICON|MB_TOPMOST "setnone"
${endif}
${If} ${Setup1} == true
${endif}
SectionEnd
Function .onInit
StrCpy $1 ${set1} ; Group 1 - Option 1 is selected by default
StrCpy $2 ${setup1} ; Group 2 - Option 1 is selected by default
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${set1}
!insertmacro RadioButton ${set2}
!insertmacro RadioButton ${setskip}
!insertmacro EndRadioButtons
!insertmacro StartRadioButtons $2
!insertmacro RadioButton ${setup1}
!insertmacro RadioButton ${setup2}
!insertmacro RadioButton ${setupNone}
!insertmacro EndRadioButtons
FunctionEnd
You cannot combine radio buttons and checkmarks on the built-in components page but you can use your own custom radio button .BMP file with !define MUI_COMPONENTSPAGE_CHECKBITMAP "myradio.bmp".
You can customize the MUI components page a little bit by defining MUI_COMPONENTSPAGE_SMALLDESC or MUI_COMPONENTSPAGE_NODESC but if you need more than that you have to copy and modify "...\NSIS\Contrib\UIs\modern.exe" with Resource Hacker and apply this custom UI with MUI_UI.
Replicating the components page as a custom page might be possible but it is a lot of work. nsDialogs does not have much support for the TreeView control so you are pretty much on your own if you go down this route.

Skipping pages: Button should say "Install" instead of "Next"

I have an installer using the Modern UI 2 (MUI 2) that installs up to three components into different locations.
I use a MUI_PAGE_COMPONENTS page and multiple MUI_PAGE_DIRECTORY pages which are skipped automatically if the corresponding section is not selected (like described here).
So far so good.
However, if the last of the three components is not chosen to be installed, the button on the previous (not-skipped) directory page should say Install instead of Next, because next the last directory page will be skipped and the installation will be executed.
Since we already know which page will be skipped after we leave the components page, I wonder if there is a way to make it work?
Minimal example:
!include MUI2.nsh
InstallDir $EXEDIR
OutFile "skip.exe"
RequestExecutionLevel user
ShowInstDetails show
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE directoryPreA
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_PAGE_CUSTOMFUNCTION_PRE directoryPreB
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section "A" SEC_A
DetailPrint "Installing A..."
SectionEnd
Section /o "B" SEC_B
DetailPrint "Installing B..."
SectionEnd
Function directoryPreA
# Skips the directory page for A if not chosen for installation.
${Unless} ${SectionIsSelected} ${SEC_A}
Abort
${EndUnless}
FunctionEnd
Function directoryPreB
# Skips the directory page for B if not chosen for installation.
${Unless} ${SectionIsSelected} ${SEC_B}
Abort
${EndUnless}
FunctionEnd
!include MUI2.nsh
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_DIRECTORYPAGE_TEXT_TOP "Dir:A"
!define MUI_PAGE_CUSTOMFUNCTION_PRE directoryPreA
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_DIRECTORYPAGE_TEXT_TOP "Dir:B"
!define MUI_PAGE_CUSTOMFUNCTION_PRE directoryPreB
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section "A" SEC_A
DetailPrint "Installing A..."
SectionEnd
Section /o "B" SEC_B
DetailPrint "Installing B..."
SectionEnd
Function .onSelChange
GetDlgItem $0 $HWNDPARENT 1
${If} ${SectionIsSelected} ${SEC_A}
${OrIf} ${SectionIsSelected} ${SEC_B}
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^NextBtn)"
${Else}
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^InstallBtn)"
${EndIf}
FunctionEnd
Function directoryPreA
# Skips the directory page for A if not chosen for installation.
${IfNot} ${SectionIsSelected} ${SEC_A}
Abort
${ElseIfNot} ${SectionIsSelected} ${SEC_B}
GetDlgItem $0 $HWNDPARENT 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^InstallBtn)"
${EndIf}
FunctionEnd
Function directoryPreB
# Skips the directory page for B if not chosen for installation.
${Unless} ${SectionIsSelected} ${SEC_B}
Abort
${EndUnless}
FunctionEnd

How to check back button pressed in startmenu folder page in NSIS?

var startmenu
!insertmacro MUI_PAGE_STARTMENU DefaultPage $startmenu
In the above one line code can be used to create startmenu folder page.If the user click back button of this page want to move control some specific page.
I have tried ${NSD_Back}, OnClick functions but i dont know where to implement this code to check back button pressed?
How to check back button pressed in the startmenu folder page?
What you are asking for does not make any sense but here you go:
!include MUI2.nsh
Var MyStartFolder
Var BackDetection
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_PRE PageCallbackBeforeSMPre
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE PageCallbackSMPre
!insertmacro MUI_PAGE_STARTMENU DefaultPage $MyStartFolder
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
# nsis.sf.net/Go_to_a_NSIS_page
Function RelGotoPage
IntCmp $R9 0 0 Move Move
StrCmp $R9 "X" 0 Move
StrCpy $R9 "120"
Move:
SendMessage $HWNDPARENT 0x408 $R9 ""
FunctionEnd
Function PageCallbackBeforeSMPre
${If} $BackDetection == "SM"
StrCpy $BackDetection ""
StrCpy $R9 -1
Call RelGotoPage
${EndIf}
FunctionEnd
Function PageCallbackSMPre
StrCpy $BackDetection SM
FunctionEnd
Start menu page is created by third party plug-in, not by NSIS code.
So you need to modify Start menu plug-in sources to get notifications about.
Maybe if you say what are you trying to achieve we can help you?
There are plenty of other functions you can use - e.g. page's callback to check state of previous/next page.

How can I get a finish button after a nsDialogs page

I'm trying to create a post install configuration page in my nsis script using nsDialogs. My script for gathering the input and executing the configuration works however I'm never presented with a finish/close/exit button after I'm done. Currently my pages declaration looks like:
Page directory
Page instfiles
Page custom nsDialogsPage nsDialogsPageLeave
How can I get a finish/exit/done button to show after nsDialogsPageLeave executes?
The classic NSIS UI does not have a finish page, the instfiles page is usually the last page and it will show a "finish button" after all the sections have executed. You can set the text of any button to the same string with SendMessage $hwndButton ${WM_SETTEXT} 0 "STR:$(^CloseBtn)" if you want to provide your own finish page.
Most installers request the required information before the instfiles page, if you cannot do this then you might want to use the Modern UI, it will provide a finish page for you:
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Page custom nsDialogsPage nsDialogsPageLeave
!insertmacro MUI_PAGE_FINISH
It was a little unclear to me if you wanted two pages; a input page and then a finish page or a combined input/finish page. A combined page is a little weird but it is possible:
!define AppName "Test"
Name "${AppName}"
Outfile "${AppName} setup.exe"
InstallDir $temp
!include LogicLib.nsh
!include WinMessages.nsh
!include nsDialogs.nsh
Var MyEndConfigPageStage
Page Directory
Page InstFiles
Page Custom MyEndConfigPageCreate MyEndConfigPageLeave /EnableCancel
Function MyEndConfigPageCreate
StrCpy $MyEndConfigPageStage 0
GetDlgItem $0 $hwndparent 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:&Apply"
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckBox} 0 13u 100% -13u "FooBar"
Pop $1
nsDialogs::Show
FunctionEnd
Function MyEndConfigPageLeave
${If} $MyEndConfigPageStage > 0
Return
${EndIf}
${NSD_GetState} $1 $2
ClearErrors
WriteIniStr "$instdir\settings.ini" Dummy "FooBar" $2
${If} ${Errors}
MessageBox mb_iconstop "Unable to apply settings!"
Abort
${EndIf}
IntOp $MyEndConfigPageStage $MyEndConfigPageStage + 1
GetDlgItem $0 $hwndparent 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^CloseBtn)"
GetDlgItem $0 $hwndparent 2
EnableWindow $0 0 ;Disable cancel
EnableWindow $1 0 ;Disable the checkbox
Abort
FunctionEnd
Section
SectionEnd

How do I make a section required for a sectiongroup in NSIS?

I want to make a section inside of a sectiongroup required for that section group but not required for the entire install if the group is unchecked. I've tried "SectionIn R0" but this makes that section required for the entire install and I only want it to be required if they select the group itself.
SectionGroup "group"
Section "required for section group"
SectionIn RO
SectionEnd
Section "optional"
SectionEnd
SectionGroupEnd
You can't do this with just properties, you need some actual code:
!include Sections.nsh
!include LogicLib.nsh
SectionGroup /e "group"
Section "required for section group" SEC_REQ
SectionIn RO
SectionEnd
Section "optional" SEC_OPT
SectionEnd
SectionGroupEnd
Function .onSelChange
${If} ${SectionIsSelected} ${SEC_OPT}
!define /math MYSECTIONFLAGS ${SF_SELECTED} | ${SF_RO}
!insertmacro SetSectionFlag ${SEC_REQ} ${MYSECTIONFLAGS}
!undef MYSECTIONFLAGS
${Else}
!insertmacro ClearSectionFlag ${SEC_REQ} ${SF_RO}
${EndIf}
FunctionEnd
Note that there is a "bug" when unchecking the section group itself, to workaround that, you need to keep some global state since nsis does not tell you which section generated the notification. The following code has better logic:
!include Sections.nsh
!include LogicLib.nsh
SectionGroup /e "group" SEC_GRP
Section "required for section group" SEC_REQ
SectionIn RO
SectionEnd
Section "optional" SEC_OPT
SectionEnd
Section "" PRIVSEC_TOGGLESTATE ;hidden section to keep track of state
SectionEnd
SectionGroupEnd
Function .onSelChange
!define /math SECFLAGS_SELRO ${SF_SELECTED} | ${SF_RO}
${IfNot} ${SectionIsSelected} ${PRIVSEC_TOGGLESTATE}
${AndIf} ${SectionIsReadOnly} ${SEC_REQ}
!insertmacro ClearSectionFlag ${SEC_REQ} ${SECFLAGS_SELRO}
${EndIf}
${If} ${SectionIsSelected} ${SEC_OPT}
!insertmacro SetSectionFlag ${SEC_REQ} ${SECFLAGS_SELRO}
${Else}
!insertmacro ClearSectionFlag ${SEC_REQ} ${SF_RO}
${EndIf}
${If} ${SectionIsSelected} ${SEC_REQ}
!insertmacro SelectSection ${PRIVSEC_TOGGLESTATE}
${Else}
!insertmacro UnselectSection ${PRIVSEC_TOGGLESTATE}
${EndIf}
!undef SECFLAGS_SELRO
FunctionEnd
You can also set the sections as mandatory sections by using the SectionSetFlags command. You simply need to add it to the .onInit function as follows:
SectionGroup "group" Sec01
Section "required for section group"
SectionIn RO
SectionEnd
Section "optional" Sec02
SectionEnd
SectionGroupEnd
Function .onInit
SectionSetFlags ${Sec01} 17
FunctionEnd
This will gray "group" out, but it will be selected and installed as expected.
You can also setup a custom function which is being called when user clicks "Next" but no option is selected. In this function, you can check if any of Sections is selected or, as I did, check the variable which is set to "nothingSelected" on init, then modified when any section is created. If you put "Abort" in the custom function, the installer will stay on the same page. Here is a snippet:
page license
page directory
page components "" "" testSelection
page instfiles
function .onInit
StrCpy $somethingSelected "nothingSelected"
functionEnd
function testSelection
${If} $somethingSelected == "nothingSelected"
MessageBox MB_OK "Please select any option"
Abort
${EndIf}
functionEnd
function .onSelChange
#selecting mutually exclusive sections (removed for clarity)
StrCpy $somethingSelected $1
functionEnd

Resources