我的 Inno Setup 脚本使用内置功能下载一些资源。 它创建下载向导页面:
DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
它添加了几个应该下载的项目:
if WizardIsTaskSelected('taskA') then
begin
DownloadPage.Add('https://randomresource/taskA.zip', 'taskA.zip', '');
end;
if WizardIsTaskSelected('taskB') then
begin
DownloadPage.Add('https://randomresource/taskB.zip', 'taskB.zip', '');
end;
最后一步是显示向导页面并开始下载:
try
try
DownloadPage.Download;
Result := True;
except
SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
Result := False;
end;
finally
DownloadPage.Hide;
end;
以上所有内容基本上都来自Inno Setup提供的示例。有一个问题:如果任何下载失败(引发异常或任何其他情况),它会中断整个下载过程,并且其他项目将不会下载。我希望它继续下载其余文件。我浏览了 Inno Setup 文档,但没有找到任何可以启用该功能的标志。有解决办法吗?提前致谢。
最佳答案
一个简单的解决方案是单独下载每个文件。
以下代码将允许用户选择对每个文件的下载错误执行的操作:
- 重试下载
- 跳过下载
- 中止安装。
var
DownloadPage: TDownloadWizardPage;
function RobustDownload(
Url, BaseName, RequiredSHA256OfFile: String): Boolean;
var
Retry: Boolean;
Answer: Integer;
begin
repeat
try
DownloadPage.Clear;
DownloadPage.Add(Url, BaseName, RequiredSHA256OfFile);
DownloadPage.Download;
Retry := False;
Result := True;
except
if DownloadPage.AbortedByUser then
begin
Log('Aborted by user.')
Result := False;
Retry := False;
end
else
begin
// Make sure the page displays the URL that fails to download
DownloadPage.Msg2Label.Caption := Url;
Answer :=
SuppressibleMsgBox(
AddPeriod(GetExceptionMessage),
mbCriticalError, MB_ABORTRETRYIGNORE, IDABORT);
Retry := (Answer = IDRETRY);
Result := (Answer <> IDABORT);
end;
end;
until not Retry;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = wpReady then
begin
try
DownloadPage :=
CreateDownloadPage(
SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc),
@OnDownloadProgress);
DownloadPage.Show;
Result :=
RobustDownload('https://example.com/setup1.exe', 'setup1.exe', '') and
RobustDownload('https://example.com/setup2.exe', 'setup2.exe', '') and
RobustDownload('https://example.com/setup3.exe', 'setup3.exe', '');
finally
DownloadPage.Hide;
end;
end
else Result := True;
end;
关于download - Inno Setup 出错时如何继续下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71659973/