Inno - 自定义页面之前的任何其他内容

时间:2014-02-20 11:43:49

标签: inno-setup

我们正在将我们的应用程序切换到.Net4,但我们仍然在Windows XP SP2上拥有客户。所以我需要在设置中进行额外的检查。

在设置开始时发出弹出消息以丢弃XP SP2用户非常简单:

function InitializeSetup(): Boolean;
var
  Version: TWindowsVersion;
begin
  if IsModuleLoaded('monalbumphoto.exe') then begin
    MsgBox(ExpandConstant('{cm:PleaseClose}'), mbError, MB_OK);
    Result := false;
    Abort;
  end else begin
    // check Windows version (to display a better error message for XP SP2 users)
    GetWindowsVersionEx(Version);
    if (Version.Major = 5) and (Version.Minor = 1) and (Version.ServicePackMajor < 3) then begin
      MsgBox(ExpandConstant('{cm:WrongVersion}'), mbError, MB_OK);
      Result := false;
      Abort;
    end else begin
      Result := true;
    end;
  end;
end;

但现在,要求已经改变。我需要显示一条(有点长)消息,解释用户要么升级到SP3,要么下载我们应用的旧版本,并附带链接。

简单的方法是将消息框更改为使用“YESNO”按钮(如此问题How to show a hyperlink in Inno Setup?中)来自动下载设置。但我想更进一步。

我想显示一个自定义向导页面,其中包含说明和嵌入式链接。另一个问题(Inno Setup custom page)显示了如何做到这一点,但看起来我只能在特定页面之后创建一个页面,而不是在任何事情之前。

那么,是否可以在取消整个安装的任何其他页面之前显示自定义向导页面?

谢谢!

2 个答案:

答案 0 :(得分:2)

您可以创建要在wpWelcome之后显示的页面,并从ShouldSkipPage(wpWelcome)事件函数返回true。

或者,您可以跳过所有页面并直接跳到“准备安装”页面并重新发送文字说明。

答案 1 :(得分:1)

感谢@TLama,我现在有了这个,这看起来效果很好:

// http://stackoverflow.com/questions/5461674/
function GetSystemMetrics (nIndex: Integer): Integer;
  external 'GetSystemMetrics@User32.dll stdcall setuponly';

Const
  SM_CXSCREEN = 0; // The enum-value for getting the width of the cient area for a full-screen window on the primary display monitor, in pixels.
  SM_CYSCREEN = 1; // The enum-value for getting the height of the client area for a full-screen window on the primary display monitor, in pixels.

// Download the legacy version of the software
procedure DownloadLegacyVersion(Sender : TObject);
var
  ErrorCode: Integer;
begin
  ShellExec('open', 'http://download.monalbumphoto.fr/monAlbumPhoto_XPSP2.exe', '', '', SW_SHOW, ewNoWait, ErrorCode);
end;

// Download the legacy version of the software
procedure OpenWindowsUpdate(Sender : TObject);
var
  ErrorCode: Integer;
begin
  ShellExec('open', 'http://update.microsoft.com/', '', '', SW_SHOW, ewNoWait, ErrorCode);
end;

// creates a form specifying that the user must upgrade to SP3 or download a legacy version
procedure WindowsUpgradeNeeded();
var
  Form: TSetupForm;
  StaticText: TNewStaticText;
  LinkButton, UpdateButton, OKButton: TNewButton;
begin
  Form := CreateCustomForm();
  try
    Form.ClientWidth := ScaleX(500);
    Form.ClientHeight := ScaleY(200);
    Form.Caption := ExpandConstant('{cm:WrongVersionTitle}');
    Form.BorderStyle := bsDialog;
    Form.Center();

    StaticText := TNewStaticText.Create(Form);
    StaticText.Top := ScaleY(10);
    StaticText.Left := ScaleX(10);
    StaticText.Caption := ExpandConstant('{cm:WrongVersion}');
    StaticText.AutoSize := True;
    StaticText.Parent := Form;

    LinkButton := TNewButton.Create(Form);
    LinkButton.Parent := Form;
    LinkButton.Width := ScaleX(200);
    LinkButton.Height := ScaleY(30);
    LinkButton.Left := Round(Form.ClientWidth / 2) - Round(LinkButton.Width / 2);
    LinkButton.Top := ScaleY(StaticText.Top + StaticText.Height + 10);
    LinkButton.Caption := ExpandConstant('{cm:WrongVersionDL}');
    LinkButton.OnClick := @DownloadLegacyVersion;
    LinkButton.Default := True;

    UpdateButton := TNewButton.Create(Form);
    UpdateButton.Parent := Form;
    UpdateButton.Width := ScaleX(200);
    UpdateButton.Height := ScaleY(30);
    UpdateButton.Left := Round(Form.ClientWidth / 2) - Round(LinkButton.Width / 2);
    UpdateButton.Top := ScaleY(StaticText.Top + StaticText.Height + 10 + LinkButton.Height + 10);
    UpdateButton.Caption := ExpandConstant('{cm:WrongVersionWU}');
    UpdateButton.OnClick := @OpenWindowsUpdate;
    UpdateButton.Default := True;

    OKButton := TNewButton.Create(Form);
    OKButton.Parent := Form;
    OKButton.Width := ScaleX(75);
    OKButton.Height := ScaleY(23);
    OKButton.Left := Round(Form.ClientWidth / 2) - Round(OKButton.Width / 2);
    OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    OKButton.Caption := 'OK';
    OKButton.ModalResult := mrOk;
    OKButton.Default := False;

    Form.ActiveControl := LinkButton;

    if Form.ShowModal() = mrOk then
      MsgBox('You clicked OK.', mbInformation, MB_OK);
  finally
    Form.Free();
  end;
end;

// checks if map already running, and the minimum Windows version
function InitializeSetup(): Boolean;
var
  Version: TWindowsVersion;
begin
    // check Windows version (to display a better error message for XP SP2 users)
    GetWindowsVersionEx(Version);
    if (Version.Major = 5) and (Version.Minor = 1) and (Version.ServicePackMajor < 3) then begin
      WindowsUpgradeNeeded();
      Result := false;
    end else begin
      Result := true;
    end;
end;