Search code examples
dependenciesnsis

NSIS - section dependency .onSelChange


I need a little help or advise how to force SEC033 & SEC085 section's to work together in this way:
1. when SEC033 is selected, SEC085 should be selected & when SEC033 is unselected, SEC085 should be unselected to
2. when SEC085 is selected, SEC033 should be selected & when SEC085 is unselected, SEC033 should be unselected to

My nsis section structure:

SectionGroup "$(SEC03)" SEC03    

    Section "Product 1" SEC031
        SectionIn 1 2
    SectionEnd    

    Section "Product 3" SEC033
        SectionIn 1 2
    SectionEnd    

    Section "Product 6" SEC036
        SectionIn 1 2
    SectionEnd    

SectionGroupEnd    

SectionGroup "$(SEC08)" SEC08    

    Section "Product 2" SEC082
        SectionIn 1 2
    SectionEnd    

    Section "Product 5" SEC085
        SectionIn 1 2
    SectionEnd    

    Section "Product 8" SEC088
        SectionIn 1 2
    SectionEnd    

SectionGroupEnd

I have no idea how to do that, unfortunately I'm not familiar with all this SectionGetFlags/SectionSetFlags

I try to use this:

SectionGetFlags ${SEC033} $0
SectionSetFlags ${SEC085} $0

& for SEC033 works great

but when I add

SectionGetFlags ${SEC085} $0
SectionSetFlags ${SEC033} $0

SEC085 wont work at all, I understand that this is exactly the same but in opposite way & probably this is the problem, but I don't know how to fix it....:/


Solution

  • The section flags stores more than just the checked state, it also stores group, bold and read-only flags so you should not use SectionSetFlags to set the state to just 0 or 1. Sections.nsh contains defines for each bit and it also contains helper macros you can use to manipulate sections. If you manually want to see if a section is checked (selected) you must use a bit test:

    SectionGetFlags ${SEC033} $4
    IntOp $4 $4 & ${SF_SELECTED}
    

    LogicLib.nsh contains macros that lets you check sections in a ${If} statement:

    !include Sections.nsh
    !include LogicLib.nsh
    Function .onSelChange
    ${If} $6 == "1" ; Use $6 here like you did in your answer
        StrCpy $6 0
        ${If} ${SectionIsSelected} ${SEC033}
        ${OrIf} ${SectionIsSelected} ${SEC085}
            !insertmacro SelectSection ${SEC033}
            !insertmacro SelectSection ${SEC085}
        ${EndIf}
    ${Else}
        StrCpy $6 1
        ${IfNot} ${SectionIsSelected} ${SEC033}
        ${OrIfNot} ${SectionIsSelected} ${SEC085}
            !insertmacro UnselectSection ${SEC033}
            !insertmacro UnselectSection ${SEC085}
        ${EndIf}
    ${EndIf}