Archive: how to create a custom page (.nsh-file)


how to create a custom page (.nsh-file)
Hi there,

I have a problem. I want to create an installer with a pair of custom pages, but one of this custom pages only should appear if on the "MUI_PAGE_COMPONENTS" a special section is marked. If this section isn't marked this page shouldn't appear.

I want this, 'cause i want the most sections in on one directory, but this special section (if marked) in another folder. Or has anyone an idea how to make it in one "MUI_PAGE_DIRECTORY" so there will be shown to rows of Path and the second is only active if it is marked.

How must the ".ini" and the ".nsh"-file look like, that this will be work?


1. you can't use mui_page_directory. Create your own custom page (InstallOptionsEx, NSDialogs (comes with NSIS) - InstallOptions2 (comes with NSIS) is not an option as it crashes when using 2 directory fields)

2. Use SectionGetFlags to get whether a section is selected

3. Use "EnableWindow <control ID of your 2nd directory UI elements> 0" to disable your 2nd dir field if the section was not selected

With all the above, you should be well on your way..
here's some sample code - you'll have to fill in the blanks wrt the directory controls;


!include nsDialogs.nsh

Name "Test"
OutFile "SetupTest.exe"
InstallDir "$PROGRAMFILES\Test"

Page Components
Page Custom fnPre

Var Dialog
Var Dir1
Var DirBtn1
Var Dir2
Var DirBtn2

Section "A" "aSection"
SectionEnd

Section "B" "bSection"
SectionEnd

Function fnPre
; Create a dialog
nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog
StrCmp $Dialog error 0 +2
Abort

; Populate with directory bits
${NSD_CreateDirRequest} 0 0 90% 12u ""
Pop $Dir1
${NSD_CreateButton} 90% 0 12u 12u "..."
Pop $DirBtn1

${NSD_CreateDirRequest} 0 14u 90% 12u ""
Pop $Dir2
${NSD_CreateButton} 90% 14u 12u 12u "..."
Pop $DirBtn2

; Get the section flags
SectionGetFlags ${bSection} $0
IntOp $0 $0 && 1
IntCmp $0 0 0 _skip _skip
; Disable if section "B" os not selected
EnableWindow $Dir2 0
EnableWindow $DirBtn2 0

_skip:

; Display the dialog
nsDialogs::Show
FunctionEnd