# This example demonstrates how to control section selection. # It allows only one of the four optional section to be # selected at any given time. #### Uncomment the next line for an example with subsections too # !define USE_SUBSECTION #### Name example OutFile one-section.exe ComponentText "please choose just one but the default" Var seca Var secb Var secc Var secd # defines SF_*, SECTION_OFF and some macros !include Sections.nsh Section !Required SectionIn RO SectionEnd !ifdef USE_SUBSECTION SubSection /e "choose one a" subseca !endif Section "optional #1" sec1a SectionEnd Section /o "optional #2" sec2a SectionEnd Section /o "optional #3" sec3a SectionEnd Section /o "optional #4" sec4a SectionEnd !ifdef USE_SUBSECTION SubSectionEnd !endif Section !Required SectionIn RO SectionEnd !ifdef USE_SUBSECTION SubSection /e "choose one b" subsecb !endif Section "optional #1" sec1b SectionEnd Section /o "optional #2" sec2b SectionEnd Section /o "optional #3" sec3b SectionEnd Section /o "optional #4" sec4b SectionEnd !ifdef USE_SUBSECTION SubSectionEnd !endif Section !Required SectionIn RO SectionEnd !ifdef USE_SUBSECTION SubSection /e "choose one c" subsecc !endif Section "optional #1" sec1c SectionEnd Section /o "optional #2" sec2c SectionEnd Section /o "optional #3" sec3c SectionEnd Section /o "optional #4" sec4c SectionEnd !ifdef USE_SUBSECTION SubSectionEnd !endif Section !Required SectionIn RO SectionEnd !ifdef USE_SUBSECTION SubSection /e "choose one d" subsecd !endif Section "optional #1" sec1d SectionEnd Section /o "optional #2" sec2d SectionEnd Section /o "optional #3" sec3d SectionEnd Section /o "optional #4" sec4d SectionEnd !ifdef USE_SUBSECTION SubSectionEnd !endif Function .onInit StrCpy $seca ${sec1a} ; Gotta remember which section we are at now... StrCpy $secb ${sec1b} StrCpy $secc ${sec1c} StrCpy $secd ${sec1d} FunctionEnd Function .onSelChange Push $0 !ifdef USE_SUBSECTION ; Check if the user have selected all of the sections using the sub-section SectionGetFlags ${subseca} $0 IntOp $0 $0 & ${SF_SELECTED} StrCmp $0 0 skipa SectionSetFlags ${sec1a} 0 SectionSetFlags ${sec2a} 0 SectionSetFlags ${sec3a} 0 SectionSetFlags ${sec4a} 0 skipa: SectionGetFlags ${subsecb} $0 IntOp $0 $0 & ${SF_SELECTED} StrCmp $0 0 skipb SectionSetFlags ${sec1b} 0 SectionSetFlags ${sec2b} 0 SectionSetFlags ${sec3b} 0 SectionSetFlags ${sec4b} 0 skipb: SectionGetFlags ${subsecc} $0 IntOp $0 $0 & ${SF_SELECTED} StrCmp $0 0 skipc SectionSetFlags ${sec1c} 0 SectionSetFlags ${sec2c} 0 SectionSetFlags ${sec3c} 0 SectionSetFlags ${sec4c} 0 skipc: SectionGetFlags ${subsecd} $0 IntOp $0 $0 & ${SF_SELECTED} StrCmp $0 0 skipd SectionSetFlags ${sec1d} 0 SectionSetFlags ${sec2d} 0 SectionSetFlags ${sec3d} 0 SectionSetFlags ${sec4d} 0 skipd: !endif ; Turn off old selected section SectionGetFlags $seca $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags $seca $0 # !insertmacro UnselectSection $seca ; Now remember the current selection Push $2 StrCpy $2 $seca SectionGetFlags ${sec1a} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $seca ${sec1a} SectionGetFlags ${sec2a} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $seca ${sec2a} SectionGetFlags ${sec3a} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $seca ${sec3a} SectionGetFlags ${sec4a} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $seca ${sec4a} StrCmp $2 $seca 0 +4 ; selection hasn't changed SectionGetFlags $seca $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags $seca $0 # !insertmacro SelectSection $seca ; Turn off old selected section SectionGetFlags $secb $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags $secb $0 # !insertmacro UnselectSection $secb ; Now remember the current selection Push $2 StrCpy $2 $secb SectionGetFlags ${sec1b} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secb ${sec1b} SectionGetFlags ${sec2b} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secb ${sec2b} SectionGetFlags ${sec3b} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secb ${sec3b} SectionGetFlags ${sec4b} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secb ${sec4b} StrCmp $2 $secb 0 +4 ; selection hasn't changed SectionGetFlags $secb $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags $secb $0 # !insertmacro SelectSection $secb ; Turn off old selected section SectionGetFlags $secc $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags $secc $0 # !insertmacro UnselectSection $secc ; Now remember the current selection Push $2 StrCpy $2 $secc SectionGetFlags ${sec1c} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secc ${sec1c} SectionGetFlags ${sec2c} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secc ${sec2c} SectionGetFlags ${sec3c} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secc ${sec3c} SectionGetFlags ${sec4c} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secc ${sec4c} StrCmp $2 $secc 0 +4 ; selection hasn't changed SectionGetFlags $secc $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags $secc $0 # !insertmacro SelectSection $secc ; Turn off old selected section SectionGetFlags $secd $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags $secd $0 # !insertmacro UnselectSection $secd ; Now remember the current selection Push $2 StrCpy $2 $secd SectionGetFlags ${sec1d} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secd ${sec1d} SectionGetFlags ${sec2d} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secd ${sec2d} SectionGetFlags ${sec3d} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secd ${sec3d} SectionGetFlags ${sec4d} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 +2 +2 StrCpy $secd ${sec4d} StrCmp $2 $secd 0 +4 ; selection hasn't changed SectionGetFlags $secd $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags $secd $0 # !insertmacro SelectSection $secd Pop $2 Pop $0 FunctionEnd