Search code examples
inno-setuppascalscriptinno-download-plugin

Download additional files based on contents of first download using IDP


Want to download files based on contents of first download using Inno Download Plugin (IDP). How to do that?

Here is my code

[Code]
procedure InitializeWizard();
var
  line: string;
  line2: string;
  url: string;
  appname: string;
begin
  idpAddFile('http://download.website.com/files.txt', ExpandConstant('{tmp}\files.txt'));
  idpDownloadAfter(wpReady);
  TryGetFileLine(expandConstant('{tmp}\files.txt'), 0, line);
  TryGetFileLine(expandConstant('{tmp}\files.txt'), 1, line2);
  url := line;
  appname := line2;    
  idpAddFile(url, ExpandConstant('{tmp}\'+appname));
  idpDownloadAfter(wpReady);
end;

Here second file starts downloading before the first file finishes. So how to make it one after another?


Solution

  • Tell IDP to only download the list initially. Then wait for the download to finish (for that see Running a program after it is downloaded in Code section in Inno Setup) and based on the results, create new download list and restart the download.

    var
      ListDownloaded: Boolean;
    
    procedure InitializeWizard();
    begin
      idpAddFile('http://www.example.com/files.txt', ExpandConstant('{tmp}\files.txt'));
      idpDownloadAfter(wpReady);
      ListDownloaded := False;
    end;
    
    function NextButtonClick(CurPageID: Integer): Boolean;
    var
      Url, AppName: string;
    begin
      Result := True;
      if CurPageID = IDPForm.Page.ID then
      begin
        if not ListDownloaded then
        begin
          TryGetFileLine(ExpandConstant('{tmp}\files.txt'), 0, Url);
          TryGetFileLine(ExpandConstant('{tmp}\files.txt'), 1, AppName);
    
          idpClearFiles;
          idpAddFile(Url, ExpandConstant('{tmp}\' + AppName));
          idpFormActivate(nil); { This restarts the download }
          Result := False;
          ListDownloaded := True;
        end;
      end;
    end;