How to set the progress bar value in the [Run] sec

2019-04-10 06:51发布

问题:

This question already has an answer here:

  • Inno Setup: How to manipulate progress bar on Run section? 1 answer

This is similar to this question: Inno Setup Simple progress page for Run section

If I'm adding some MSI files to my Inno Setup script, I can install these files from the [Run] section. At that time the progress bar shows 100% and shows the StatusMsg above the progress bar.

I want manually set the value of the progress bar in the [Run] section, say a value of 50%.

Similar to something like this:

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

回答1:

You can use similar code to the question you linked to, by calling it from the BeforeInstall and/or AfterInstall handler for each [Run] entry. Note that Inno itself will run up to 100% in the files section, so you're code will need to start from 0% again, or adjust EVERY entry to use the custom positioning.



回答2:

Late response, but here is some example code I made for anyone else looking for an answer.

Above the [Setup] section you will need to define a constant named AppName for use later, you can also use it to set your Setup AppName variable.

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

Now down in your [code] section you will need to add the following.

[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;

Now you can call the DisplayInstallProgress and UpdateInstallProgress procedures in the [Run] section using the BeforeInstall and AfterInstall Parameters, like below.

[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, '');

I had used this question/answer as a template for creating the progress page: How to show progress during “PrepareToInstall”?

Final note, this implementation goes against jrsoftware's advice:

Always put the Hide call inside the finally part of a try..finally language construct, as demonstrated in CodeDlg.iss. Not calling Hide will result in the wizard being permanently stuck on the progress page.

However I couldn't figure out a way of implementing progress accross items in the [run] section without doing this.