简体   繁体   中英

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".

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.

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?

How can I stop the wizard if all component are installed because 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).


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. If you really want to abort the installer, return False from InitializeSetup (you would need to move some of your code to the InitializeSetup ).

Or use the ExitProcess function , as in my example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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