Search code examples
inno-setuppascalscript

Are there any benefits in moving some of this code from InitializeWizard to InitializeSetup in Inno Setup?


This question is a spin off from this one:
Report installed .NET Framework version during install with Inno Setup

Here is my InitializeWizard:

(* InitializeWizard is called when the wizard is about to begin.
    This is where we add any custom pages into the installation process.
    The relevant XXX_CreatePage methods should be defined BEFORE this method. *)
procedure InitializeWizard();
begin
    dotNetNeeded := not IsDotNetInstalled(net462, 0);
    if (dotNetNeeded) then begin
        if (MsgBox(ExpandConstant('{cm:DotNet_NeedToDownload}'), \
                                            mbConfirmation, MB_OKCANCEL) = IDCANCEL) then begin
            //result := ExpandConstant('{cm:DotNet_InstallAborted}');
            Abort();
        end;
    end;

    bVcRedist64BitNeeded := false;
    if (IsWin64()) then
        bVcRedist64BitNeeded := IsVCRedist64BitNeeded();

    bVcRedist32BitNeeded := IsVCRedist32BitNeeded();

    DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);

    { Support File Progress Monitoring via ListBox }
    { See: https://stackoverflow.com/a/64588818/2287576 }
    { Start }
    OldStatusLabelWndProc :=
        SetWindowLong(WizardForm.StatusLabel.Handle, GWL_WNDPROC,
            CreateCallback(@StatusLabelWndProc));
    OldFilenameLabelWndProc :=
        SetWindowLong(WizardForm.FilenameLabel.Handle, GWL_WNDPROC,
            CreateCallback(@FilenameLabelWndProc));

    WizardForm.ProgressGauge.Top := WizardForm.FilenameLabel.Top;

    ProgressListBox := TNewListBox.Create(WizardForm);
    ProgressListBox.Parent := WizardForm.ProgressGauge.Parent;
    ProgressListBox.Top :=
        WizardForm.ProgressGauge.Top + WizardForm.ProgressGauge.Height + ScaleY(8);
    ProgressListBox.Width := WizardForm.FilenameLabel.Width;
    ProgressListBox.Height :=
        ProgressListBox.Parent.ClientHeight - ProgressListBox.Top - ScaleY(16);
    ProgressListBox.Anchors := [akLeft, akTop, akRight, akBottom];
    OldProgressListBoxWndProc :=
        SetWindowLong(ProgressListBox.Handle, GWL_WNDPROC,
            CreateCallback(@ProgressListBoxWndProc));
    { Lame way to shrink width of labels to client width of the list box, }
    { so that particularly when the file paths in FilenameLabel are shortened }
    { to fit to the label, they actually fit even to the list box. }
    WizardForm.StatusLabel.Width := WizardForm.StatusLabel.Width - ScaleY(24);
    WizardForm.FilenameLabel.Width := WizardForm.FilenameLabel.Width - ScaleY(24);
    { End }

    AutoBackupPage_InitializeWizard(wpSelectTasks);
end;

Here is my InitializeSetup:

{ Called just before setup is about to start }
function InitializeSetup(): Boolean;
var
    WinVer: TWindowsVersion;
    WinVerPacked: Int64;
begin
    Result := True;

    ExtractTemporaryFile('{#Skin}');
    LoadVCLStyle(ExpandConstant('{tmp}\{#Skin}'));

    { Are we performing an upgrade? }
    bIsUpgrading := IsUpgrading();

    { Check Windows Version }
    GetWindowsVersionEx(WinVer);
    WinVerPacked := PackVersionComponents(WinVer.Major, WinVer.Minor, WinVer.Build, 0);

    (* Windows must be Win 7 SP1 (6.1.7601), Win 8.1 (6.3.9200) or higher, eg: Win 10 (10.0.10240)
        See: http://www.jrsoftware.org/ishelp/index.php?topic=winvernotes
        Microsoft .Net Framework 4.6.2 will only work with these operating systems. *)
    if (ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 1, 7601, 0)) < 0) or
            ((ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 2, 0, 0)) >= 0) and
            (ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 3, 0, 0)) < 0)) then
    begin
        MsgBox(SetupMessage(msgWindowsVersionNotSupported), mbError, MB_OK);
        Result := False;
    end;
  { Log(Format('Windows Version: %x', [WindowsVersion])); }
end;

Are there any benefits in moving some of this code from InitializeWizard to InitializeSetup? And if so, why?


Solution

  • There are probably no real benefits, but imo:

    • InitializeSetup is meant for checking preprequsities. Its API allows aborting the installation cleanly by returning False.

    • InitializeWizard is meant for adjusting the wizard window. It is not supposed to fail.

    Related: Exit from Inno Setup installation from [Code]