我要根据检查计算机上是否已经存在某些文件,有条件地在“组件”页面中设置第一种安装类型。
我已经尝试了两种不同的方法。 1)使用SetCurInstType,2)根据“文件存在”检查有条件地定义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
条件检查后,如果文件存在,则预期结果是使用“安装(最小)”选项初始化了“组件中的安装模式组合框”
实际结果如下:
方法1)->禁用所有部分,并使用“自定义”选项初始化安装模式组合框
方法2)->脚本编译期间收到错误消息
Section: "1" ->(Sec1)
SectionIn: Usage: SectionIn InstTypeIdx [InstTypeIdx [...]]
Error in script "<script_name>.nsi" on line XXX -- aborting creation process
任何建议将不胜感激
答案 0 :(得分:0)
不要问我为什么,但是SectionIn
使用的索引系统不同于其他所有inst类型的函数。
与SectionIn不同,索引从零开始,这意味着第一个安装类型的索引为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