2

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I do not think that IDP supports parallel downloads. Why do you think it does? – Martin Prikryl Oct 11 '19 at 05:26
  • @MartinPrikryl then how to download multiple files one after another? any help.. –  Oct 11 '19 at 05:46
  • Your code *does download the two files one after another*. – Martin Prikryl Oct 11 '19 at 05:49
  • nope it is not happening! second file starts downloading before the first one finishes. –  Oct 11 '19 at 05:52
  • i used `idpStopDownload` and `idpStartDownload` as well but no luck. –  Oct 11 '19 at 05:54
  • Can you post a screenshot showing that? – Martin Prikryl Oct 11 '19 at 06:06
  • yes, screenshot has been attached above, please have a look and the status is `cannot connect` –  Oct 11 '19 at 06:16
  • OK, I understand now. You want to download one file, read its contents and download other files based on that. -- The problem is not that the files are not downloaded one after another - They are. -- The problem is that you incorrectly believe that your `TryGetFileLine` code happens *after* the download of he first file. It does not! All your code happens even before the wizard window appears. – Martin Prikryl Oct 11 '19 at 06:33
  • yes,you are right, based on the first downloaded file's contents the second files have to download. Then how to make `TryGetFileLine` wait till it finishes downloading or any other way to read the content of the downloaded files? –  Oct 11 '19 at 06:58

1 Answers1

1

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