杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1939|回复: 0

NSIS 选择不同组件

[复制链接]
发表于 2017-2-26 11:06:46 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. !define CUST_INI "$PLUGINSDIR\custom.ini"
  2. !include Logiclib.nsh
  3. !include Sections.nsh

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

  10. page custom CreateCustom ;显示自定义页面
  11. page components func_pre  ;自定义参数
  12. page directory
  13. page instfiles

  14. section "${SEC1_TEXT}" sec1 ;组件1
  15. detailprint "section 1 selected"
  16. sectionend

  17. section "${SEC2_TEXT}" sec2  ;组件2
  18. detailprint "section 2 selected"
  19. sectionend

  20. section "${SEC3_TEXT}" sec3 ;组件3
  21. detailprint "section 3 selected"
  22. sectionend

  23. Function .onInit
  24.     InitPluginsDir

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

  26.       WriteINIStr "${CUST_INI}" "field 1" "type" "radiobutton"
  27.       WriteINIStr "${CUST_INI}" "field 1" "left" "30"
  28.       WriteINIStr "${CUST_INI}" "field 1" "right" "-30"
  29.       WriteINIStr "${CUST_INI}" "field 1" "top" "40"
  30.       WriteINIStr "${CUST_INI}" "field 1" "bottom" "52"
  31.       WriteINIStr "${CUST_INI}" "field 1" "Text" "Unselect and hide section 1"
  32.       WriteINIStr "${CUST_INI}" "field 1" "state" "1"   ;组件1 state=1
  33.       WriteINIStr "${CUST_INI}" "field 1" "flags" "GROUP"
  34. ;http://blog.163.com/53_54/
  35.       WriteINIStr "${CUST_INI}" "field 2" "type" "radiobutton"
  36.       WriteINIStr "${CUST_INI}" "field 2" "left" "30"
  37.       WriteINIStr "${CUST_INI}" "field 2" "right" "-30"
  38.       WriteINIStr "${CUST_INI}" "field 2" "top" "60"
  39.       WriteINIStr "${CUST_INI}" "field 2" "bottom" "72"
  40.       WriteINIStr "${CUST_INI}" "field 2" "Text" "Unselect and hide section 2"
  41.       WriteINIStr "${CUST_INI}" "field 2" "state" "0"  ;组件2 state=0

  42.       WriteINIStr "${CUST_INI}" "field 3" "type" "radiobutton"
  43.       WriteINIStr "${CUST_INI}" "field 3" "left" "30"
  44.       WriteINIStr "${CUST_INI}" "field 3" "right" "-30"
  45.       WriteINIStr "${CUST_INI}" "field 3" "top" "80"
  46.       WriteINIStr "${CUST_INI}" "field 3" "bottom" "92"
  47.       WriteINIStr "${CUST_INI}" "field 3" "Text" "Unselect and hide section 3"
  48.       WriteINIStr "${CUST_INI}" "field 3" "state" "0" ;组件3 state=0
  49. FunctionEnd

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

  54. Function func_pre ;自定义页面参数
  55.        ReadINIStr $0  "${CUST_INI}" "field 1" "state"    ;当组件1 state=1时候
  56.        ${If} $0 = 1
  57.             !insertmacro UnselectSection ${sec1}  ;不显示组件1   UN
  58.             SectionSetText ${sec1} ""
  59.             !insertmacro SelectSection ${sec2}  ;显示组件2
  60.             SectionSetText ${sec2} "${SEC2_TEXT}"
  61.             !insertmacro SelectSection ${sec3}   ;显示组件3
  62.             SectionSetText ${sec3} "${SEC3_TEXT}"
  63.        ${ElseIf} $0 = 0
  64.         ReadINIStr $1  "${CUST_INI}" "field 2" "state"
  65.         ${AndIf} $1 = 1
  66.             !insertmacro UnselectSection ${sec2}
  67.             SectionSetText ${sec2} ""
  68.             !insertmacro SelectSection ${sec1}
  69.             SectionSetText ${sec1} "${SEC1_TEXT}"
  70.             !insertmacro SelectSection ${sec3}
  71.             SectionSetText ${sec3} "${SEC3_TEXT}"
  72.        ${Else}
  73.             !insertmacro UnselectSection ${sec3}
  74.             SectionSetText ${sec3} ""
  75.             !insertmacro SelectSection ${sec2}
  76.             SectionSetText ${sec2} "${SEC2_TEXT}"
  77.             !insertmacro SelectSection ${sec1}
  78.             SectionSetText ${sec1} "${SEC1_TEXT}"
  79.        ${EndIf}
  80. FunctionEnd
  81. ;下端被注释部分无再次返回选择,上端拥有返回
  82. /*
  83. Function func_pre
  84.        GetDlgItem $R0 $HWNDPARENT 3
  85.        EnableWindow $R0 0

  86.        ReadINIStr $0  "${CUST_INI}" "field 1" "state"
  87.        ${If} $0 = 1
  88.             !insertmacro UnselectSection ${sec1}
  89.             SectionSetText ${sec1} ""
  90.        ${ElseIf} $0 = 0
  91.         ReadINIStr $1  "${CUST_INI}" "field 2" "state"
  92.         ${AndIf} $1 = 1
  93.             !insertmacro UnselectSection ${sec2}
  94.             SectionSetText ${sec2} ""
  95.        ${Else}
  96.             !insertmacro UnselectSection ${sec3}
  97.             SectionSetText ${sec3} ""
  98.        ${EndIf}
  99. FunctionEnd
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 12:32 , Processed in 0.183223 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表