nsisunattended-processing

NSIS unattended options


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

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?


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