【问题标题】:Downloading file with Inno Setup only when user chooses to仅当用户选择时才使用 Inno Setup 下载文件
【发布时间】:2021-02-08 19:19:50
【问题描述】:

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

【问题讨论】:

    标签: installation inno-setup pascalscript inno-download-plugin inno-tools-downloader


    【解决方案1】:

    仅在发布我的答案后,我才注意到尽管您标记了问题,但您实际上正在使用 InnoTools 下载器。不要——InnoTools Downloader is dead and unmaintained

    另外请注意,Inno Setup 6.1 内置了对下载的支持。使用该 API,解决方案将更容易,但与 IDP 下面显示的不同。见Inno Setup: Install file from Internet


    在Inno Download Plugin安装的examples文件夹中,有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的组件名称必须小写(实际组件名称可以使用大写)。

    【讨论】:

      【解决方案2】:

      Inno Setup 6.1.2新增DownloadTemporaryFile支持功能,无需使用第三方工具即可下载文件:

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

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

      【讨论】:

        猜你喜欢
        • 2021-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-19
        • 1970-01-01
        • 1970-01-01
        • 2016-09-27
        • 1970-01-01
        相关资源
        最近更新 更多