Search code examples
installationinno-setuppascalscript

Inno Setup - Prevent extraction of files from setting progress bar to 100%


In the Inno Setup wpInstalling page how can I prevent the initial extraction of the files as defined in the [Files] section from setting the progress bar to (almost) 100%?

enter image description here

My installation script mainly consists of installing a number of third party installation files from the '[Run]' section. Example below:

[Run]
Filename: "{tmp}\vcredist_x86-2010-sp1.exe"; Parameters: "/q /norestart"; \
  Check: InstallVCRedist;  \
  BeforeInstall: UpdateProgress(10, 'Installing Microsoft Visual C++ 2010 x86 Redistributable - 10.0.40219...');
Filename: "{tmp}\openfire_3_8_1.exe"; Check: InstallOpenFire; \
  BeforeInstall: UpdateProgress(25, 'Installing OpenFire 3.8.1...');
Filename: "{tmp}\postgresql-8.4.16-2-windows.exe"; \
  Parameters: "--mode unattended --unattendedmodeui none --datadir ""{commonappdata}\PostgreSQL\8.4\data"" --install_runtimes 0"; \
  Check: InstallPostgreSQL; \
  BeforeInstall: UpdateProgress(35, 'Installing PostgreSQL 8.4...'); \
  AfterInstall: UpdateProgress(50, 'Setting up database...');

The installation of these third party components takes longer than any other part of the install (by far) but unfortunately the progress bar goes from 0% to close to 100% during the initial extraction of these files. I then can reset the progress bar to an amount of my choosing by using the following procedure:

procedure UpdateProgress(Position: Integer; StatusMsg: String);
begin
  WizardForm.StatusLabel.Caption := StatusMsg;
  WizardForm.ProgressGauge.Position := 
    Position * WizardForm.ProgressGauge.Max div 100;
end;

Ideally however I'd prefer the initial extraction to instead go from 0–10% (approx.) as that would more closely represent what is actually happening.

Is there any event to capture the progression of the extraction of the files or alternatively a way to prevent or block the extraction of the files from updating the progress bar?


Solution

  • You have to increase the WizardForm.ProgressGauge.Max.

    But unfortunately there's no event that happens after the Inno Setup sets its initial maximum.

    You can abuse the BeforeInstall parameter of the first installed file though.

    And then in the [Run] section, use the AfterInstall to progress the bar.

    This expands on my answer to Inno Setup: How to manipulate progress bar on Run section?

    [Files]
    Source: "vcredist_x86-2010-sp1.exe"; DestDir: "{tmp}"; \
        BeforeInstall: SetProgressMax(10)
    Source: "openfire_3_8_1.exe"; DestDir: "{tmp}"
    
    [Run]
    Filename: "{tmp}\vcredist_x86-2010-sp1.exe"; AfterInstall: UpdateProgress(55);
    Filename: "{tmp}\openfire_3_8_1.exe"; AfterInstall: UpdateProgress(100);
    
    [Code]
    
    procedure SetProgressMax(Ratio: Integer);
    begin
      WizardForm.ProgressGauge.Max := WizardForm.ProgressGauge.Max * Ratio;
    end;
    
    procedure UpdateProgress(Position: Integer);
    begin
      WizardForm.ProgressGauge.Position :=
        Position * WizardForm.ProgressGauge.Max div 100;
    end;