You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Inno Setup 6.2.1网络下载失败及组件集成问题排查

Inno Setup 6 下载失败及组件适配问题解决

问题背景

环境:Inno Setup 6.2.1,Windows 7/10

  • 使用与官方示例高度一致的脚本(示例可正常运行),但下载操作失败,报错:源文件“C:\Users\ADMINI~1\AppData\Local\Temp\is-MBBKM.tmp\version.txt”不存在
  • 尝试修改下载路径至用户应用数据目录、移除安装后代码,问题未得到解决
  • 与官方脚本的唯一差异为使用了回滚至HTTP协议的Sourceforge项目URL,该URL在Inno Setup 5中通过第三方下载插件可正常下载,但Inno Setup 6无法完成任何文件下载
  • 2022年12月补充:添加Components部分后编译正常,但测试运行时仍出现临时文件找不到的问题;尝试在下载代码中添加组件引用导致编译失败

用户提供的脚本代码:

[Setup]
PrivilegesRequired=lowest

[Files]
Source: "{tmp}\version";  DestDir: "{userappdata}\wire"; Flags: external ignoreversion; Components: connect  

[Code]
var
DownloadPage: TDownloadWizardPage;

function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
begin
  if Progress = ProgressMax then
    Log(Format('Successfully downloaded file to {tmp}: %s', [FileName]));
  Result := True;
end;

procedure InitializeWizard;
begin
  DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpReady then begin
    DownloadPage.Clear
    DownloadPage.Add('http://yyy.sourceforge.net/SecurityUpdates/version', 'version.txt', '');
    DownloadPage.Show;
    try
      try
        DownloadPage.Download; // This downloads the files to {tmp}
        Result := True;
      except
        SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
        Result := False;
      end;
    finally
      DownloadPage.Hide;
    end;
  end else
    Result := True;
end;

(注:URL及文件名已编辑)

解决方案

1. 基础下载失败问题修复

  • 修正文件名不匹配:代码中下载的文件名为version.txt,但[Files]段引用的是{tmp}\version,文件名不一致直接导致找不到文件。可二选一修改:
    • 修改[Files]段的Source路径为{tmp}\version.txt
    • 修改DownloadPage.Add的第二个参数为version
  • 处理URL重定向:Sourceforge的HTTP链接可能存在隐性重定向,Inno Setup 6默认下载组件可能未正确处理。可更换为文件直链,或通过WinINet API实现自定义下载逻辑来处理重定向
  • 确保临时目录存在:在下载前添加代码确认{tmp}目录存在,避免目录缺失导致下载失败:
    procedure InitializeWizard;
    begin
      DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);
      // 确保临时目录存在
      if not DirExists(ExpandConstant('{tmp}')) then
        CreateDir(ExpandConstant('{tmp}'));
    end;
    

2. 带组件的安装程序适配

  • 添加组件勾选判断:仅当用户勾选目标组件(如connect)时执行下载,避免无意义的下载操作和文件不存在错误,修改NextButtonClick逻辑:
    function NextButtonClick(CurPageID: Integer): Boolean;
    begin
      if CurPageID = wpReady then begin
        Result := True;
        // 仅当组件被勾选时执行下载
        if IsComponentSelected('connect') then begin
          DownloadPage.Clear;
          DownloadPage.Add('http://yyy.sourceforge.net/SecurityUpdates/version', 'version.txt', '');
          DownloadPage.Show;
          try
            try
              DownloadPage.Download;
            except
              SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
              Result := False;
            end;
          finally
            DownloadPage.Hide;
          end;
        end;
      end else
        Result := True;
    end;
    
  • [Files]段添加存在性检查:确保只有文件存在时才执行复制操作,避免报错:
    [Files]
    Source: "{tmp}\version.txt"; DestDir: "{userappdata}\wire"; Flags: external ignoreversion; Components: connect; Check: FileExists(ExpandConstant('{tmp}\version.txt'))
    
  • 组件配置校验:确认Components段的connect组件定义正确,无依赖冲突或配置错误,示例配置:
    [Components]
    Name: connect; Description: "Connect组件"; Types: full compact; Flags: fixed
    

内容的提问来源于stack exchange,提问作者Jenn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:15:36