3

问题:我想知道如何编写脚本来下载第二个 zip 文件,但最初会在两个 zip 文件之间进行选择;下载,解压缩并删除zip。每个 zip 文件具有不同的名称,但内容与 zip 具有不同的名称(每个名称相同);无需重命名。这个问题有点类似于应用下载文件条件 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;
4

2 回答 2

3

仅在发布我的答案后,我才注意到尽管您标记了问题,但您实际上正在使用 InnoTools Downloader。不要 - InnoTools 下载器已死且无人维护

另请注意,Inno Setup 6.1 具有对下载的内置支持。使用该 API,解决方案将更容易,但与 IDP 下面显示的不同。请参阅Inno 设置:从 Internet 安装文件


examplesInno Download Plugin 安装文件夹中,有components1.isscomponents2.iss示例。

第一个展示了在选择组件时如何使用idpAddFileComp有条件地下载文件。

我重新发布一个完整的例子:

; 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 必须是小写的(实际的组件名称可以使用大写)。

于 2019-06-04T12:56:34.203 回答
0

Inno Setup 6.1.2新增DownloadTemporaryFile支持不使用第三方工具下载文件的功能:

  • 支持 HTTPS(但未过期或自签名证书)和 HTTP。
  • 自动遵循重定向并自动使用代理设置。
  • 与现有的第三方工具不同,可以从服务中安全使用。
  • 支持对下载文件进行 SHA-256 哈希检查。
  • 支持基本认证。

我添加了这个答案,因为即使是接受的答案中提到的 IDP 插件也是在 2016 年最后更新的,现在对我不起作用,我不得不更改为 Inno Setup 6.1.2 提供的新功能。

于 2020-11-17T17:35:05.193 回答