使用/ COMPONENTSONLYONCUSTOM时如何确保取消选择所有组件?

时间:2013-10-18 19:50:41

标签: installation nsis

我有以下NSIS安装类型:

  

InstType“X(推荐)”
    InstType“/ CUSTOMSTRING = Y(高级模式)”
    InstType / COMPONENTSONLYONCUSTOM

这个想法是安装“X”应该静默安装所有组件,而安装“Y”应该只安装已经选择的组件。默认情况下,应取消选择安装“Y”的组件。这是我无法实现的目标。

我尝试了很多不同的场景来取消选择安装“Y”的所有组件,但由于某些原因,NSIS总是选择“X”作为“Y”的默认值。由于已为“X”选择了所有组件,因此安装“Y”将默认选择所有组件。

如何确保在此方案中默认取消选择所有组件安装“Y”?

1 个答案:

答案 0 :(得分:2)

/ CUSTOMSTRING InstType很特别,所以你可能会在这里稍微弯曲一下规则,自定义就是让用户选择部分并最终得到与你预定义的任何InstType不同的东西。它没有真正的默认值,它基于用户选择的先前InstType(在您的情况下,它总是X)。

!include LogicLib.nsh
!include Sections.nsh
!include WinMessages.nsh

Page Components
Page InstFiles

!define ITSIN_X 1 ; SectionIn ID's are 1 based
InstType "X (recommended)"
InstType "/CUSTOMSTRING=Y (advanced mode)" ; The "special" custom InstType
InstType /COMPONENTSONLYONCUSTOM

Section "A" SID_A
SectionIn ${ITSIN_X}
DetailPrint a
SectionEnd

Section "B" SID_B
SectionIn ${ITSIN_X}
DetailPrint b
SectionEnd

Function .onSelChange
/*
UNDOCUMENTED HACK!
We are going to check if the current InstType is the custom type even if the current section "selection" matches another InstType (GetCurInstType returns non-custom if possible)
*/
FindWindow $9 "#32770" "" $HWNDPARENT
FindWindow $9 "ComboBox" "" $9
SendMessage $9 ${CB_GETCURSEL} 0 0 $0
SendMessage $9 ${CB_GETITEMDATA} $0 0 $0
${If} $0 = ${NSIS_MAX_INST_TYPES} ; The custom InstType?
${AndIf} $1 <> $0 ; Only do the unselect hack on InstType changes (BUGBUG: Should really set $1 to something in the page create/show callback)
!if 1 ; If you only have a few sections you can just use their ID
    !insertmacro UnselectSection ${SID_A}
    !insertmacro UnselectSection ${SID_B}
!else ; ...or use a loop if you are lazy
    StrCpy $2 0
    ClearErrors
    loop:
        SectionGetFlags $2 $3
        IfErrors end
        !insertmacro UnselectSection $2 ; You could check SectionGetText if you need to skip hidden sections here
        IntOp $2 $2 + 1
        Goto loop
    end:
!endif
${EndIf}
StrCpy $1 $0 ; Save the current InstType so we can tell if it changes
FunctionEnd