最新消息:

NSIS 选择不同组件

nsis 永恒心锁 1465浏览 0评论
!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
免责声明:根据《计算机软件保护条例》第十七条规定“为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。”您需知晓本站所有内容资源均来源于网络,仅供用户交流学习与研究使用,版权归属原版权方所有,版权争议与本站无关,用户本人下载后不能用作商业或非法用途,需在24个小时之内从您的电脑中彻底删除上述内容,否则后果均由用户承担责任;如果您访问和下载此文件,表示您同意只将此文件用于参考、学习而非其他用途,否则一切后果请您自行承担,如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。丨本站为个人博客非盈利性站点,所有软件信息均来自网络,所有资源仅供学习参考研究目的,并不贩卖软件,不存在任何商业目的及用途。丨本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权BY-NC-SA协议进行授权

转载请注明:永恒心锁-分享互联网 » NSIS 选择不同组件

您必须 登录 才能发表评论!