【问题标题】:Ending the setup when all components have been installed in Inno Setup在 Inno Setup 中安装所有组件后结束安装
【发布时间】:2016-03-30 12:43:21
【问题描述】:

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

安装示例:

  1. 首次安装:一个组件安装
  2. 第二次安装:安装其余组件
  3. 第三次安装:安装开始并直接转到wpFinished 页面或停止并输入一条消息“所有组件都已安装”。

我在这里和其他网站上做了一些研究,我做了以下事情:

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; 在我的情况下似乎不起作用?

感谢您的帮助。

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

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


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

    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,就像我的例子一样。

    【讨论】:

      猜你喜欢
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多