杉宫竹苑工作室

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

NSIS自定义页面实现多个安装目录的脚本

[复制链接]
发表于 2019-3-1 22:03:51 | 显示全部楼层 |阅读模式

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

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

x
  1. !include "MUI.nsh"
  2. Name "Test App"
  3. OutFile "test.exe"
  4. !insertmacro MUI_PAGE_COMPONENTS
  5. Page custom SetCustom LeaveCustom
  6. !insertmacro MUI_PAGE_INSTFILES
  7. !insertmacro MUI_LANGUAGE "SimpChinese"
  8. ;--------------------------------
  9. Section "SectionA" SecA
  10. ReadINIStr $0 "$PLUGINSDIRtest.ini" "Field 4" State
  11. MessageBox MB_OK "SectionA 的安装路径为:$0"
  12. SectionEnd
  13. Section "SectionB" SecB
  14. ReadINIStr $0 "$PLUGINSDIRtest.ini" "Field 5" State
  15. MessageBox MB_OK "SectionB 的安装路径为:$0"
  16. SectionEnd
  17. Section "SectionC" SecC
  18. ReadINIStr $0 "$PLUGINSDIRtest.ini" "Field 6" State
  19. MessageBox MB_OK "SectionC 的安装路径为:$0"
  20. SectionEnd
  21. Function .Oninit
  22. InitPluginsDir
  23. File /oname=$PLUGINSDIRtest.ini ".test.ini"
  24. FunctionEnd
  25. Function SetCustom
  26. ; 判断勾选的组件,并把未勾选组件的安装路径控件设为不可用
  27. SectionGetFlags ${SecA} $0
  28. StrCmp $0 0 0 +2
  29. WriteINIStr "$PLUGINSDIRtest.ini" "Field 4" "Flags" "Disabled"
  30. StrCmp $0 1 0 +2 ; 如果组件勾选了,还需要去掉 Disabled,这两行代码不能省略
  31. WriteINIStr "$PLUGINSDIRtest.ini" "Field 4" "Flags" ""
  32. SectionGetFlags ${SecB} $0
  33. StrCmp $0 0 0 +2
  34. WriteINIStr "$PLUGINSDIRtest.ini" "Field 5" "Flags" "Disabled"
  35. StrCmp $0 1 0 +2
  36. WriteINIStr "$PLUGINSDIRtest.ini" "Field 5" "Flags" ""
  37. SectionGetFlags ${SecC} $0
  38. StrCmp $0 0 0 +2
  39. WriteINIStr "$PLUGINSDIRtest.ini" "Field 6" "Flags" "Disabled"
  40. StrCmp $0 1 0 +2
  41. WriteINIStr "$PLUGINSDIRtest.ini" "Field 6" "Flags" ""
  42. ; 预定义组件安装路径
  43. WriteINIStr "$PLUGINSDIRtest.ini" "Field 4" "State" "$ProgramFiles"
  44. WriteINIStr "$PLUGINSDIRtest.ini" "Field 5" "State" "$DeskTop"
  45. WriteINIStr "$PLUGINSDIRtest.ini" "Field 6" "State" "$WinDir"
  46. InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIRtest.ini"
  47. !insertmacro MUI_HEADER_TEXT "选择各组件的安装路径" "必须输入有效路径"
  48. InstallOptions::show
  49. Pop $R0
  50. FunctionEnd
  51. Function LeaveCustom
  52. ; 判断用户输入的路径是否合法。
  53. ReadINIStr $0 "$PLUGINSDIRtest.ini" "Field 4" "State"
  54. StrCmp $0 "" 0 +3
  55. MessageBox MB_OK|MB_ICONSTOP "组件 A 的安装路径不能为空!"
  56. Abort
  57. IfFileExists "$0*" +4
  58. MessageBox MB_YESNO|MB_ICONQUESTION "组件 A 的安装路径的安装目录不存在,是否创建该文件夹?" IDYES +2
  59. Abort
  60. CreateDirectory $0
  61. ReadINIStr $0 "$PLUGINSDIRtest.ini" "Field 5" "State"
  62. StrCmp $0 "" 0 +3
  63. MessageBox MB_OK|MB_ICONSTOP "组件 B 的安装路径不能为空!"
  64. Abort
  65. IfFileExists "$0*" +4
  66. MessageBox MB_YESNO|MB_ICONQUESTION "组件 B 的安装路径的安装目录不存在,是否创建该文件夹?" IDYES +2
  67. Abort
  68. CreateDirectory $0
  69. ReadINIStr $0 "$PLUGINSDIRtest.ini" "Field 6" "State"
  70. StrCmp $0 "" 0 +3
  71. MessageBox MB_OK|MB_ICONSTOP "组件 C 的安装路径不能为空!"
  72. Abort
  73. IfFileExists "$0*" +4
  74. MessageBox MB_YESNO|MB_ICONQUESTION "组件 C 的安装路径的安装目录不存在,是否创建该文件夹?" IDYES +2
  75. Abort
  76. CreateDirectory $0
  77. FunctionEnd
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-1 00:37 , Processed in 0.110836 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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