首页 > 解决方案 > 将部分代码从 InitializeWizard 移动到 Inno Setup 中的 InitializeSetup 有什么好处吗?

问题描述

这个问题是从这个问题中衍生出来的:
Report installed .NET Framework version during install with Inno Setup

这是我的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;

这是我的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;

将其中一些代码从 移动InitializeWizard到有什么好处InitializeSetup吗?如果是这样,为什么?

标签: inno-setuppascalscript

解决方案


可能没有真正的好处,但imo:

  • InitializeSetup用于检查 preprequities。它的 API 允许通过返回False.

  • InitializeWizard用于调整向导窗口。它不应该失败。

相关:从 [代码] 退出 Inno Setup 安装


推荐阅读