views:

25

answers:

1

In NSI, how can I make one section depend on another?

Our installer has four visible sections (components):

* Client
* Database
* Server
* Interface

All components depend on Client, so it is mandatory. In addition, Server depends on Database and will fail to install if Database is not present.

+1  A: 

You can use the .onSelChange callback to change section states in response to a section change.

Outfile test.exe
!include Sections.nsh
!include LogicLib.nsh

Page Components
Page InstFiles

Section "Client"
SectionIn RO
SectionEnd

Section /o "Database" SEC_DB
SectionEnd

Section /o "Server" SEC_SRV
SectionEnd

Section /o "Interface"
SectionEnd


Function .onSelChange
${If} ${SectionIsSelected} ${SEC_SRV}
    !insertmacro SetSectionFlag ${SEC_DB} ${SF_RO}
    !insertmacro SelectSection ${SEC_DB}
${Else}
    !insertmacro ClearSectionFlag ${SEC_DB} ${SF_RO}
${EndIf}
FunctionEnd

Or without read-only DB section:

Function .onSelChange
var /Global HadSecSrv
${IfNot} ${SectionIsSelected} ${SEC_DB}
    ${If} $HadSecSrv <> 0
        !insertmacro UnselectSection ${SEC_SRV}
    ${EndIf}
${EndIf}
StrCpy $HadSecSrv 0
${If} ${SectionIsSelected} ${SEC_SRV} 
    StrCpy $HadSecSrv 1
    !insertmacro SelectSection ${SEC_DB}
${EndIf}
FunctionEnd
Anders