Reputation: 6037
We are switching our application to .Net4, but we still have customers on Windows XP SP2. So I need to make additionnal checks in the setup.
Making a popup message at the start of the setup to throw away XP SP2 users is pretty easy :
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;
But now, the requirements have changed. I need to display a (kind of long) message, explaining that the user either have to upgrade to SP3, or download a legacy version of our app, with a link to it.
The easy way is to change the messagebox to use "YESNO" buttons (like in this question How to show a hyperlink in Inno Setup?) to automatically download the setup. But I want to go further.
I would like to display a custom wizard page with the explanation, and an embedded link. Another question (Inno Setup custom page) shows how to do it, but it looks like I can only create a page AFTER a specific page, and not BEFORE anything.
So, is it possible to display a custom wizard page BEFORE any other page, that cancels the whole installation ?
Thank you !
Upvotes: 3
Views: 1153
Reputation: 6037
Thanks to @TLama, I now have this, which seems to be working great :
// http://stackoverflow.com/questions/5461674/
function GetSystemMetrics (nIndex: Integer): Integer;
external '[email protected] 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;
Upvotes: 1
Reputation: 24273
You can create the page to appear after wpWelcome
and return true from the ShouldSkipPage(wpWelcome)
event function.
Alternatively, you can skip all pages and jump straight to the "Prepare to install" page and retunr text giving instructions.
Upvotes: 2