Question

I want to build a NSIS-script, which has three section

  • section Main
  • section Minor
  • section Shared

Shared is invisible and would be installed, if Main or Minor is checked. If I start the installer, every section (Main, Minor) is checked.

Now it should be able to define the section (in silent install). What have I to change, to only install Main or Minor or Both?

Was it helpful?

Solution

Name "Test"
Outfile "Test.exe"
;RequestExecutionLevel ?

!include "Sections.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh" ;For GetOptions

Page Components "" "" EnforceSectionDependencies
Page InstFiles

Section /o "Main" SID_MAIN
DetailPrint Main
SectionEnd

Section /o "Minor" SID_MINOR
DetailPrint Minor
SectionEnd

Section "" SID_SHARED
DetailPrint Shared
SectionEnd

!macro CheckSectionSwitch sw sid
${GetOptions} $0 '${sw}' $9
${IfNot} ${Errors}
    StrCpy $1 1
    !insertmacro SelectSection ${sid}
${EndIf}
!macroend

Function .onInit
${GetParameters} $0
StrCpy $1 0 ;Any section swithes?
ClearErrors
!insertmacro CheckSectionSwitch '/Main' ${SID_MAIN}
!insertmacro CheckSectionSwitch '/Minor' ${SID_MINOR}

${If} $1 = 0
    ;Set defaults
    !insertmacro SelectSection ${SID_MAIN}
    !insertmacro SelectSection ${SID_MINOR}
${EndIf}

call EnforceSectionDependencies
FunctionEnd

Function EnforceSectionDependencies
!insertmacro UnselectSection ${SID_SHARED}
${If} ${SectionIsSelected} ${SID_MAIN}
${OrIf} ${SectionIsSelected} ${SID_MINOR}
    !insertmacro SelectSection ${SID_SHARED}
${EndIf}
FunctionEnd

OTHER TIPS

You should look at the Section management part of the documentation, notably the SectionSetFlags to change the sections selections.

Also, maybe that the How to control Section selections, while using SubSections & InstTypes example will be useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top