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

时间:2016-03-30 12:43:22

标签: inno-setup pascalscript

我正在尝试在所有组件都已安装时停止设置。

安装示例:

  1. 首次安装:安装一个组件
  2. 第二次安装:安装组件的其余部分
  3. 第三次安装:设置开始并直接转到wpFinished页面或停止并显示“所有组件已安装”的消息。
  4. 我在这里和其他网站上做了一些研究,我做了以下工作:

    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安装程序中启动。

    如果安装了所有组件(并且无法选择),我希望向导停止而不是继续......

    我无法找到直接转到wpFinished页面的解决方案......有没有办法做到这一点?

    如果因为WizardForm.Close;似乎在我的情况下不起作用而安装了所有组件,我该如何停止向导?

    感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您无法跳到wpFinished页面,因为Inno安装程序不允许您跳过wpReady页面以避免创建全自动安装程序(可能会被滥用)。

您可以创建自定义的“已完成”页面:

enter image description here

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将关闭安装程序,无论如何都不会进入“完成”页面。如果您确实想要中止安装程序,请从InitializeSetup返回False(您需要将部分代码移至InitializeSetup)。

或者使用ExitProcess function,如我的示例所示。

相关问题