我想在该部分组所需的部分组内部创建一个部分,但如果未选中该部分,则不需要整个安装。我已经尝试了“SectionIn R0”,但是这使得整个安装需要该部分,我只希望在他们选择组本身时需要它。
SectionGroup "group"
Section "required for section group"
SectionIn RO
SectionEnd
Section "optional"
SectionEnd
SectionGroupEnd
答案 0 :(得分:3)
您不能仅使用属性执行此操作,而是需要一些实际代码:
!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
请注意,取消选中部分组本身时会出现“错误”,要解决此问题,您需要保留一些全局状态,因为nsis不会告诉您哪个部分生成了通知。以下代码具有更好的逻辑:
!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
答案 1 :(得分:0)
还可以使用SectionSetFlags命令将这些部分设置为必填部分。您只需将其添加到.onInit函数中,如下所示:
SectionGroup "group" Sec01
Section "required for section group"
SectionIn RO
SectionEnd
Section "optional" Sec01
SectionEnd
SectionGroupEnd
Function .onInit
SectionSetFlags ${Sec01} 17
FunctionEnd
这将使“组”变灰,但是将选择并安装它。