Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

installation - Running a program after it is downloaded in Code section in Inno Setup

How do I run an application I have downloaded over the Internet, in the code section using, and also wait for that application to finish running. I have, using InnoTools downloader, downloaded these two files and I want to, after the second one is done downloading to run that download, or jdk-8u111-windows-x64.exe, then continue the installation.

[Code]?

procedure InitializeWizard();?
begin?
? ? ?ITD_Init;

? ? ?ITD_AddFile('http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M13/bin/apache-tomcat-9.0.0.M13-windows-x64.zip', expandconstant('{tmp}apache-tomcat-9.0.0.M13-windows-x64.zip'));

? ? ?ITD_DownloadAfter(1);?

? ? ?ITD_AddFile('http://files.downloadnow-1.com/s/software/15/62/36/39/jdk-8u111-windows-x64.exe?token=1479511171_b51e94edd4e002c94fd60a570a7dd270&fileName=jdk-8u111-windows-x64.exe',expandconstant('{tmp}jdk-8u111-windows-x64.exe'));

? ? ?ITD_DownloadAfter(2); ? ? ??
end;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use other download plugin, not ITD (see below for reasons).


Inno Setup 6.1 supports downloads natively. See Inno Setup: Install file from Internet


If you are stuck with an older version of Inno Setup, use the Inno Download Plugin.

When you include idp.iss, it defines a global IDPForm structure. Its Page field is the TWizardPage, representing a download page. Use its ID in the NextButtonClick to run the downloaded file, once the download finishes (the "Next" button on the download page is "pressed" automatically):

#include <idp.iss>

[Code]

procedure InitializeWizard;
begin
  idpAddFile(
    'https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M13/bin/' +
      'apache-tomcat-9.0.0.M13-windows-x64.zip',
    ExpandConstant('{tmp}apache-tomcat-9.0.0.M13-windows-x64.zip'));
  idpAddFile(
    'https://www.example.com/jdk-8u111-windows-x64.exe',
    ExpandConstant('{tmp}jdk-8u111-windows-x64.exe'));
  idpDownloadAfter(wpSelectDir);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
  FileName: string;
begin
  if CurPageID = IDPForm.Page.ID then
  begin
    FileName := ExpandConstant('{tmp}jdk-8u111-windows-x64.exe');
    Result := Exec(FileName, '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    if not Result then
    begin
      MsgBox('Cannot execute sub-installer', mbError, MB_OK);
    end
      else
    begin
      Result := (ResultCode = 0);
      if not Result then
      begin
        MsgBox('Sub-installer failed', mbError, MB_OK);
      end
    end;
  end
    else
  begin
    Result := True;
  end;
end;

There's also DwinsHs (Downloader for Inno Setup).


While you can implement the same using InnoTools Downloader, you should avoid it:

  • It's outdated and not maintained anymore;
  • Does not support Unicode Inno Setup (do not use Ansi Inno Setup for new projects);
  • Does not support HTTPS;
  • Its download page does not scale on high DPI.

Anyway, for completeness: the ITD_DownloadAfter returns TWizardPage, representing a download page. Use its ID in the NextButtonClick to run the downloaded file, once the download finishes (the "Next" button on the download page is "pressed" automatically):

var
  DownloadPage: TWizardPage;

procedure InitializeWizard(); 
begin 
  ITD_Init;
  ITD_AddFile(
    'http://www.example.com/jdk-8u111-windows-x64.exe',
    ExpandConstant('{tmp}jdk-8u111-windows-x64.exe'));
  DownloadPage := ITD_DownloadAfter(wpSelectDir); 
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
begin
  if CurPageID = DownloadPage.ID then
  begin
    Result :=
      Exec(
        ExpandConstant('{tmp}jdk-8u111-windows-x64.exe'),
        '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    if not Result then
    begin
      MsgBox('Cannot execute sub-installer', mbError, MB_OK);
    end
      else
    begin
      Result := (ResultCode = 0);
      if not Result then
      begin
        MsgBox('Sub-installer failed', mbError, MB_OK);
      end
    end;
  end
    else
  begin
    Result := True;
  end;
end;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...