使用/COMPONENTSONLYONCUSTOM时如何确保取消选择所有组件? [英] How to make sure all components are deselected when using /COMPONENTSONLYONCUSTOM?

查看:88
本文介绍了使用/COMPONENTSONLYONCUSTOM时如何确保取消选择所有组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下NSIS安装类型:

I have the following NSIS installation types:

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

InstType "X (recommended)"
InstType "/CUSTOMSTRING=Y (advanced mode)"
InstType /COMPONENTSONLYONCUSTOM

这个想法是,安装"X"应静默安装所有组件,而安装"Y"应仅安装已选择的组件.默认情况下,应全部取消选择安装"Y"的组件.这是我无法实现的.

The idea is that installation "X" should install all components silently, whereas installation "Y" should only install components that have been selected. The components of installation "Y" should all be deselected by default. This is something I can't manage to achieve.

我已经尝试了许多不同的方案来取消选择所有要安装"Y"的组件,但是由于某些原因,NSIS始终将选择"X"作为"Y"的默认设置.由于已为"X"选择了所有组件,因此默认情况下将在安装"Y"中选择所有组件.

I have tried a lot of different scenarios to get all components deselected for installation "Y", but for some reason NSIS will always take the selection of "X" as the default for "Y". Since all components have been selected for "X", installation "Y" will have all components selected by default.

在这种情况下,如何确保默认情况下取消选中所有组件安装"Y"?

How can I make sure all components installation "Y" are deselected by default for this scenario?

推荐答案

/CUSTOMSTRING InstType很特殊,因此您可能在这里稍加修改了规则,自定义的目的是让用户选择部分并以与您预定义的InstTypes有所不同.它实际上没有默认值,它基于用户选择的先前InstType(在您的情况下,始终为X).

The /CUSTOMSTRING InstType is special so you are maybe bending the rules a bit here, the point of custom is to let the user cherry pick sections and end up with something different than any of your predefined InstTypes. It does not really have a default, it is based on the previous InstType the user selected (In your case it is always 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

这篇关于使用/COMPONENTSONLYONCUSTOM时如何确保取消选择所有组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆