Search code examples
nsis

NSIS SectionIn InstType swapable based on Language Selection


Looking to change the SectionIn for a section based on what language the user selects. So if the "Standard" install is 1 and "Full" install is 2, I want it so that if the user selects English then the "English Documentation" section has SectionIn 1 2, but if they select something else like French, then "English Documentation" is SectionIn 2 and "French Documentation" is SectionIn 1 2.

The goal is to have both language documentations selectable no matter what, but based on the language one is the default and InstType drop down box will show "Standard" instead of custom (I already know how to make it select one or the other based on the language selection). Here's basically what I'm working with to change the selection at least:

    InstType "Standard"
    InstType "Full"

    Section /o "English Docs" English
    SectionIn 2
    ;crap to run
    SectionEnd

    Section /o "French Docs" French
    SectionIn 2
    ;crap to run
    SectionEnd


    Function .onInit
    !insertmacro MUI_LANGDLL_DISPLAY
    ${If} $LANGUAGE == ${LANG_ENGLISH}
    !insertmacro SelectSection ${English}
    ${EndIf}
    ${If} $LANGUAGE == ${LANG_FRENCH}
    !insertmacro SelectSection ${French}
    ${EndIf}
    FunctionEnd

Solution

  • Use SectionSetInstTypes:

    !include MUI2.nsh
    !insertmacro MUI_PAGE_COMPONENTS
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE English
    !insertmacro MUI_LANGUAGE French
    
    
    InstType "Standard"
    InstType "Full"
    
    Section /o "English Docs" SID_English
    SectionIn 2
    ;crap to run
    SectionEnd
    
    Section /o "French Docs" SID_French
    SectionIn 2
    ;crap to run
    SectionEnd
    
    
    Function .onInit
    !insertmacro MUI_LANGDLL_DISPLAY
    ${If} $LANGUAGE == ${LANG_ENGLISH}
        StrCpy $0 ${SID_English}
    ${EndIf}
    ${If} $LANGUAGE == ${LANG_FRENCH}
        StrCpy $0 ${SID_French}
    ${EndIf}
    
    SectionSetInstTypes $0 3
    !insertmacro SelectSection $0
    FunctionEnd