tags:

views:

248

answers:

1

I want to make a section inside of a sectiongroup required for that section group but not required for the entire install if the group is unchecked. I've tried "SectionIn R0" but this makes that section required for the entire install and I only want it to be required if they select the group itself.

SectionGroup "group"
  Section "required for section group"
    SectionIn RO
  SectionEnd

  Section "optional"
  SectionEnd
SectionGroupEnd
A: 

You can't do this with just properties, you need some actual code:

!include Sections.nsh
!include LogicLib.nsh

SectionGroup /e "group"
  Section "required for section group" SEC_REQ
    SectionIn RO
  SectionEnd
  Section "optional" SEC_OPT
  SectionEnd
SectionGroupEnd

Function .onSelChange
${If} ${SectionIsSelected} ${SEC_OPT}
    !define /math MYSECTIONFLAGS ${SF_SELECTED} | ${SF_RO}
    !insertmacro SetSectionFlag ${SEC_REQ} ${MYSECTIONFLAGS} 
    !undef MYSECTIONFLAGS
${Else}
    !insertmacro ClearSectionFlag ${SEC_REQ} ${SF_RO}
${EndIf}
FunctionEnd

Note that there is a "bug" when unchecking the section group itself, to workaround that, you need to keep some global state since nsis does not tell you which section generated the notification. The following code has better logic:

!include Sections.nsh
!include LogicLib.nsh

SectionGroup /e "group" SEC_GRP
  Section "required for section group" SEC_REQ
    SectionIn RO
  SectionEnd
  Section "optional" SEC_OPT
  SectionEnd
  Section "" PRIVSEC_TOGGLESTATE ;hidden section to keep track of state
  SectionEnd
SectionGroupEnd

Function .onSelChange
!define /math SECFLAGS_SELRO ${SF_SELECTED} | ${SF_RO}
${IfNot} ${SectionIsSelected} ${PRIVSEC_TOGGLESTATE}
${AndIf} ${SectionIsReadOnly} ${SEC_REQ}
    !insertmacro ClearSectionFlag ${SEC_REQ} ${SECFLAGS_SELRO}
${EndIf}
${If} ${SectionIsSelected} ${SEC_OPT}
    !insertmacro SetSectionFlag ${SEC_REQ} ${SECFLAGS_SELRO} 
${Else}
    !insertmacro ClearSectionFlag ${SEC_REQ} ${SF_RO}
${EndIf}
${If} ${SectionIsSelected} ${SEC_REQ}
    !insertmacro SelectSection ${PRIVSEC_TOGGLESTATE}
${Else}
    !insertmacro UnselectSection ${PRIVSEC_TOGGLESTATE}
${EndIf}
!undef SECFLAGS_SELRO
FunctionEnd
Anders