2

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.

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

2 Answers2

1

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0
//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;
  • 1
    Consider referring to the implementation of `FileCopyLogged` and doing error checking there. + In general it might be worth trying move first, instead of copy. But I understood that you copy to an USB drive, so moving cannot succeed. + You might want to delete the unneeded file from the `{tmp}` right after copying it, instead of waiting for Inno Setup to do it for you at the end, not to run out of disk space, if you have several downloads. – Martin Prikryl Jun 21 '21 at 18:53