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

基于Inno Setup与IDP实现分阶段按需下载文件的问题

问题:Inno Download Plugin(IDP)能否实现分阶段多次下载?

可以实现分阶段多次下载,你的代码逻辑存在几个关键错误导致第二次下载未生效,以下是修正方案:

问题分析

  1. 触发时机判断错误:你在NextButtonClick里判断CurPageID = IDPForm.Page.ID,这会在第一次下载完成后的IDP页面点击下一步时触发逻辑,但此时用户还未选择组件,逻辑顺序颠倒。
  2. 重复设置下载时机:将idpDownloadAfter(CustomSelectComponentsPage.ID)放在循环里多次调用,导致IDP的触发逻辑混乱。
  3. 组件生成逻辑位置不对:应该在进入自定义组件页时生成选项,而非在IDP页面点击下一步时。

修正后的代码

[Code]
var
  CustomSelectComponentsPage: TWizardPage;
  ComponentsList: TNewCheckListBox;
  ListDownloaded: Boolean;

procedure InitializeWizard();
var
  SelectComponentsLabel: TNewStaticText;
begin
  // 第一次下载:欢迎页后下载组件列表文件
  idpDownloadAfter(wpWelcome); 
  idpAddFile('ftp://host.com/filesToDownload.txt', ExpandConstant('{tmp}\filesToDownload.txt'));

  // 创建自定义组件选择页
  CustomSelectComponentsPage := CreateCustomPage(wpSelectComponents,
    SetupMessage(msgWizardSelectComponents), SetupMessage(msgSelectComponentsDesc));
  
  // 在自定义页添加复选框列表
  ComponentsList := TNewCheckListBox.Create(CustomSelectComponentsPage);
  ComponentsList.Parent := CustomSelectComponentsPage.Surface;
  ComponentsList.Left := ScaleX(16);
  ComponentsList.Top := ScaleY(40);
  ComponentsList.Width := CustomSelectComponentsPage.Surface.Width - ScaleX(32);
  ComponentsList.Height := CustomSelectComponentsPage.Surface.Height - ScaleY(56);
  
  ListDownloaded := False;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  AppName: string;
  Lines: array of string;
  I: Integer;
begin
  Result := True;

  // 进入自定义组件页时,生成组件选项(仅第一次进入)
  if CurPageID = wpSelectComponents then
  begin
    if not ListDownloaded then
    begin
      // 读取下载的组件列表文件
      if ReadTextFile(ExpandConstant('{tmp}\filesToDownload.txt'), Lines) then
      begin
        for I := 0 to GetArrayLength(Lines) - 1 do
        begin
          AppName := Trim(Lines[I]);
          if AppName <> '' then
          begin
            ComponentsList.AddCheckBox(AppName, '', 0, False, True, False, False, nil);
          end;
        end;
        ListDownloaded := True;
      end;
    end;
  end
  // 用户在自定义组件页点击下一步时,触发第二次下载
  else if CurPageID = CustomSelectComponentsPage.ID then
  begin
    // 清空之前的下载任务(第一次的已经完成)
    idpClearFiles;

    // 添加选中的组件文件到下载列表
    for I := 0 to ComponentsList.Items.Count - 1 do
    begin
      if ComponentsList.Checked[I] then
      begin
        AppName := ComponentsList.Items[I];
        idpAddFile('ftp://host.com/' + AppName, ExpandConstant('{tmp}\' + AppName));
      end;
    end;

    // 设置第二次下载在当前页之后触发
    idpDownloadAfter(CustomSelectComponentsPage.ID);
    // 激活IDP下载表单
    idpFormActivate(nil);
    // 返回False阻止直接跳转到下一页,等待下载完成
    Result := False;
  end;
end;

关键说明

  • 第一次下载:在InitializeWizard中设置idpDownloadAfter(wpWelcome),确保欢迎页结束后自动下载组件列表文件。
  • 生成组件选项:在进入wpSelectComponents阶段时(自定义页显示前),读取下载的文件生成复选框选项,确保用户看到最新的组件列表。
  • 第二次下载触发:当用户在自定义组件页点击下一步时,收集选中的组件,添加到IDP下载任务,设置下载触发时机并激活IDP表单,阻止页面跳转直到下载完成。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 22:09:49