仅当用户选择时才使用 Inno Setup 下载文件
Downloading file with Inno Setup only when user chooses to
问题:我想知道如何编写脚本来下载第二个 zip 文件,但最初在两个 zip 文件之间进行选择;下载、解压缩并删除 zip。每个 zip 文件都有不同的名称,但内容与 zips 有不同的名称(每个名称相同);无需重命名。这个问题有点类似于Apply Download file condition in inno-setup
有问题的文件是通过 SourceForge 网站下载的。这些文件适用的程序(克隆)未在 SF 上列出或已更改用途。
修复 PChar
错误后:InnoTools Downloader not working with Inno 5.5 我现在可以重新使用 2011 年的这个 Inno Setup 脚本,但想稍微扩展它但很难。
#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');
[Code]
procedure InitializeWizard();
begin
itd_init;
{ Set download source.. }
itd_addfile('http://www.example.com/Textfile.txt', ExpandConstant('{tmp}\Textfile.txt'));
itd_setoption('UI_AllowContinue','1');
itd_setoption('UI_DetailedMode','1');
{ Start the download after the "Ready to install" screen is shown }
itd_downloadafter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then { Lets install the downloaded files }
begin
FileCopy(ExpandConstant('{tmp}\Textfile.txt'), ExpandConstant('{userappdata}\program_name\Textfile.txt'), false);
end;
end;
基于答案的工作代码:
#pragma include __INCLUDE__ + ";" + "c:\lib\InnoDownloadPlugin"
[Setup]
...
CreateUninstallRegKey=no
#include <idp.iss>
...
[Types]
Name: full; Description: "Full installation"
Name: compact; Description: "Compact installation"
Name: custom; Description: "Custom installation"; Flags: iscustom
[Components]
Name: abc; Description: "C File"; Types: full compact custom; Flags: fixed
Name: hlnj; Description: "HL (Recommended)"; Types: custom; Flags: exclusive
Name: hnj; Description: "HF"; Types: custom; Flags: exclusive
[Files]
Source: "{tmp}\text.net"; DestDir: "{userappdata}\ccc"; Flags: external; Components: abc
Source: "{tmp}\HLNJ.zip"; DestDir: "{userappdata}\ccc"; Flags: external; Components: hlnj
Source: "{tmp}\HNJ.zip"; DestDir: "{userappdata}\ccc"; Flags: external; Components: hnj
[Code]
procedure InitializeWizard;
begin
idpAddFileComp('http://www.example.com/text.net', ExpandConstant('{tmp}\text.net'), 'abc');
idpAddFileComp('http://www.example.com/SecurityUpdates/HLNJ.zip', ExpandConstant('{tmp}\HLNJ.zip'), 'hlnj');
idpAddFileComp('http://www.example.com/SecurityUpdates/HNJ.zip', ExpandConstant('{tmp}\HNJ.zip'), 'hnj');
idpDownloadAfter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
FileCopy(ExpandConstant('{tmp}\text.net'), ExpandConstant('{userappdata}\ccc\text.net'), false);
FileCopy(ExpandConstant('{tmp}\HLNJ.zip'), ExpandConstant('{userappdata}\ccc\HLNJ.txt'), false);
FileCopy(ExpandConstant('{tmp}\HNJ.zip'), ExpandConstant('{userappdata}\ccc\HNJ.txt'), false);
end;
end;
仅在发布我的答案后,我才注意到尽管您标记了问题 inno-download-plugin, you are actually using InnoTools Downloader. Do not – InnoTools Downloader is dead and unmaintained。
另请注意,Inno Setup 6.1 built-in 支持下载。有了 API,解决方案会更简单,但与下面显示的 IDP 不同。参见 Inno Setup: Install file from Internet。
在Inno Download Plugin安装的examples
文件夹中,有components1.iss
和components2.iss
个例子
第一个演示如何使用 idpAddFileComp
在选择组件时有条件地下载文件。
我是re-posting一个完整的例子:
; Uncomment one of following lines, if you haven't checked "Add IDP include path to ISPPBuiltins.iss" option during IDP installation:
;#pragma include __INCLUDE__ + ";" + ReadReg(HKLM, "Software\Mitrich Software\Inno Download Plugin", "InstallDir")
;#pragma include __INCLUDE__ + ";" + "c:\lib\InnoDownloadPlugin"
[Setup]
AppName = My Program
AppVersion = 1.0
DefaultDirName = {pf}\My Program
DefaultGroupName = My Program
OutputDir = userdocs:Inno Setup Examples Output
#include <idp.iss>
[Types]
Name: full; Description: "Full installation"
Name: compact; Description: "Compact installation"
Name: custom; Description: "Custom installation"; Flags: iscustom
[Components]
Name: app; Description: "My Program"; Types: full compact custom; Flags: fixed
Name: help; Description: "Help files"; Types: full
Name: src; Description: "Source code"; Types: full
[Files]
Source: "{tmp}\app.exe"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: app
Source: "{tmp}\help.chm"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: help
Source: "{tmp}\src.zip"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: src
[Icons]
Name: "{group}\My Program"; Filename: "app.exe"; Components: app
Name: "{group}\Help file"; Filename: "help.chm"; Components: help
Name: "{group}\{cm:UninstallProgram,My Program}"; Filename: "{uninstallexe}"
[Code]
procedure InitializeWizard;
begin
idpAddFileComp('http://127.0.0.1/app.exe', ExpandConstant('{tmp}\app.exe'), 'app');
idpAddFileComp('http://127.0.0.1/help.chm', ExpandConstant('{tmp}\help.chm'), 'help');
idpAddFileComp('http://127.0.0.1/src.zip', ExpandConstant('{tmp}\src.zip'), 'src');
idpDownloadAfter(wpReady);
end;
注意:传递给idpAddFileComp
的组件名必须小写(实际组件名可以大写)
Inno Setup 6.1.2新增DownloadTemporaryFile
支持功能,无需第三方工具即可下载文件:
- 支持 HTTPS(但不支持过期或自签名证书)和 HTTP。
- 自动遵循重定向并自动使用代理设置。
- 不同于现有的第三方工具,可以通过服务安全使用。
- 支持下载文件的 SHA-256 哈希检查。
- 支持基本身份验证。
我添加这个答案是因为即使是接受的答案中提到的 IDP 插件也是在 2016 年最后更新的,现在对我不起作用,我不得不更改为 Inno Setup 6.1.2 提供的新功能。
问题:我想知道如何编写脚本来下载第二个 zip 文件,但最初在两个 zip 文件之间进行选择;下载、解压缩并删除 zip。每个 zip 文件都有不同的名称,但内容与 zips 有不同的名称(每个名称相同);无需重命名。这个问题有点类似于Apply Download file condition in inno-setup
有问题的文件是通过 SourceForge 网站下载的。这些文件适用的程序(克隆)未在 SF 上列出或已更改用途。
修复 PChar
错误后:InnoTools Downloader not working with Inno 5.5 我现在可以重新使用 2011 年的这个 Inno Setup 脚本,但想稍微扩展它但很难。
#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');
[Code]
procedure InitializeWizard();
begin
itd_init;
{ Set download source.. }
itd_addfile('http://www.example.com/Textfile.txt', ExpandConstant('{tmp}\Textfile.txt'));
itd_setoption('UI_AllowContinue','1');
itd_setoption('UI_DetailedMode','1');
{ Start the download after the "Ready to install" screen is shown }
itd_downloadafter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then { Lets install the downloaded files }
begin
FileCopy(ExpandConstant('{tmp}\Textfile.txt'), ExpandConstant('{userappdata}\program_name\Textfile.txt'), false);
end;
end;
基于答案的工作代码:
#pragma include __INCLUDE__ + ";" + "c:\lib\InnoDownloadPlugin"
[Setup]
...
CreateUninstallRegKey=no
#include <idp.iss>
...
[Types]
Name: full; Description: "Full installation"
Name: compact; Description: "Compact installation"
Name: custom; Description: "Custom installation"; Flags: iscustom
[Components]
Name: abc; Description: "C File"; Types: full compact custom; Flags: fixed
Name: hlnj; Description: "HL (Recommended)"; Types: custom; Flags: exclusive
Name: hnj; Description: "HF"; Types: custom; Flags: exclusive
[Files]
Source: "{tmp}\text.net"; DestDir: "{userappdata}\ccc"; Flags: external; Components: abc
Source: "{tmp}\HLNJ.zip"; DestDir: "{userappdata}\ccc"; Flags: external; Components: hlnj
Source: "{tmp}\HNJ.zip"; DestDir: "{userappdata}\ccc"; Flags: external; Components: hnj
[Code]
procedure InitializeWizard;
begin
idpAddFileComp('http://www.example.com/text.net', ExpandConstant('{tmp}\text.net'), 'abc');
idpAddFileComp('http://www.example.com/SecurityUpdates/HLNJ.zip', ExpandConstant('{tmp}\HLNJ.zip'), 'hlnj');
idpAddFileComp('http://www.example.com/SecurityUpdates/HNJ.zip', ExpandConstant('{tmp}\HNJ.zip'), 'hnj');
idpDownloadAfter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
FileCopy(ExpandConstant('{tmp}\text.net'), ExpandConstant('{userappdata}\ccc\text.net'), false);
FileCopy(ExpandConstant('{tmp}\HLNJ.zip'), ExpandConstant('{userappdata}\ccc\HLNJ.txt'), false);
FileCopy(ExpandConstant('{tmp}\HNJ.zip'), ExpandConstant('{userappdata}\ccc\HNJ.txt'), false);
end;
end;
仅在发布我的答案后,我才注意到尽管您标记了问题 inno-download-plugin, you are actually using InnoTools Downloader. Do not – InnoTools Downloader is dead and unmaintained。
另请注意,Inno Setup 6.1 built-in 支持下载。有了 API,解决方案会更简单,但与下面显示的 IDP 不同。参见 Inno Setup: Install file from Internet。
在Inno Download Plugin安装的examples
文件夹中,有components1.iss
和components2.iss
个例子
第一个演示如何使用 idpAddFileComp
在选择组件时有条件地下载文件。
我是re-posting一个完整的例子:
; Uncomment one of following lines, if you haven't checked "Add IDP include path to ISPPBuiltins.iss" option during IDP installation:
;#pragma include __INCLUDE__ + ";" + ReadReg(HKLM, "Software\Mitrich Software\Inno Download Plugin", "InstallDir")
;#pragma include __INCLUDE__ + ";" + "c:\lib\InnoDownloadPlugin"
[Setup]
AppName = My Program
AppVersion = 1.0
DefaultDirName = {pf}\My Program
DefaultGroupName = My Program
OutputDir = userdocs:Inno Setup Examples Output
#include <idp.iss>
[Types]
Name: full; Description: "Full installation"
Name: compact; Description: "Compact installation"
Name: custom; Description: "Custom installation"; Flags: iscustom
[Components]
Name: app; Description: "My Program"; Types: full compact custom; Flags: fixed
Name: help; Description: "Help files"; Types: full
Name: src; Description: "Source code"; Types: full
[Files]
Source: "{tmp}\app.exe"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: app
Source: "{tmp}\help.chm"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: help
Source: "{tmp}\src.zip"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: src
[Icons]
Name: "{group}\My Program"; Filename: "app.exe"; Components: app
Name: "{group}\Help file"; Filename: "help.chm"; Components: help
Name: "{group}\{cm:UninstallProgram,My Program}"; Filename: "{uninstallexe}"
[Code]
procedure InitializeWizard;
begin
idpAddFileComp('http://127.0.0.1/app.exe', ExpandConstant('{tmp}\app.exe'), 'app');
idpAddFileComp('http://127.0.0.1/help.chm', ExpandConstant('{tmp}\help.chm'), 'help');
idpAddFileComp('http://127.0.0.1/src.zip', ExpandConstant('{tmp}\src.zip'), 'src');
idpDownloadAfter(wpReady);
end;
注意:传递给idpAddFileComp
的组件名必须小写(实际组件名可以大写)
Inno Setup 6.1.2新增DownloadTemporaryFile
支持功能,无需第三方工具即可下载文件:
- 支持 HTTPS(但不支持过期或自签名证书)和 HTTP。
- 自动遵循重定向并自动使用代理设置。
- 不同于现有的第三方工具,可以通过服务安全使用。
- 支持下载文件的 SHA-256 哈希检查。
- 支持基本身份验证。
我添加这个答案是因为即使是接受的答案中提到的 IDP 插件也是在 2016 年最后更新的,现在对我不起作用,我不得不更改为 Inno Setup 6.1.2 提供的新功能。