脚本:选择不同组件

优质
小牛编辑
126浏览
2023-12-01

引用脚本内容:

!define CUST_INI "$PLUGINSDIR\custom.ini"
!include Logiclib.nsh
!include Sections.nsh

!define SEC1_TEXT "Section One"   ;组件1
!define SEC2_TEXT "Section Two"   ;组件2
!define SEC3_TEXT "Section Three" ;组件3
outfile "test.exe"
showinstdetails show
Installdir "$PROGRAMFILES\My App"

page custom CreateCustom ;显示自定义页面
page components func_pre ;自定义参数
page directory
page instfiles

section "${SEC1_TEXT}" sec1 ;组件1
detailprint "section 1 selected"
sectionend

section "${SEC2_TEXT}" sec2 ;组件2
detailprint "section 2 selected"
sectionend

section "${SEC3_TEXT}" sec3 ;组件3
detailprint "section 3 selected"
sectionend

Function .onInit
    InitPluginsDir

      WriteINIStr "${CUST_INI}" "Settings" "NumFields" "3"

      WriteINIStr "${CUST_INI}" "field 1" "type" "radiobutton"
      WriteINIStr "${CUST_INI}" "field 1" "left" "30"
      WriteINIStr "${CUST_INI}" "field 1" "right" "-30"
      WriteINIStr "${CUST_INI}" "field 1" "top" "40"
      WriteINIStr "${CUST_INI}" "field 1" "bottom" "52"
      WriteINIStr "${CUST_INI}" "field 1" "Text" "Unselect and hide section 1"
      WriteINIStr "${CUST_INI}" "field 1" "state" "1"    ;组件1 state=1
      WriteINIStr "${CUST_INI}" "field 1" "flags" "GROUP"
;http://blog.163.com/53_54/
      WriteINIStr "${CUST_INI}" "field 2" "type" "radiobutton"
      WriteINIStr "${CUST_INI}" "field 2" "left" "30"
      WriteINIStr "${CUST_INI}" "field 2" "right" "-30"
      WriteINIStr "${CUST_INI}" "field 2" "top" "60"
      WriteINIStr "${CUST_INI}" "field 2" "bottom" "72"
      WriteINIStr "${CUST_INI}" "field 2" "Text" "Unselect and hide section 2"
      WriteINIStr "${CUST_INI}" "field 2" "state" "0"   ;组件2 state=0

      WriteINIStr "${CUST_INI}" "field 3" "type" "radiobutton"
      WriteINIStr "${CUST_INI}" "field 3" "left" "30"
      WriteINIStr "${CUST_INI}" "field 3" "right" "-30"
      WriteINIStr "${CUST_INI}" "field 3" "top" "80"
      WriteINIStr "${CUST_INI}" "field 3" "bottom" "92"
      WriteINIStr "${CUST_INI}" "field 3" "Text" "Unselect and hide section 3"
      WriteINIStr "${CUST_INI}" "field 3" "state" "0" ;组件3 state=0
FunctionEnd

Function CreateCustom ;显示自定义页面
        InstallOptions::Dialog "${CUST_INI}"
   pop $0
FunctionEnd

Function func_pre ;自定义页面参数
       ReadINIStr $0 "${CUST_INI}" "field 1" "state"    ;当组件1 state=1时候
       ${If} $0 = 1
            !insertmacro UnselectSection ${sec1} ;不显示组件1   UN
            SectionSetText ${sec1} ""
            !insertmacro SelectSection ${sec2}   ;显示组件2
            SectionSetText ${sec2} "${SEC2_TEXT}"
            !insertmacro SelectSection ${sec3}    ;显示组件3
            SectionSetText ${sec3} "${SEC3_TEXT}"
       ${ElseIf} $0 = 0
        ReadINIStr $1 "${CUST_INI}" "field 2" "state"
        ${AndIf} $1 = 1
            !insertmacro UnselectSection ${sec2}
            SectionSetText ${sec2} ""
            !insertmacro SelectSection ${sec1}
            SectionSetText ${sec1} "${SEC1_TEXT}"
            !insertmacro SelectSection ${sec3}
            SectionSetText ${sec3} "${SEC3_TEXT}"
       ${Else}
            !insertmacro UnselectSection ${sec3}
            SectionSetText ${sec3} ""
            !insertmacro SelectSection ${sec2}
            SectionSetText ${sec2} "${SEC2_TEXT}"
            !insertmacro SelectSection ${sec1}
            SectionSetText ${sec1} "${SEC1_TEXT}"
       ${EndIf}
FunctionEnd
;下端被注释部分无再次返回选择,上端拥有返回
/*
Function func_pre
       GetDlgItem $R0 $HWNDPARENT 3
       EnableWindow $R0 0

       ReadINIStr $0 "${CUST_INI}" "field 1" "state"
       ${If} $0 = 1
            !insertmacro UnselectSection ${sec1}
            SectionSetText ${sec1} ""
       ${ElseIf} $0 = 0
        ReadINIStr $1 "${CUST_INI}" "field 2" "state"
        ${AndIf} $1 = 1
            !insertmacro UnselectSection ${sec2}
            SectionSetText ${sec2} ""
       ${Else}
            !insertmacro UnselectSection ${sec3}
            SectionSetText ${sec3} ""
       ${EndIf}
FunctionEnd