【问题标题】:Display number of downloaded files on Inno Setup TDownloadWizardPage在 Inno Setup TDownloadWizardPage 上显示下载文件的数量
【发布时间】:2022-06-13 13:53:59
【问题描述】:

假设我正在使用示例CodeDownloadFiles.iss,我想通知用户下载状态写入进度文件下载的数量“N of Y 文件”。 p>

我想检索所选组件的总数,但如何更改标签“正在下载其他文件...”?我尝试了以下命令,但该类不支持它:

TDownloadWizardPage.DownloadingLabel := 'Downloading additional files... file 1 of 3, please wait...'

这是函数,你可以看到我没有写如何检索所选组件的总数;我会很感激得到这个任务的建议以编程方式检索它......也许创建一个检查任何组件的新函数? :

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  //Download Components
  if CurPageID = wpReady then begin
    DownloadPage.Clear;

    if WizardIsComponentSelected('Database\ABC') then begin
      TDownloadWizardPage.DownloadingLabel := 'Downloading additional files... file 1 of 3, please wait...'
      DownloadPage.Add('https://example.com/MyDB1.sqlite', 'MyDB1.sqlite', '');
    end;
    if WizardIsComponentSelected('Database\DEF') then begin
      TDownloadWizardPage.DownloadingLabel := 'Downloading additional files... file 2 of 3, please wait...'
      DownloadPage.Add('https://example.com/MyDB2.sqlite', 'MyDB2.sqlite', '');;
    end;
    if WizardIsComponentSelected('Database\GHI') then begin
      TDownloadWizardPage.DownloadingLabel := 'Downloading additional files... file 3 of 3, please wait...'
      DownloadPage.Add('https://example.com/MyDB3.sqlite', 'MyDB3.sqlite', '');;
    end;
    DownloadPage.Show;
    try
      try
        DownloadPage.Download;
        Result := True;
      except
        SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
        Result := False;
      end;
    finally
      DownloadPage.Hide;
    end;
  end else
  Result := True;
end;

我该如何解决这个问题?我如何计算所选组件的总数?

感谢您的任何建议!

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:
    • DownloadPage.Msg1Label.Caption,不是TDownloadWizardPage.DownloadingLabel
    • DownloadPage.Add 不下载文件,因此您无法在调用时更新标签。 下载文件的是DownloadPage.Download

    你可以做什么:

    • 每次调用DownloadPage.Add时,通过增加一个计数器来计算要下载的文件总数。

      全局变量:

      var
        DownloadCount: Integer;
        DownloadFile: Integer;
        PreviousDownload: string;
      

      之后

      DownloadPage.Clear;
      

      添加

      DownloadCount := 0;
      DownloadFile := 0;
      PreviousDownload := '';
      

      在每个DownloadPage.Add 做:

      DownloadPage.Add(...);
      Inc(DownloadCount);
      
    • 使用TOnDownloadProgress 监控下载过程。每次更改 Url 时,更新标签。

      假设您的InitializeWizard(或其他)使用TOnDownloadProgress 处理程序创建下载页面,如下所示:

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

      更新您的 OnDownloadProgress 处理程序(或任何其他)以执行以下操作:

      function OnDownloadProgress(
        const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
      begin
        if Url <> PreviousDownload then
        begin
          Inc(DownloadFile);
          PreviousDownload := Url;
          DownloadPage.Msg1Label.Caption :=
            Format('Downloading additional files... file %d of %d, please wait...', [
              DownloadFile, DownloadCount]);
        end;
        Result := True;
      end;
      

    【讨论】:

    • 太棒了!! @Martin Prikryl,谢谢你的帖子总是很棒!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多