3

Question: I’d like to know how to script to download a second file which is a zip but initially give a choice between two zip files; download, unzip and delete the zip. The zip files each have different names but the contents have a different name to the zips (each the same name); no renaming required. This question is a little similar to Apply Download file condition in inno-setup

The files in question are downloaded via the SourceForge website. The programs (clones) these files are intended for are either not listed on SF or have changed purpose.

After fixing the PChar bug: InnoTools Downloader not working with Inno 5.5 I'm now able to re-use this Inno Setup script from 2011 but want to expand it slightly but struggling to.

#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;

Working code based on the answer:

#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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Jenn
  • 111
  • 7

2 Answers2

4

Only after posting my answer, I've noticed that despite you tagging the question , you are actually using InnoTools Downloader. Do not – InnoTools Downloader is dead and unmaintained.

Also note that the Inno Setup 6.1 has a built-in support for downloads. With that API, the solution will be easier, but different than what is shown below to IDP. See Inno Setup: Install file from Internet.


In the examples folder of Inno Download Plugin installation, there are components1.iss and components2.iss examples.

The first shows how to use idpAddFileComp to conditionally download a file, when a component is selected.

I'm re-posting a full example:

; 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;

Caveat: The component name passed to idpAddFileComp must be in lowercase (the actual component name can use uppercase).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

Inno Setup 6.1.2 has new DownloadTemporaryFile support function to download files without using a third-party tool:

  • Supports HTTPS (but not expired or self-signed certificates) and HTTP.
  • Redirects are automatically followed and proxy settings are automatically used.
  • Safe to use from services unlike existing third-party tools.
  • Supports SHA-256 hash checking of the downloaded file.
  • Supports basic authentication.

I added this answer because even the IDP plugin referred in the accepted answer was last updated in 2016 and did not work for me now and I had to change to the new function provided by Inno Setup 6.1.2.

Arundale Ramanathan
  • 1,781
  • 1
  • 18
  • 25