Archive: Does anyone have an example of section dependencies using LogicLib?


Does anyone have an example of section dependencies using LogicLib?
I was looking at the example for section dependency on the wiki and it seems to me that it could possibly be done with less lines using the LogicLib and since I have a dependency tree with 9 sections in it then less complexity would really help. Anyone have a good example of section dependency using the LogicLib?


Hmm.. I took a look at the wiki article ( http://nsis.sourceforge.net/Section_Dependency ) and made a LogicLib version below.

There are some differences, however.. From reading the wiki, there's a comment that reads "# Check if Sec2 was just selected then select Sec3 and Sec4.". However, it doesn't actually do that in the code there. The below LogicLib'd code does.

In short, the behavior is as follows:
Selecting Section 2 -> Selects Section 3 and Section 4
Unselecting Section 2 -> Unselects Section 3 and Section 4
Selecting Section 3 -> Selects Section 2
Selecting Section 4 -> Selects Section 2

To match the behavior of the wiki article code, just remove the code that selects Section 3 and Section 4 when Section 2 was selected.

In addition, I have hardcoded the value of the independent section's selected state in .onInit. The reason I've hardcoded this is because, presumably, as the author of the installer you would -know- whether your independent section ('Section 2' in the example) is selected on startup or not (made optional using "Section /o"), so detecting this at runtime is a bit wasteful.


Name SectionDependencyLogicLib
OutFile SectionDependencyLogicLib.exe

Var IndependentSectionState

Page Components

!include Sections.nsh

; LogicLib and some additional defines for convenience
!include LogicLib.nsh
!define SelectSection `!insertmacro SelectSection`
!define UnselectSection `!insertmacro UnselectSection`

Section "Section 1" Sec1
SectionIn RO
SectionEnd

Section "Section 2" Sec2
SectionEnd

Section /o "Section 3" Sec3
SectionEnd

Section /o "Section 4" Sec4
SectionEnd

Function .onInit
StrCpy $IndependentSectionState 1
FunctionEnd

Function .onSelChange
${If} ${SectionIsSelected} ${Sec2}
${If} $IndependentSectionState != 1
StrCpy $IndependentSectionState 1
${SelectSection} ${Sec3}
${SelectSection} ${Sec4}
${EndIf}
${Else}
${If} $IndependentSectionState != 0
StrCpy $IndependentSectionState 0
${UnselectSection} ${Sec3}
${UnselectSection} ${Sec4}
${EndIf}
${EndIf}

${If} ${SectionIsSelected} ${Sec3}
${OrIf} ${SectionIsSelected} ${Sec4}
StrCpy $IndependentSectionState 1
${SelectSection} ${Sec2}
${EndIf}
FunctionEnd

Thank you Animaether!
Thank you and good work Animaether! You know what would be really cool, if someone wrote a dependency library or even just a macro for dependencies... so the macro would have syntax something like this:

!insertmacro DEPENDENCY ${Sec2} ${Sec3} ${Sec4}

where the first param (Sec2) is the section all other following params (sections Sec3 and Sec4) are dependent on.

Not even sure if that would be possible but it sure would make it simple to set up dependency trees.