简体   繁体   English

在 Inno Setup 中安装所有组件后结束安装

[英]Ending the setup when all components have been installed in Inno Setup

I'm trying to make my setup stop when all components are already install.当所有组件都已安装时,我试图让我的安装程序停止。

Installation Example :安装示例:

  1. First Install : one component install第一次安装:一个组件安装
  2. Second Install : install the rest of component第二次安装:安装其余组件
  3. Third install : setup begin and go directly to wpFinished page or stop and put a message saying "all component are already install".第三次安装:安装开始并直接转到wpFinished页面或停止并显示“所有组件都已安装”的消息。

I've make some research here and on other website and I have do the following :我在这里和其他网站上做了一些研究,我做了以下事情:

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;

Note: Code may not be very clean, I started in Pascal + Inno Setup in the Code section.注意:代码可能不是很干净,我从Code部分的 Pascal + Inno Setup 开始。

If all my component are installed (and not selectable), I want the wizard to stop and not continue...如果我的所有组件都已安装(并且不可选择),我希望向导停止而不是继续...

I can't find a solution to go directly at wpFinished page... Is there a way to do that?我找不到直接进入wpFinished页面的解决方案......有没有办法做到这一点?

How can I stop the wizard if all component are installed because WizardForm.Close;如果由于WizardForm.Close;安装了所有组件,我该如何停止向导WizardForm.Close; seems not work in my case?在我的情况下似乎不起作用?

Thanks for help.感谢您的帮助。

You cannot skip to the wpFinished page as Inno Setup does not allow you to skip the wpReady page to avoid creating a fully-automated installers (which might be abused).您不能跳到wpFinished页面,因为 Inno Setup 不允许您跳过wpReady页面以避免创建全自动安装程序(可能会被滥用)。


You can create a custom "finished" page though:你可以创建一个自定义的“完成”页面:

在此处输入图片说明

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;

Even simpler solution is to use a plain message box .更简单的解决方案是使用简单的消息框


The Wizard.Close would close the installer, it would not go to the "Finished" page anyway. Wizard.Close将关闭安装程序,无论如何它不会转到“已完成”页面。 If you really want to abort the installer, return False from InitializeSetup (you would need to move some of your code to the InitializeSetup ).如果您真的想中止安装程序,请从InitializeSetup返回False (您需要将一些代码移动到InitializeSetup )。

Or use the ExitProcess function , as in my example.或者使用ExitProcess函数,就像我的例子一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM