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.