2

In Inno Setup below is the code used to detect the Next button events,

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  case CurPageID of
    wpLicense:
      begin
        //
      end;
    wpSelectDir:
      begin
        //
      end;
    wpSelectComponents:
      begin
        //
      end;
    wpReady:
      begin
        //
      end;
    wpFinished:
      begin
        //
      end;
    else
      begin
        ///
      end;
  end;
end;

There is custom page in place that will be shown after the installation is completed and before the finish dialog. At wpSelectDir or wpSelectComponents how can you make the installer go to this custom page without installing, when the user chooses so?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Codename K
  • 890
  • 4
  • 23
  • 52

1 Answers1

2

You cannot skip installation in Inno Setup. But what you can do is to dynamically change the placement of your custom page to show either:

  • after the installation (e.g. after wpInfoAfter), if the user chooses to install the application, or
  • before the installation (e.g. right after the wpSelectDir), if not. And abort the installation afterwards.
var
  SkipInstallCheckbox: TNewCheckBox;
  SomePage: TWizardPage;
  
procedure InitializeWizard();
begin
  SkipInstallCheckbox := TNewCheckBox.Create(WizardForm.SelectDirPage);
  SkipInstallCheckbox.Parent := WizardForm.SelectDirPage;
  SkipInstallCheckbox.Top :=
    WizardForm.DirEdit.Top + WizardForm.DirEdit.Height + ScaleY(8);
  SkipInstallCheckbox.Left := WizardForm.DirEdit.Left;
  SkipInstallCheckbox.Caption := '&Skip installation';
  // See https://stackoverflow.com/q/30469660/850848
  SkipInstallCheckbox.Height := ScaleY(SkipInstallCheckbox.Height);
end;

procedure SomePageOnActivate(Sender: TWizardPage);
begin 
  if SkipInstallCheckbox.Checked then
  begin
    // When skipping the installation, this is the last page.
    WizardForm.NextButton.Caption := SetupMessage(msgButtonFinish);
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  AfterID: Integer;
begin
  if CurPageID = wpSelectDir then
  begin
    if SkipInstallCheckbox.Checked then
      AfterID := wpSelectDir
    else
      AfterID := wpInfoAfter;

    // If user returned from the "skip" version of the page and
    // re-enabled the installation, make sure we remove the "skip" version.
    if Assigned(SomePage) then SomePage.Free;

    SomePage := CreateCustomPage(AfterID, 'Some page', '');
    SomePage.OnActivate := @SomePageOnActivate;
  end;
  Result := True;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;
  // When skipping the installation, skip all pages after our custom page
  // and before the installation.
  if (PageID in [wpSelectComponents, wpSelectProgramGroup, wpSelectTasks, wpReady]) and
     SkipInstallCheckbox.Checked then
  begin
    Result := True;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if (CurStep = ssInstall) and SkipInstallCheckbox.Checked then
  begin
    // See https://stackoverflow.com/q/4438506/850848#39788977
    Abort();
  end;
end;

A related question of yours that improves this: Can you create a custom page that looks like the Finish page?


Though to avoid all these hacks, consider allowing the installation to proceed normally, but without changing anything. It might be easier to implement in the end.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992