杉宫竹苑工作室

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

组件方式实现多目录安装

[复制链接]
发表于 2016-6-22 19:26:25 | 显示全部楼层 |阅读模式

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

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

x
  1. ;自定义页面实现多个安装目录的脚本

  2. !include "MUI.nsh"

  3.   Name "Test App"
  4.   OutFile "test.exe"

  5.   !insertmacro MUI_PAGE_COMPONENTS
  6.   Page custom SetCustom LeaveCustom
  7.   !insertmacro MUI_PAGE_INSTFILES

  8.   !insertmacro MUI_LANGUAGE "SimpChinese"

  9. ;--------------------------------

  10. Section "SectionA" SecA
  11.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 4" State
  12.   MessageBox MB_OK "SectionA 的安装路径为:$0"
  13. SectionEnd

  14. Section "SectionB" SecB
  15.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 5" State
  16.   MessageBox MB_OK "SectionB 的安装路径为:$0"
  17. SectionEnd

  18. Section "SectionC" SecC
  19.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 6" State
  20.   MessageBox MB_OK "SectionC 的安装路径为:$0"
  21. SectionEnd


  22. Function .Oninit
  23.   InitPluginsDir
  24.   File /oname=$PLUGINSDIR\test.ini ".\test.ini"
  25. FunctionEnd

  26. Function SetCustom
  27. ; 判断勾选的组件,并把未勾选组件的安装路径控件设为不可用
  28.   SectionGetFlags ${SecA} $0
  29.   StrCmp $0 0 0 +2
  30.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 4" "Flags" "Disabled"
  31.   StrCmp $0 1 0 +2    ; 如果组件勾选了,还需要去掉 Disabled,这两行代码不能省略
  32.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 4" "Flags" ""
  33.    
  34.   SectionGetFlags ${SecB} $0
  35.   StrCmp $0 0 0 +2
  36.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 5" "Flags" "Disabled"
  37.   StrCmp $0 1 0 +2
  38.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 5" "Flags" ""
  39.    
  40.   SectionGetFlags ${SecC} $0
  41.   StrCmp $0 0 0 +2
  42.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 6" "Flags" "Disabled"
  43.   StrCmp $0 1 0 +2
  44.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 6" "Flags" ""

  45. ; 预定义组件安装路径
  46.   WriteINIStr "$PLUGINSDIR\test.ini" "Field 4" "State" "$ProgramFiles"
  47.   WriteINIStr "$PLUGINSDIR\test.ini" "Field 5" "State" "$DeskTop"
  48.   WriteINIStr "$PLUGINSDIR\test.ini" "Field 6" "State" "$WinDir"

  49.   InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\test.ini"
  50.   !insertmacro MUI_HEADER_TEXT "选择各组件的安装路径" "必须输入有效路径"
  51.   InstallOptions::show
  52.   Pop $R0

  53. FunctionEnd

  54. Function LeaveCustom
  55. ; 判断用户输入的路径是否合法。

  56.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 4" "State"
  57.   StrCmp $0 "" 0 +3
  58.   MessageBox MB_OK|MB_ICONSTOP "组件 A 的安装路径不能为空!"
  59.   Abort
  60.     IfFileExists "$0\*" +4
  61.     MessageBox MB_YESNO|MB_ICONQUESTION "组件 A 的安装路径的安装目录不存在,是否创建该文件夹?" IDYES +2
  62.     Abort
  63.     CreateDirectory $0
  64.       
  65.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 5" "State"
  66.   StrCmp $0 "" 0 +3
  67.   MessageBox MB_OK|MB_ICONSTOP "组件 B 的安装路径不能为空!"
  68.   Abort
  69.     IfFileExists "$0\*" +4
  70.     MessageBox MB_YESNO|MB_ICONQUESTION "组件 B 的安装路径的安装目录不存在,是否创建该文件夹?" IDYES +2
  71.     Abort
  72.     CreateDirectory $0

  73.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 6" "State"
  74.   StrCmp $0 "" 0 +3
  75.   MessageBox MB_OK|MB_ICONSTOP "组件 C 的安装路径不能为空!"
  76.   Abort
  77.     IfFileExists "$0\*" +4
  78.     MessageBox MB_YESNO|MB_ICONQUESTION "组件 C 的安装路径的安装目录不存在,是否创建该文件夹?" IDYES +2
  79.     Abort
  80.     CreateDirectory $0
  81. FunctionEnd
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-17 20:39 , Processed in 0.104515 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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