Inno Setup 安装向导结束时有条件地跳到自定义页面而不安装?

Conditionally skip to a custom page at the end of the Inno Setup installation wizard without installing?

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 
  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 
    Abort();
  end;
end;

你的一个相关问题改进了这一点:


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