这个问题是这个问题的衍生:
在使用Inno Setup 安装期间报告已安装的.NET Framework版本
这是我的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
有什么好处吗?如果是,为什么?
可能没有真正的好处,但imo:
-
InitializeSetup
用于检查预浸料。它的API允许通过返回False
来干净地中止安装。 -
InitializeWizard
用于调整向导窗口。它不应该失败。
相关:从[Code]退出Inno Setup安装