使用Inno Download Plugin下载失败时如何跳过错误继续安装
问题背景
在Windows 7等部分系统上使用Inno Download Plugin下载文件时,会遇到Download failed: An error occurred in the secure channel support报错。添加idpSetOption('AllowContinue', '1');配置后未生效,需要实现非核心文件下载失败时跳过下载步骤,继续正常执行安装流程。
最小可复现示例
#include "D:\idp.iss" [Setup] PrivilegesRequired=admin AppName=My Project AppVersion=2.0 DefaultDirName={pf}\My Project DefaultGroupName=My Project UninstallDisplayIcon={app}\My Project.exe Compression=lzma2 SolidCompression=yes OutputDir=D:\setup DisableDirPage=yes DisableProgramGroupPage=yes DisableReadyMemo=yes DisableReadyPage=yes OutputBaseFilename=Setup [Files] Source: "My Project.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "{tmp}\online.exe"; DestDir: "{commondesktop}"; Flags: external; ExternalSize: 1736547 Source: "{tmp}\offline.exe"; DestDir: "{commondesktop}"; Flags: external; ExternalSize: 166148 [Icons] Name: "{group}\My Project"; Filename: "{app}\My Project.exe"; WorkingDir: "{app}"; Comment: "Launch My Project" [Run] Filename: "{app}\My Project.EXE"; Description: "My Project"; Flags: postinstall [Code] procedure InitializeWizard(); begin idpSetOption('AllowContinue', '1'); idpAddFileSize('https://download.mysite.com/download/online.exe', ExpandConstant('{tmp}\online.exe'), 1736547); idpAddFileSize('https://download.mysite.com/download/offline.exe', ExpandConstant('{tmp}\offline.exe'), 166148); idpDownloadAfter(wpReady); end;
解决方案
需要修改两处配置即可实现下载失败自动跳过:
- 给[Files]段中的非核心外部文件添加
onlyifexists标记,确保下载失败、文件不存在时,安装流程不会因为找不到源文件终止
[Files] Source: "My Project.exe"; DestDir: "{app}"; Flags: ignoreversion ; 新增onlyifexists标记,文件不存在时直接跳过部署 Source: "{tmp}\online.exe"; DestDir: "{commondesktop}"; Flags: external ignoreversion onlyifexists; ExternalSize: 1736547 Source: "{tmp}\offline.exe"; DestDir: "{commondesktop}"; Flags: external ignoreversion onlyifexists; ExternalSize: 166148
- 在[Code]段添加IDP下载错误回调函数,覆盖默认的错误终止逻辑
[Code] // 下载错误回调函数,返回True即表示忽略当前错误,继续后续流程 function idpOnError(Error: Integer; const FileName, Url: string): Boolean; begin Result := True; end; procedure InitializeWizard(); begin idpSetOption('AllowContinue', '1'); // 绑定自定义错误回调 idpSetEvent('OnError', @idpOnError); idpAddFileSize('https://download.mysite.com/download/online.exe', ExpandConstant('{tmp}\online.exe'), 1736547); idpAddFileSize('https://download.mysite.com/download/offline.exe', ExpandConstant('{tmp}\offline.exe'), 166148); idpDownloadAfter(wpReady); end;
修改完成后,任意文件下载失败都会自动跳过,不会弹出报错提示,安装流程会正常执行到结束。
内容的提问来源于stack exchange,提问作者Ramesh Patel
相关产品推荐
相关产品推荐

