在不安装的情况下,有条件地跳到 Inno Setup 安装向导末尾的自定义页面?

问题描述

Inno Setup 下面是用于检测Next按钮事件的代码

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;

安装完成后和完成对话框之前,将显示自定义页面。在 wpSelectDirwpSelectComponents 处,如果用户选择这样做,您如何让安装程序在不安装的情况下转到此自定义页面

解决方法

您不能在 Inno Setup 中跳过安装。但是您可以做的是动态更改自定义页面的位置以显示:

  • 在安装之后(例如在 wpInfoAfter 之后),如果用户选择安装应用程序,或者
  • 在安装之前(例如在 wpSelectDir 之后),如果没有。然后abort the installation
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;

你的一个相关问题改善了这一点:Can you create a custom page that looks like the Finish page?


虽然要避免所有这些黑客行为,但请考虑允许安装正常进行,但不要更改任何内容。最终可能更容易实施。