【问题标题】:How to set the progress bar value in the [Run] section of the Inno Setup install script? [duplicate]如何在 Inno Setup 安装脚本的 [Run] 部分设置进度条值? [复制]
【发布时间】:2011-12-14 09:24:41
【问题描述】:

这类似于这个问题: Inno Setup Simple progress page for Run section

如果我将一些 MSI 文件添加到我的 Inno Setup 脚本,我可以从 [Run] 部分安装这些文件。此时进度条显示100%,并在进度条上方显示StatusMsg

我想在[Run] 部分手动设置进度条的值,比如50%。

类似这样的:

[Run]
Filename: msiexec.exe; Parameters: "/i ""{#MyRtePath}\runtime.msi"" /qn /norestart"; \
    StatusMsg: Installing Runtime Engine; WizardForm.ProgressGauge.progress: 50 ;

【问题讨论】:

    标签: installation progress-bar inno-setup uninstallation


    【解决方案1】:

    您可以使用与您链接的问题类似的代码,方法是从每个[Run] 条目的BeforeInstall 和/或AfterInstall 处理程序调用它。 请注意,Inno 本身将在文件部分运行高达 100%,因此您的代码将需要再次从 0% 开始,或者调整每个条目以使用自定义定位。

    【讨论】:

    • 感谢您的回复。我不明白你想表达什么。你能提供一个示例代码吗..?
    • 不,我不能,除了帮助文件。简而言之,进度条从 0% 变为 100%,然后处理 [Run] 条目,因此它必须从 0% 重新开始,并通过调用 AfterInstall 参数中的代码为每个条目递增。
    【解决方案2】:

    回复较晚,但这是我为其他寻找答案的人制作的一些示例代码。

    [Setup] 部分上方,您需要定义一个名为 AppName 的常量供以后使用,您也可以使用它来设置您的 Setup AppName 变量。

    #define AppName "Test Installer"
    [Setup]
    AppName={#AppName}
    

    现在您需要在[code] 部分添加以下内容。

    [Code]
    var 
    InstallWithProgressPage : TOutputProgressWizardPage;
    
    //Create custom progress bar for install progress
    procedure InitializeWizard;
    var
      UpdatedPageString:  AnsiString;
      OriginalPageString: String;
    begin
      //The string msgWizardPreparing has the macro '[name]' inside that we have to replace.
      OriginalPageString := SetupMessage(msgPreparingDesc); 
      StringChange(OriginalPageString, '[name]', '{#AppName}');
      UpdatedPageString := OriginalPageString;
      InstallWithProgressPage := CreateOutputProgressPage(SetupMessage(msgWizardPreparing), UpdatedPageString);
    end;
    
    //Enable or Disable the install progress page (also set initial progress/text)
    procedure DisplayInstallProgress(showPage:Boolean; progressText:String);
    begin
       if(showPage = True) then
          begin
             InstallWithProgressPage.Show;
             InstallWithProgressPage.SetText(progressText, '');
             InstallWithProgressPage.SetProgress(0,100);
          end
       else
          begin
             InstallWithProgressPage.Hide;
          end
    end;
    
    //Update the install progress page
    procedure UpdateInstallProgress(progressText:String; progressPercent:Integer);
    begin
       InstallWithProgressPage.SetProgress(progressPercent,100);
       InstallWithProgressPage.SetText(progressText, '');
    end;
    

    现在您可以使用 BeforeInstall 和 AfterInstall 参数调用 [Run] 部分中的 DisplayInstallProgress 和 UpdateInstallProgress 过程,如下所示。

    [Run]
    FileName: "Powershell.exe"; Parameters: "-File {app}\Part1.ps1"; BeforeInstall: DisplayInstallProgress(True, 'Installing part 1.');
    FileName: "Powershell.exe"; Parameters: "-File {app}\Part2.ps1"; BeforeInstall: UpdateInstallProgress('Installing part 2.', 30);
    FileName: "Powershell.exe"; Parameters: "-File {app}\Part3.ps1"; BeforeInstall: UpdateInstallProgress('Installing part 3.', 60);
    FileName: "Powershell.exe"; Parameters: "-File {app}\Part3.ps1"; BeforeInstall: UpdateInstallProgress('Installing part 4.',90); AfterInstall: DisplayInstallProgress(False, '');
    

    我曾将此问题/答案用作创建进度页面的模板:How to show progress during “PrepareToInstall”?

    最后一点,这个实现违背了jrsoftware's advice

    始终将 Hide 调用放在 try..finally 语言结构的 finally 部分中,如 CodeDlg.iss 中所示。不调用 Hide 将导致向导永久卡在进度页面上。

    但是,如果不这样做,我无法想出在 [run] 部分中跨项目实施进度的方法。

    【讨论】:

    • 也许你应该解释一下,你的代码实际上创建了一个新的进度页面。而不是操纵标准“安装”页面上的进度条,而是问题所要求的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多