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

时间:2016-11-18 14:22:42

标签: inno-setup

如何运行我通过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;

1 个答案:

答案 0 :(得分:1)

使用其他下载插件,而不是ITD(请参阅下面的原因)。

例如,Inno Download Plugin

当您加入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;

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

  • 它已经过时而不再维护;
  • 不支持Unicode Inno设置(不要将Ansi Inno设置用于新项目);
  • 不支持HTTPS;
  • 下载页面does not scale on high DPI

无论如何,为了完整性:ITD_DownloadAfter返回TWizardPage,表示下载页面。下载完成后,使用NextButtonClick中的ID运行下载的文件(下载页面上的&#34;下一步&#34;按钮是&#34;按下&#34;自动):

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;