在 Inno Setup 的 Code 部分下载后运行程序 [英] Running a program after it is downloaded in Code section in Inno Setup
问题描述
如何运行我通过 Internet 下载的应用程序,在代码部分使用,并等待该应用程序完成运行.我已经使用 InnoTools 下载器下载了这两个文件,我想在第二个下载完成后运行该下载,或者 jdk-8u111-windows-x64.exe
,然后继续安装.
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;
推荐答案
使用其他下载插件,而不是 ITD(原因见下文).
Use other download plugin, not ITD (see below for reasons).
Inno Setup 6.1 原生支持下载.请参阅 Inno Setup:从 Internet 安装文件
Inno Setup 6.1 supports downloads natively. See Inno Setup: Install file from Internet
如果您坚持使用旧版本的 Inno Setup,请使用 Inno 下载插件.
If you are stuck with an older version of Inno Setup, use the Inno Download Plugin.
当你包含 idp.iss
时,它定义了一个全局的 IDPForm
结构.它的Page
字段是TWizardPage
,代表一个下载页面.使用 NextButtonClick
中的 ID 运行下载的文件,下载完成后(自动按下"下载页面上的下一步"按钮):
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;
虽然您可以使用 InnoTools Downloader 实现相同的功能,但您应该避免使用它:
While you can implement the same using InnoTools Downloader, you should avoid it:
- 它已经过时,不再维护;
- 不支持 Unicode Inno Setup(新项目不要使用 Ansi Inno Setup);
- 不支持HTTPS;
- 它的下载页面在高 DPI 下无法缩放.
无论如何,为了完整性:ITD_DownloadAfter
返回 TWizardPage
,代表一个下载页面.使用 NextButtonClick
中的 ID 运行下载的文件,下载完成后(自动按下"下载页面上的下一步"按钮):
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;
这篇关于在 Inno Setup 的 Code 部分下载后运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!