0

I need to know for app stats reason from within Inno Setup Pascal script why InnoSetup installation/uninstallation failed.

i.e. Was the installation user cancelled, was there an error and the error itself.

I can hack my way around for the user cancel but did not find a reliable way to find the exact error.

Would have been really helpful at the installer/uninstaller unload event to have an easy way to find the install/uninstall general result and on error reason of error.

This is the "hack around" code:

I need to know for app stats reason from within Inno Setup Pascal script why InnoSetup installation/uninstallation failed.

i.e. Was the installation user cancelled, was there an error and the error itself.

I can hack my way around for the user cancel but did not find a reliable way to find the exact error.

Would have been really helpful at the installer/uninstaller unload event to have an easy way to find the install/uninstall general result and on error reason of error.

This is the "hack around" code:

var
  LastInstallStep:   TSetupStep;
  LastPageID:        Integer;
  UserCanceled:      Boolean;
  UserChooseRestart: Boolean;
  LastUninstallStep: TUninstallStep;

procedure AppStat_Init(IsInstaller : boolean; AppName, AppVersion, AppUninstallKey: String; Debug: Boolean);
begin
  // on uninstall, by default set as user canceled because shown a confirmation dialog that we can't bypass
  UserCanceled      := not IsInstaller;
  UserChooseRestart := False;
end;

procedure AppStat_StepChange(CurrStep : TSetupStep);
begin
  LastInstallStep := CurrStep;

  if CurrStep = ssDone then
    UserChooseRestart := WizardForm.YesRadio.Checked;
end;

procedure AppStat_InstallCurrPageChange(CurrPageID : Integer);
begin
  LastPageID := CurrPageID;
end;

procedure AppStat_UninstallCurrStepChange(CurUninstallStep: TUninstallStep);
begin
  LastUninstallStep := CurUninstallStep;
  // user did not cancel on startup confirmation dialog
  UserCanceled      := False;
end;

procedure AppStat_OnUserCanceled();
begin
  UserCanceled := True;
end;

procedure AppStat_DeinitializeSetup();
var
  StatProps: TStrings;
begin
  // https://stackoverflow.com/questions/40982671/inno-setup-how-to-display-a-message-after-installation-is-cancelled
  StatProps := TStringList.Create();

  if LastInstallStep = ssDone then
  begin
    StatProps.Add('result=success');
    if UserChooseRestart then
      StatProps.Add('user_selected_to_restart=true')
    else
      StatProps.Add('user_selected_to_restart=false');
  end
  else
  if UserCanceled then
    StatProps.Add('result=canceled')
  else
  begin
    StatProps.Add('result=failed');
    // to get more error details, need parse log file
  end;

  StatProps.Add('last_step=' + SetupStepToStr(LastInstallStep));
  StatProps.Add('last_page=' + PageIDToStr(LastPageID));
end;

procedure AppStat_DeinitializeUninstall();
var
  StatProps: TStrings;
begin
  StatProps := TStringList.Create();

  if LastUninstallStep = usDone then
    StatProps.Add('result=success')
  else
  if UserCanceled then
    StatProps.Add('result=canceled')
  else
  begin
    StatProps.Add('result=failed');
    // to get more error details, need parse log file
  end;end;

  StatProps.Add('last_step=' + UninstallStepToStr(LastUninstallStep));
end;


function InitializeUninstall(): Boolean;
begin
  AppStat_Init(False, '{#AppName}', '{#AppVersion}', '{#UninstallID}_is1', True);
  Result := True;
end;

procedure DeinitializeUninstall();
begin
  AppStat_DeinitializeUninstall();
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  AppStat_UninstallCurrStepChange(CurUninstallStep);
end;

function InitializeSetup: Boolean;
begin
  AppStat_Init(True, '{#AppName}', '{#AppVersion}', '{#UninstallID}_is1', True);
  Result := True;
end;

procedure DeinitializeSetup;
begin
  AppStat_DeinitializeSetup();
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  Cancel := True;
  if CurPageID <> wpFinished then
    AppStat_OnUserCanceled();
end;
procedure CurPageChanged(CurPageID: Integer);
begin
  AppStat_InstallCurrPageChange(CurPageID);
end;

// copy log file to CTH logs dir
procedure CurStepChanged(CurStep: TSetupStep);
begin
    AppStat_StepChange(CurStep);
end;

Basically I follow various install/uninstall pages and try to deduce the final user actions and result. I find that overcomplicated and unreliable because most certainly not every case is taken care of.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Niki
  • 558
  • 4
  • 10
  • Yes "Delphi script" == Inno Setup Pascal Script – Niki Apr 24 '23 at 15:45
  • "Can you show us your "hack" " Ok will do that tonight, must go through the code and extract all relevant parts. – Niki Apr 24 '23 at 15:49
  • @MartinPrikryl I've added my current "solution". – Niki Apr 24 '23 at 20:06
  • Yes indeed, I did copy my actual factorized code, just removed irrelevant to the issue parts. I call it a hack because I find it way too complicated for the simple task. From what I understand and your input the API does not allow to make it easier. – Niki Apr 25 '23 at 07:22
  • 1
    I believe that what you have is the easiest solution. – Martin Prikryl Apr 25 '23 at 14:33

0 Answers0