How do I make one nsi section depend on another?
In NSI, how can I make one section depend on another?
Our installer has four visible sections (componen开发者_开发百科ts):
* 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.
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
精彩评论