在 Inno Setup 中安装所有组件后结束设置
Ending the setup when all components have been installed in Inno Setup
我试图在所有组件都已安装时停止安装。
安装示例:
- 首次安装:安装一个组件
- 第二次安装:安装其余组件
- 第三次安装:安装程序开始并直接转到
wpFinished
页面或停止并放置一条消息说 "all component are already install"。
我在这里和其他网站上做了一些研究,我做了以下事情:
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Confirm := False;
end;
procedure InitializeWizard;
var
ItemIndex: Integer;
InstallEn: String;
InstallFr: String;
InstallDe: String;
CompDescEnIndex: Integer;
CompDescFrIndex: Integer;
CompDescDeIndex: Integer;
Check: Integer;
begin
# This part is to make not selectable component already install
if RegQueryStringValue(HKLM, 'Software\COMPANY\{#RegProduct}\{#RegCurVer}', 'Install-ENG', InstallEn) then
if ((InstallEn = 'International Pack' )
or (InstallEn = 'Pack International')
or (InstallEn = 'International Paket'))
then
ItemIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescEn'));
WizardForm.ComponentsList.ItemEnabled[ItemIndex] := False;
if RegQueryStringValue(HKLM, 'Software\COMPANY\{#RegProduct}\{#RegCurVer}', 'Install-FRA', InstallFr) then
if ((InstallFr = 'French Pack')
or (InstallFr = 'Pack France')
or (InstallFr = 'Franzosisch Paket'))
then
ItemIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescFr'));
WizardForm.ComponentsList.ItemEnabled[ItemIndex] := False;
if RegQueryStringValue(HKLM, 'Software\COMPANY\{#RegProduct}\{#RegCurVer}', 'Install-DEU', InstallDe) then
if ((InstallDe = 'German Pack')
or (InstallDe = 'Pack Allemand')
or (InstallDe = 'Deutsches Paket'))
then
ItemIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescDe'));
WizardForm.ComponentsList.ItemEnabled[ItemIndex] := False;
# After I try to say if all component are install, close the wizard.
CompDescEnIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescEn'));
CompDescFrIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescFr'));
CompDescDeIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescDe'));
if not WizardForm.ComponentsList.ItemEnabled[CompDescEnIndex]
and not WizardForm.ComponentsList.ItemEnabled[CompDescFrIndex]
and not WizardForm.ComponentsList.ItemEnabled[CompDescDeIndex]
then
Check := 1;
if (Check <> 0) then
WizardForm.Close;
end;
注意: 代码可能不是很干净,我在 Code
部分开始使用 Pascal + Inno Setup。
如果我的所有组件都已安装(并且不可选择),我希望向导停止而不继续...
我找不到直接进入 wpFinished
页面的解决方案...有办法吗?
如果安装了所有组件,我该如何停止向导,因为 WizardForm.Close;
似乎对我的情况不起作用?
感谢您的帮助。
您不能跳到 wpFinished
页面,因为 Inno Setup 不允许您跳过 wpReady
页面以避免创建全自动安装程序(这可能会被滥用)。
不过您可以创建自定义 "finished" 页面:
procedure AllInstalledPageActivate(Sender: TWizardPage);
begin
{ Change the "Next" button to "Finish" on our custom page }
WizardForm.NextButton.Caption := SetupMessage(msgButtonFinish);
{ Hide the "Cancel" button }
WizardForm.CancelButton.Visible := False;
end;
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess@kernel32.dll stdcall';
function AllInstalledPageNextButtonClick(Sender: TWizardPage): Boolean;
begin
{ Abort the installer when the "Finish" button is clicked on our custom page }
ExitProcess(0);
Result := True; { shut up the compiler warning }
end;
procedure InitializeWizard();
var
Caption: TLabel;
AllInstalledPage: TWizardPage;
begin
...
{ If everything is installed already ... }
if IsEverythingInstalled then
begin
{ ... create a custom "everything is installed" page }
AllInstalledPage :=
CreateCustomPage(
wpWelcome, 'All components are installed already',
'There''s nothing to install.');
AllInstalledPage.OnActivate := @AllInstalledPageActivate;
AllInstalledPage.OnNextButtonClick := @AllInstalledPageNextButtonClick;
Caption := TLabel.Create(AllInstalledPage);
Caption.Caption :=
'Everything is installed already. Click Finish to close the installer.';
Caption.Width := AllInstalledPage.SurfaceWidth;
Caption.Parent := AllInstalledPage.Surface;
end;
end;
更简单的解决方案是使用普通 message box.
Wizard.Close
会关闭安装程序,它不会转到 "Finished" 页面。如果你真的想中止安装程序,从 InitializeSetup
return False
(你需要将一些代码移动到 InitializeSetup
)。
或使用 ExitProcess
function,如我的示例。
我试图在所有组件都已安装时停止安装。
安装示例:
- 首次安装:安装一个组件
- 第二次安装:安装其余组件
- 第三次安装:安装程序开始并直接转到
wpFinished
页面或停止并放置一条消息说 "all component are already install"。
我在这里和其他网站上做了一些研究,我做了以下事情:
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Confirm := False;
end;
procedure InitializeWizard;
var
ItemIndex: Integer;
InstallEn: String;
InstallFr: String;
InstallDe: String;
CompDescEnIndex: Integer;
CompDescFrIndex: Integer;
CompDescDeIndex: Integer;
Check: Integer;
begin
# This part is to make not selectable component already install
if RegQueryStringValue(HKLM, 'Software\COMPANY\{#RegProduct}\{#RegCurVer}', 'Install-ENG', InstallEn) then
if ((InstallEn = 'International Pack' )
or (InstallEn = 'Pack International')
or (InstallEn = 'International Paket'))
then
ItemIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescEn'));
WizardForm.ComponentsList.ItemEnabled[ItemIndex] := False;
if RegQueryStringValue(HKLM, 'Software\COMPANY\{#RegProduct}\{#RegCurVer}', 'Install-FRA', InstallFr) then
if ((InstallFr = 'French Pack')
or (InstallFr = 'Pack France')
or (InstallFr = 'Franzosisch Paket'))
then
ItemIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescFr'));
WizardForm.ComponentsList.ItemEnabled[ItemIndex] := False;
if RegQueryStringValue(HKLM, 'Software\COMPANY\{#RegProduct}\{#RegCurVer}', 'Install-DEU', InstallDe) then
if ((InstallDe = 'German Pack')
or (InstallDe = 'Pack Allemand')
or (InstallDe = 'Deutsches Paket'))
then
ItemIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescDe'));
WizardForm.ComponentsList.ItemEnabled[ItemIndex] := False;
# After I try to say if all component are install, close the wizard.
CompDescEnIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescEn'));
CompDescFrIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescFr'));
CompDescDeIndex := WizardForm.ComponentsList.Items.IndexOf(CustomMessage('CompDescDe'));
if not WizardForm.ComponentsList.ItemEnabled[CompDescEnIndex]
and not WizardForm.ComponentsList.ItemEnabled[CompDescFrIndex]
and not WizardForm.ComponentsList.ItemEnabled[CompDescDeIndex]
then
Check := 1;
if (Check <> 0) then
WizardForm.Close;
end;
注意: 代码可能不是很干净,我在 Code
部分开始使用 Pascal + Inno Setup。
如果我的所有组件都已安装(并且不可选择),我希望向导停止而不继续...
我找不到直接进入 wpFinished
页面的解决方案...有办法吗?
如果安装了所有组件,我该如何停止向导,因为 WizardForm.Close;
似乎对我的情况不起作用?
感谢您的帮助。
您不能跳到 wpFinished
页面,因为 Inno Setup 不允许您跳过 wpReady
页面以避免创建全自动安装程序(这可能会被滥用)。
不过您可以创建自定义 "finished" 页面:
procedure AllInstalledPageActivate(Sender: TWizardPage);
begin
{ Change the "Next" button to "Finish" on our custom page }
WizardForm.NextButton.Caption := SetupMessage(msgButtonFinish);
{ Hide the "Cancel" button }
WizardForm.CancelButton.Visible := False;
end;
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess@kernel32.dll stdcall';
function AllInstalledPageNextButtonClick(Sender: TWizardPage): Boolean;
begin
{ Abort the installer when the "Finish" button is clicked on our custom page }
ExitProcess(0);
Result := True; { shut up the compiler warning }
end;
procedure InitializeWizard();
var
Caption: TLabel;
AllInstalledPage: TWizardPage;
begin
...
{ If everything is installed already ... }
if IsEverythingInstalled then
begin
{ ... create a custom "everything is installed" page }
AllInstalledPage :=
CreateCustomPage(
wpWelcome, 'All components are installed already',
'There''s nothing to install.');
AllInstalledPage.OnActivate := @AllInstalledPageActivate;
AllInstalledPage.OnNextButtonClick := @AllInstalledPageNextButtonClick;
Caption := TLabel.Create(AllInstalledPage);
Caption.Caption :=
'Everything is installed already. Click Finish to close the installer.';
Caption.Width := AllInstalledPage.SurfaceWidth;
Caption.Parent := AllInstalledPage.Surface;
end;
end;
更简单的解决方案是使用普通 message box.
Wizard.Close
会关闭安装程序,它不会转到 "Finished" 页面。如果你真的想中止安装程序,从 InitializeSetup
return False
(你需要将一些代码移动到 InitializeSetup
)。
或使用 ExitProcess
function,如我的示例。