如何在组件页面中有条件地设置第一个 InstType
How to conditionally set first InstType in Component page
我想根据检查机器上是否已经存在某些文件,有条件地在组件页面中设置第一个安装类型。
我已经尝试过两种不同的方法。 1) 使用 SetCurInstType,2) 在 "file exist" 检查的基础上有条件地定义 InstType 序列顺序。
这两种方法都已使用 UDF 函数进行了测试。此 UDF 函数已被用作 MUI_PAGE_LICENSE 的 MUI_PAGE_CUSTOMFUNCTION_LEAVE 和 MUI_PAGE_COMPONENTS 的 MUI_PAGE_CUSTOMFUNCTION_PRE 的输入。
两个测试都没有按预期工作
方法 1)
InstType "Install (all)"
InstType "Install (minimal)"
!define USER_ALL_INST_TYPE 1
!define USER_MIN_INST_TYPE 2
!define MUI_PAGE_CUSTOMFUNCTION_PRE SetInitInstType
!insertmacro MUI_PAGE_COMPONENTS
Section "1" Sec1
SectionIn ${USER_ALL_INST_TYPE} ${USER_MIN_INST_TYPE}
... other code
SectionEnd
Section "2" Sec2
SectionIn ${USER_ALL_INST_TYPE}
... other code
SectionEnd
Function SetInitInstType
IfFileExists "<file_path>" 0 endSetInitInstType
SetCurInstType ${USER_MIN_INST_TYPE}
endSetInitInstType:
FunctionEnd
方法 2)
!define MUI_PAGE_CUSTOMFUNCTION_PRE SetInitInstType
!insertmacro MUI_PAGE_COMPONENTS
Section "1" Sec1
SectionIn ${USER_ALL_INST_TYPE} ${USER_MIN_INST_TYPE}
... other code
SectionEnd
Section "2" Sec2
SectionIn ${USER_ALL_INST_TYPE}
... other code
SectionEnd
Function SetInitInstType
IfFileExists "<file_path>" 0 SetAllInstType
InstType "Install (minimal)"
InstType "Install (all)"
!define USER_MIN_INST_TYPE 1
!define USER_ALL_INST_TYPE 2
Goto endSetInitInstType
SetAllInstType:
InstType "Install (all)"
InstType "Install (minimal)"
!define USER_ALL_INST_TYPE 1
!define USER_MIN_INST_TYPE 2
endSetInitInstType:
FunctionEnd
条件检查后,如果文件存在,预期结果将是组件页面中的安装模式组合框已使用 "Install (minimal)" 选项初始化
实际结果如下:
方法 1) --> 所有部分都被禁用,安装模式组合框使用 "Custom" 选项初始化
方法 2) --> 我在脚本编译期间收到错误
Section: "1" ->(Sec1)
SectionIn: Usage: SectionIn InstTypeIdx [InstTypeIdx [...]]
Error in script "<script_name>.nsi" on line XXX -- aborting creation process
如有任何建议,我们将不胜感激
不要问我为什么 SectionIn
使用与所有其他 inst 类型函数不同的索引系统。
Unlike SectionIn the index is zero based, which means the first install type's index is 0
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_PRE SetInitInstType
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
!macro AddInstType name text
!define /IfNDef AddInstType_COUNTER 0
InstType "${text}"
!define INSTTYPE_${name}_IDX ${AddInstType_COUNTER} ; For SetCurInstType etc.
!define /ReDef /Math AddInstType_COUNTER ${AddInstType_COUNTER} + 1
!define INSTTYPE_${name}_SIN ${AddInstType_COUNTER} ; For SectionIn
!macroend
!insertmacro AddInstType ALL "Install (all)"
!insertmacro AddInstType MIN "Install (minimal)"
Section "1 (Both)" Sec1
SectionIn ${INSTTYPE_ALL_SIN} ${INSTTYPE_MIN_SIN}
SectionEnd
Section "2 (All only)" Sec2
SectionIn ${INSTTYPE_ALL_SIN}
SectionEnd
Function SetInitInstType
IfFileExists "$WinDir\Explorer.exe" 0 +2
SetCurInstType ${INSTTYPE_MIN_IDX}
FunctionEnd
Function .onInit
Call SetInitInstType ; In case installer is silent, force correct sections
FunctionEnd
我想根据检查机器上是否已经存在某些文件,有条件地在组件页面中设置第一个安装类型。
我已经尝试过两种不同的方法。 1) 使用 SetCurInstType,2) 在 "file exist" 检查的基础上有条件地定义 InstType 序列顺序。
这两种方法都已使用 UDF 函数进行了测试。此 UDF 函数已被用作 MUI_PAGE_LICENSE 的 MUI_PAGE_CUSTOMFUNCTION_LEAVE 和 MUI_PAGE_COMPONENTS 的 MUI_PAGE_CUSTOMFUNCTION_PRE 的输入。
两个测试都没有按预期工作
方法 1)
InstType "Install (all)"
InstType "Install (minimal)"
!define USER_ALL_INST_TYPE 1
!define USER_MIN_INST_TYPE 2
!define MUI_PAGE_CUSTOMFUNCTION_PRE SetInitInstType
!insertmacro MUI_PAGE_COMPONENTS
Section "1" Sec1
SectionIn ${USER_ALL_INST_TYPE} ${USER_MIN_INST_TYPE}
... other code
SectionEnd
Section "2" Sec2
SectionIn ${USER_ALL_INST_TYPE}
... other code
SectionEnd
Function SetInitInstType
IfFileExists "<file_path>" 0 endSetInitInstType
SetCurInstType ${USER_MIN_INST_TYPE}
endSetInitInstType:
FunctionEnd
方法 2)
!define MUI_PAGE_CUSTOMFUNCTION_PRE SetInitInstType
!insertmacro MUI_PAGE_COMPONENTS
Section "1" Sec1
SectionIn ${USER_ALL_INST_TYPE} ${USER_MIN_INST_TYPE}
... other code
SectionEnd
Section "2" Sec2
SectionIn ${USER_ALL_INST_TYPE}
... other code
SectionEnd
Function SetInitInstType
IfFileExists "<file_path>" 0 SetAllInstType
InstType "Install (minimal)"
InstType "Install (all)"
!define USER_MIN_INST_TYPE 1
!define USER_ALL_INST_TYPE 2
Goto endSetInitInstType
SetAllInstType:
InstType "Install (all)"
InstType "Install (minimal)"
!define USER_ALL_INST_TYPE 1
!define USER_MIN_INST_TYPE 2
endSetInitInstType:
FunctionEnd
条件检查后,如果文件存在,预期结果将是组件页面中的安装模式组合框已使用 "Install (minimal)" 选项初始化
实际结果如下:
方法 1) --> 所有部分都被禁用,安装模式组合框使用 "Custom" 选项初始化
方法 2) --> 我在脚本编译期间收到错误
Section: "1" ->(Sec1)
SectionIn: Usage: SectionIn InstTypeIdx [InstTypeIdx [...]]
Error in script "<script_name>.nsi" on line XXX -- aborting creation process
如有任何建议,我们将不胜感激
不要问我为什么 SectionIn
使用与所有其他 inst 类型函数不同的索引系统。
Unlike SectionIn the index is zero based, which means the first install type's index is 0
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_PRE SetInitInstType
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
!macro AddInstType name text
!define /IfNDef AddInstType_COUNTER 0
InstType "${text}"
!define INSTTYPE_${name}_IDX ${AddInstType_COUNTER} ; For SetCurInstType etc.
!define /ReDef /Math AddInstType_COUNTER ${AddInstType_COUNTER} + 1
!define INSTTYPE_${name}_SIN ${AddInstType_COUNTER} ; For SectionIn
!macroend
!insertmacro AddInstType ALL "Install (all)"
!insertmacro AddInstType MIN "Install (minimal)"
Section "1 (Both)" Sec1
SectionIn ${INSTTYPE_ALL_SIN} ${INSTTYPE_MIN_SIN}
SectionEnd
Section "2 (All only)" Sec2
SectionIn ${INSTTYPE_ALL_SIN}
SectionEnd
Function SetInitInstType
IfFileExists "$WinDir\Explorer.exe" 0 +2
SetCurInstType ${INSTTYPE_MIN_IDX}
FunctionEnd
Function .onInit
Call SetInitInstType ; In case installer is silent, force correct sections
FunctionEnd