0

I am trying to use this code: How to show percent done, elapsed time and estimated time progress?

But I have problems, because i use this code to the installer too.

Community
  • 1
  • 1
Nico Z
  • 997
  • 10
  • 33

1 Answers1

2

Merging these two piece of code together:

[Code]

function SetTimer(hWnd: longword; nIDEvent, uElapse: LongWord;
  lpTimerFunc: LongWord): LongWord; external 'SetTimer@user32.dll stdcall';
function GetTickCount: DWORD;
  external 'GetTickCount@kernel32.dll stdcall';

var
  UninstallStartTick: DWORD;
  UninstallPercentLabel: TNewStaticText;
  UninstallElapsedLabel: TNewStaticText;
  UninstallRemainingLabel: TNewStaticText;

function TicksToStr(Value: DWORD): string;
var
  I: DWORD;
  Hours, Minutes, Seconds: Integer;
begin
  I := Value div 1000;
  Seconds := I mod 60;
  I := I div 60;
  Minutes := I mod 60;
  I := I div 60;
  Hours := I mod 24;
  Result := Format('%.2d:%.2d:%.2d', [Hours, Minutes, Seconds]);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
  begin
    UninstallStartTick := GetTickCount;
  end;
end;

procedure UninstallTimerProc(
  h: LongWord; AMsg: LongWord; IdEvent: LongWord; dwTime: LongWord);
var
  CurTick: DWORD;
  CurProgress: Integer;
  MaxProgress: Integer;
begin
  MaxProgress := UninstallProgressForm.ProgressBar.Max;
  CurProgress := UninstallProgressForm.ProgressBar.Position;

  if MaxProgress > 0 then
  begin
    CurTick := GetTickCount;
    UninstallPercentLabel.Caption :=
      Format('Done: %.2f %%', [(CurProgress * 100.0) / MaxProgress]);
    UninstallElapsedLabel.Caption := 
      Format('Elapsed: %s', [TicksToStr(CurTick - UninstallStartTick)]);
    if CurProgress > 0 then
    begin
      UninstallRemainingLabel.Caption :=
        Format('Remaining: %s', [TicksToStr(
          ((CurTick - UninstallStartTick) / CurProgress) *
           (MaxProgress - CurProgress))]);
    end;
  end;
end;

procedure InitializeUninstallProgressForm();
begin
  UninstallPercentLabel := TNewStaticText.Create(UninstallProgressForm);
  UninstallPercentLabel.Parent := UninstallProgressForm.ProgressBar.Parent;
  UninstallPercentLabel.Left := UninstallProgressForm.ProgressBar.Left;
  UninstallPercentLabel.Top := UninstallProgressForm.ProgressBar.Top +
    UninstallProgressForm.ProgressBar.Height + ScaleY(12);

  UninstallElapsedLabel := TNewStaticText.Create(UninstallProgressForm);
  UninstallElapsedLabel.Parent := UninstallProgressForm.ProgressBar.Parent;
  UninstallElapsedLabel.Left := UninstallPercentLabel.Left;
  UninstallElapsedLabel.Top :=
    UninstallPercentLabel.Top + UninstallPercentLabel.Height + ScaleY(4);

  UninstallRemainingLabel := TNewStaticText.Create(UninstallProgressForm);
  UninstallRemainingLabel.Parent := UninstallProgressForm.ProgressBar.Parent;
  UninstallRemainingLabel.Left := UninstallPercentLabel.Left;
  UninstallRemainingLabel.Top :=
    UninstallElapsedLabel.Top + UninstallElapsedLabel.Height + ScaleY(4);

  SetTimer(0, 0, 100, CreateCallback(@UninstallTimerProc)); { every 100 ms }
end;

For CreateCallback function, you need Inno Setup 6. If you are stuck with Inno Setup 5, you can use WrapCallback function from InnoTools InnoCallback library. Note the drawbacks of using extension DLL in the uninstaller described in the question linked from the first question above.

Uninstall times

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992