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

旧城冷巷雨未停 提交于 2021-01-24 09:06:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/65532738/conditionally-skip-to-a-custom-page-at-the-end-of-the-inno-setup-installation-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!