在 Inno Setup 的代码部分下载程序后运行程序

问题描述 投票:0回答:1

如何在代码部分运行我通过 Internet 下载的应用程序,并等待该应用程序完成运行。我已经使用 InnoTools 下载器下载了这两个文件,我想在第二个文件下载完成后运行该下载,或者

jdk-8u111-windows-x64.exe
,然后继续安装。

[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;
installation inno-setup pascalscript inno-download-plugin
1个回答
3
投票

Inno Setup 6.1 原生支持下载。请参阅在 Inno Setup 中从 Internet 安装文件


如果您坚持使用旧版本的 Inno Setup,请使用 Inno 下载插件 (IDP),而不是 ITD(原因见下文)。

当你包含

idp.iss
时,它定义了一个全局的
IDPForm
结构。它的
Page
字段是
TWizardPage
,代表一个下载页面。下载完成后,使用
NextButtonClick
中的ID运行下载的文件(下载页面上的“下一步”按钮自动“按下”):

#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;

还有DwinsHs(Inno Setup 下载器).


虽然您可以使用 InnoTools Downloader 实现相同的功能,但您应该避免使用它:

  • 已经过时,不再维护;
  • 不支持Unicode Inno Setup(新项目不要使用Ansi Inno Setup);
  • 不支持HTTPS;
  • 它的下载页面does not scale on high DPI.

无论如何,为了完整性:

ITD_DownloadAfter
返回
TWizardPage
,代表下载页面。下载完成后,使用
NextButtonClick
中的ID运行下载的文件(下载页面上的“下一步”按钮自动“按下”):

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;
© www.soinside.com 2019 - 2024. All rights reserved.