正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!
您需要 登录 才可以下载或查看,没有账号?立即注册
x
用 INNO 制作安装程序,通常是把软件的所有文件打包(压缩)到一个安装程序文件 setup.exe。其实 INNO 也可以制作带外部文件的安装程序,也就是制作安装程序时并不把文件打包,只是在运行安装程序时才把这些外部文件(比如从光盘中)复制到软件的安装目录或者系统中的其它位置。写 [Files] 段的脚本时,只要使用标签 external 就可以做到这一点,比如:
[Files]
Source: "{src}\*.doc"; DestDir: "{app}"; Flags: external
用这种方式制作的安装包有个缺点就是文件数量多,而且文件没有被压缩,因此占用的空间大。
下面介绍另外一种制作带外部文件的安装包的方法。假设你的软件除了必需安装的文件外,还可以包括某些常用的插件(组件1)以及某些高级插件(组件2)。你希望在你的安装程序中只是打包那些必需安装的文件,而组件1和组件2则分别单独打包(压缩)为外部文件。这样做的好处是,用户可以根据自己的需要只下载安装程序以及某些组件,而你的安装程序则可以根据这些外部文件存在的情况给用户相应的选择。
这些外部文件是用 ZIP 格式压缩过的,为了不让人一看就知道是 ZIP 文件,所以将它们命名为 data1.dat、data2.dat 等等。
示例中使用的是一个简单的 ZIP 文件解压插件。当然你也可以使用其它比如支持带密码保护的 ZIP 文件的插件。另外你也可以在脚本中增加对插件外部文件进行校验的功能。
- ; Inno Setup 脚本
- ; 该示例脚本显示如何创建的带外部文件的安装程序。运行安装程序时用户可以根据外部文件存在的情况选择安装相应的组件。
- ; 外部文件保存在安装程序所的目录中的子目录 data 中,外部文件是 ZIP 压缩文件,命名为 data1.dat、data2.dat 等等
- ; 分别相应于组件 1、组件 2 等等。
- ;
- ;
- [Setup]
- AppName=组件安装示例程序
- AppVerName=组件安装示例程序 1.0
- DefaultDirName={pf}\_组件安装示例程序
- DefaultGroupName=组件安装示例程序
- [Messages]
- ComponentsDiskSpaceMBLabel=当前的选择至少需要 [mb] MB 磁盘空间(不包括解压后组件的大小)。
- [Files]
- ; 安装临时文件:解压外部文件所需的插件 unzipw32.dll
- Source: "unzipw32.dll"; DestDir: "{tmp}"; Flags: dontcopy
- ; 安装运行软件所必需的文件
- Source: "MyProg.exe"; DestDir: "{app}"; components: installmust
- Source: "MyProg.hlp"; DestDir: "{app}"; components: installmust
- [Components]
- Name: "installmust"; Description: "主程序(必需)"; Types: compact full custom; Flags: fixed
- Name: "installdata1"; Description: "组件 1 (常用插件)"; Types: full custom
- Name: "installdata2"; Description: "组件 2 (高级插件)"; Types: full custom
- [UninstallDelete]
- ; 卸载时删除外部解压的文件
- Type: filesandordirs; Name: "{app}\data1"
- Type: filesandordirs; Name: "{app}\data2"
- [Code]
- var dummysize, size1, size2: longint;
- // 从 unzipw32.dll 插件中要调用的函数
- function FileUnzipEx(SourceZipFile, TargetDirectory, FileSpecs: pChar ): integer;
- external 'FileUnzipEx@files:unzipw32.dll stdcall delayload';
- Function UnzipSize(SourceZipFile:pChar; Var Compressed:Longint):longint;
- external 'UnzipSize@files:unzipw32.dll stdcall delayload';
- // 点击组件列表后刷新显示的内容
- procedure ComponentsListOnClick(Sender: TObject);
- begin
- if WizardForm.ComponentsList.CHECKED[1] then
- WizardForm.ComponentsList.ITEMSUBITEM[1]:= '解压后 ' + intTOstr(size1 div 1024) + ' KB';
- if not WizardForm.ComponentsList.ITEMENABLED[1] then
- WizardForm.ComponentsList.ITEMSUBITEM[1]:= '无安装数据';
- if WizardForm.ComponentsList.CHECKED[2] then
- WizardForm.ComponentsList.ITEMSUBITEM[2]:= '解压后 ' + intTOstr(size2 div 1024) + ' KB';
- if not WizardForm.ComponentsList.ITEMENABLED[2] then
- WizardForm.ComponentsList.ITEMSUBITEM[2]:= '无安装数据';
- end;
- // 初始化安装向导
- procedure InitializeWizard();
- begin
- // 释放临时文件
- ExtractTemporaryFile(ExpandConstant('unzipw32.dll'));
- WizardForm.TYPESCOMBO.Visible:= false;
- WizardForm.ComponentsList.Onclick:= @ComponentsListOnClick;
- // 根据外部文件存在的情况确定哪些组件可用
- if not FileExists(ExpandConstant('{src}\data\data1.dat')) then
- begin
- WizardForm.ComponentsList.ITEMENABLED[1]:= false;
- WizardForm.ComponentsList.CHECKED[1]:= false;
- WizardForm.ComponentsList.ITEMSUBITEM[1]:= '无安装数据';
- end
- else
- begin
- WizardForm.ComponentsList.ITEMENABLED[1]:= true;
- WizardForm.ComponentsList.CHECKED[1]:= true;
- size1 := UnzipSize(PChar(ExpandConstant('{src}\data\data1.dat')), dummysize);
- WizardForm.ComponentsList.ITEMSUBITEM[1]:= '解压后 ' + intTOstr(size1 div 1024) + ' KB';
- end;
- if not FileExists(ExpandConstant('{src}\data\data2.dat')) then
- begin
- WizardForm.ComponentsList.ITEMENABLED[2]:= false;
- WizardForm.ComponentsList.CHECKED[2]:= false;
- WizardForm.ComponentsList.ITEMSUBITEM[2]:= '无安装数据';
- end
- else
- begin
- WizardForm.ComponentsList.ITEMENABLED[2]:= true;
- WizardForm.ComponentsList.CHECKED[2]:= true;
- size2 := UnzipSize(PChar(ExpandConstant('{src}\data\data2.dat')), dummysize);
- WizardForm.ComponentsList.ITEMSUBITEM[2]:= '解压后 ' + intTOstr(size2 div 1024) + ' KB';
- end;
- end;
- // 根据组件选择的情况从外部文件中解压组件到指定的位置,比如子目录 {app}\data1 和 {app}\data2
- procedure CurStepChanged(CurStep: TSetupStep);
- var n: integer;
- begin
- if CurStep=ssInstall then
- begin
- if IsComponentSelected('installdata1') then
- n:= FileUnzipEx(PChar(ExpandConstant('{src}\data\data1.dat')), PChar(ExpandConstant('{app}\data1')), '*.*');
- if IsComponentSelected('installdata2') then
- n:= FileUnzipEx(PChar(ExpandConstant('{src}\data\data2.dat')), PChar(ExpandConstant('{app}\data2')), '*.*');
- end;
- end;
复制代码 |