18

I am using Inno Setup to distribute my application.

Is it possible to check in Inno Script for a particular condition and download and install some file from internet if required?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Ashish Sharma
  • 357
  • 2
  • 5
  • 16

4 Answers4

20

Inno Setup 6.1 and newer has a built-in support for downloads. No 3rd party solution are needed anymore.

Check the Examples\CodeDownloadFiles.iss in Inno Setup installation folder.

The important parts of the example are:

[Files]
; These files will be downloaded
Source: "{tmp}\innosetup-latest.exe"; DestDir: "{app}"; Flags: external
Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: external
[Code]
var
  DownloadPage: TDownloadWizardPage;

function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
begin
  if Progress = ProgressMax then
    Log(Format('Successfully downloaded file to {tmp}: %s', [FileName]));
  Result := True;
end;

procedure InitializeWizard;
begin
  DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpReady then begin
    DownloadPage.Clear;
    DownloadPage.Add('https://jrsoftware.org/download.php/is.exe', 'innosetup-latest.exe', '');
    DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll', 'ISCrypt.dll', '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc');
    DownloadPage.Show;
    try
      try
        DownloadPage.Download;
        Result := True;
      except
        SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
        Result := False;
      end;
    finally
      DownloadPage.Hide;
    end;
  end else
    Result := True;
end;

enter image description here


For alternatives, see Running a program after it is downloaded in Code section in Inno Setup.

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

Inno Download Plugin by Mitrich Software.

  • It's an InnoSetup script and DLL, which allows you to download files as part of your installation.
  • It supports FTP, HTTP and HTTPS.
  • It's kind of a drop-in replacement for InnoTools Downloader. Only few changes required.
  • It brings a decent download display and HTTPS and Mirror(s) support.

Example:

#include <idp.iss>

[Files]
Source: "{tmp}\file.zip"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576

[Code]
procedure InitializeWizard();
begin
  idpAddFileSize('http://127.0.0.1/file.zip', ExpandConstant('{tmp}\file.zip'), 1048576);

  idpDownloadAfter(wpReady);
end.
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
11

Yes, there is a library called InnoTools Downloader which has samples that do pretty much this. They can be conditioned on anything you want using normal Inno code.

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • 1
    InnoTools Downloader is dead (not maintained + does not support Unicode Inno Setup + does not support HTTPS + etc). Use Inno Download Plugin instead, as shown in the answer by @Jens. – Martin Prikryl May 28 '19 at 05:32
  • 4
    And now, Inno Setup 6.1 supports downloads natively. So no 3rd party solution is needed. See [my answer](https://stackoverflow.com/q/6887428/850848#66100456). – Martin Prikryl Feb 08 '21 at 12:16
2

Found on Inno 3rd Party is one very similar in scope and style to the Inno Download Plugin, DWinsHs.
Included with an easy and intuitive chm file which requires unblocking to view.

Laurie Stearn
  • 959
  • 1
  • 13
  • 34
  • 4
    Please note: link only answers are discouraged - they turn useless when the links break. And links tend to break. Often. – GhostCat Jun 22 '17 at 07:32