杉宫竹苑工作室

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

如何创建带外部文件的安装程序

[复制链接]
发表于 2017-3-6 11:17:58 | 显示全部楼层 |阅读模式

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

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

x
  1. ; Inno Setup 脚本
  2. ; 该示例脚本显示如何创建的带外部文件的安装程序。运行安装程序时用户可以根据外部文件存在的情况选择安装相应的组件。
  3. ; 外部文件保存在安装程序所的目录中的子目录 data 中,外部文件是 ZIP 压缩文件,命名为 data1.dat、data2.dat 等等
  4. ; 分别相应于组件 1、组件 2 等等。
  5. ;
  6. ; 汉化新世纪 gnatix 于 2006.09.14

  7. [Setup]
  8. AppName=组件安装示例程序
  9. AppVerName=组件安装示例程序 1.0
  10. DefaultDirName={pf}\_组件安装示例程序
  11. DefaultGroupName=组件安装示例程序

  12. [Messages]
  13. ComponentsDiskSpaceMBLabel=当前的选择至少需要 [mb] MB 磁盘空间(不包括解压后组件的大小)。

  14. [Files]
  15. ; 安装临时文件:解压外部文件所需的插件 unzipw32.dll
  16. Source: "unzipw32.dll"; DestDir: "{tmp}"; Flags: dontcopy
  17. ; 安装运行软件所必需的文件
  18. Source: "MyProg.exe"; DestDir: "{app}"; components: installmust
  19. Source: "MyProg.hlp"; DestDir: "{app}"; components: installmust

  20. [Components]
  21. Name: "installmust"; Description: "主程序(必需)"; Types: compact full custom; Flags: fixed
  22. Name: "installdata1"; Description: "组件 1 (常用插件)"; Types: full custom
  23. Name: "installdata2"; Description: "组件 2 (高级插件)"; Types: full custom

  24. [UninstallDelete]
  25. ; 卸载时删除外部解压的文件
  26. Type: filesandordirs; Name: "{app}\data1"
  27. Type: filesandordirs; Name: "{app}\data2"

  28. [Code]
  29. var dummysize, size1, size2: longint;

  30. // 从 unzipw32.dll 插件中要调用的函数
  31. function FileUnzipEx(SourceZipFile, TargetDirectory, FileSpecs: pChar ): integer;
  32. external 'FileUnzipEx@files:unzipw32.dll stdcall delayload';

  33. Function UnzipSize(SourceZipFile:pChar; Var Compressed:Longint):longint;
  34. external 'UnzipSize@files:unzipw32.dll stdcall delayload';

  35. // 点击组件列表后刷新显示的内容
  36. procedure ComponentsListOnClick(Sender: TObject);
  37. begin
  38. if WizardForm.ComponentsList.CHECKED[1] then
  39.   WizardForm.ComponentsList.ITEMSUBITEM[1]:= '解压后 ' + intTOstr(size1 div 1024) + ' KB';
  40. if not WizardForm.ComponentsList.ITEMENABLED[1] then
  41.   WizardForm.ComponentsList.ITEMSUBITEM[1]:= '无安装数据';
  42. if WizardForm.ComponentsList.CHECKED[2] then
  43.   WizardForm.ComponentsList.ITEMSUBITEM[2]:= '解压后 ' + intTOstr(size2 div 1024) + ' KB';
  44. if not WizardForm.ComponentsList.ITEMENABLED[2] then
  45.   WizardForm.ComponentsList.ITEMSUBITEM[2]:= '无安装数据';
  46. end;

  47. // 初始化安装向导
  48. procedure InitializeWizard();
  49. begin
  50. // 释放临时文件
  51. ExtractTemporaryFile(ExpandConstant('unzipw32.dll'));
  52. WizardForm.TYPESCOMBO.Visible:= false;
  53. WizardForm.ComponentsList.Onclick:= @ComponentsListOnClick;
  54. // 根据外部文件存在的情况确定哪些组件可用
  55. if not FileExists(ExpandConstant('{src}\data\data1.dat')) then
  56.   begin
  57.   WizardForm.ComponentsList.ITEMENABLED[1]:= false;
  58.   WizardForm.ComponentsList.CHECKED[1]:= false;
  59.   WizardForm.ComponentsList.ITEMSUBITEM[1]:= '无安装数据';
  60.   end
  61. else
  62.   begin
  63.   WizardForm.ComponentsList.ITEMENABLED[1]:= true;
  64.   WizardForm.ComponentsList.CHECKED[1]:= true;
  65.   size1 := UnzipSize(PChar(ExpandConstant('{src}\data\data1.dat')), dummysize);
  66.   WizardForm.ComponentsList.ITEMSUBITEM[1]:= '解压后 ' + intTOstr(size1 div 1024) + ' KB';
  67.   end;
  68. if not FileExists(ExpandConstant('{src}\data\data2.dat')) then
  69.   begin
  70.   WizardForm.ComponentsList.ITEMENABLED[2]:= false;
  71.   WizardForm.ComponentsList.CHECKED[2]:= false;
  72.   WizardForm.ComponentsList.ITEMSUBITEM[2]:= '无安装数据';
  73.   end
  74. else
  75.   begin
  76.   WizardForm.ComponentsList.ITEMENABLED[2]:= true;
  77.   WizardForm.ComponentsList.CHECKED[2]:= true;
  78.   size2 := UnzipSize(PChar(ExpandConstant('{src}\data\data2.dat')), dummysize);
  79.   WizardForm.ComponentsList.ITEMSUBITEM[2]:= '解压后 ' + intTOstr(size2 div 1024) + ' KB';
  80.   end;
  81. end;

  82. // 根据组件选择的情况从外部文件中解压组件到指定的位置,比如子目录 {app}\data1 和 {app}\data2
  83. procedure CurStepChanged(CurStep: TSetupStep);
  84. var n: integer;
  85. begin
  86. if CurStep=ssInstall then
  87.   begin
  88.   if IsComponentSelected('installdata1') then
  89.     n:= FileUnzipEx(PChar(ExpandConstant('{src}\data\data1.dat')), PChar(ExpandConstant('{app}\data1')), '*.*');
  90.   if IsComponentSelected('installdata2') then
  91.     n:= FileUnzipEx(PChar(ExpandConstant('{src}\data\data2.dat')), PChar(ExpandConstant('{app}\data2')), '*.*');
  92.   end;
  93. end;
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-11 14:50 , Processed in 0.106457 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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