Change download location for Inno Setup TDownloadWizardPage

667 Views Asked by At

I'm using Inno Setup's download system, but I would like to change the download folder from {tmp} to another one, can someone help me?

of:

DownloadPage.Add('{#LinkJava}', ExpandConstant('{tmp}\Java.exe'), '');

for:

DownloadPage.Add('{#LinkJava}', ExpandConstant('{src}{#PastaGeralDeApps}{#PastaDownPlugins}{#NomeExeJava}'), '');

I'm creating an automatic installer and I need to store the apps in a folder, to use offline.

2

There are 2 best solutions below

1
On

You cannot change the folder, where the files are downloaded to using TDownloadWizardPage (note that the BaseName argument of TDownloadWizardPage.Add accepts a filename only, not a path).

But you can copy over the files to the final folder, once they are downloaded.

[Files]
Source: "{tmp}\downloaded-file.exe"; DestDir: "{app}"; flags: external

You of course need to download the files before the actual installation. So for example from NextButtonClick(wpReady), the way the official CodeDownloadFiles.iss example does.


If you need to move the files to the final location before the installation, use RenameFile or FileCopy functions. The copying is obviously slower, but more reliable, as you cannot move/rename between disks/filesystems. You might try moving, falling back to copying, if moving fails.

1
On
//function that performs the download - OK
function DownloadFiles(Url, Destination, FileName, Hash : String): Boolean;
begin
    DownloadPage.Clear;    
    DownloadPage.Add(Url, FileName, Hash);     
    DownloadPage.Show;
    try
      try
        DownloadPage.Download;
        Result := True;
      except
        if DownloadPage.AbortedByUser then
          Log('Aborted by user.')
        else
          SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
        Result := False;
      end;
    finally
      FileCopyLogged(ExpandConstant('{tmp}\'+FileName), ExpandConstant(Destination+'\'+FileName), False);      
    end;
    Result := True;     
end;