| 1 |
(* Initial Developer's Public License. |
| 2 |
The contents of this file are subject to the Initial Developer's Public |
| 3 |
License Version 1.0 (the "License"). You may not use this file except |
| 4 |
in compliance with the License. You may obtain a copy of the License at |
| 5 |
http://www.ibphoenix.com?a=ibphoenix&page=ibp_idpl |
| 6 |
Software distributed under the License is distributed on an "AS IS" basis, |
| 7 |
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 8 |
for the specific language governing rights and limitations under the |
| 9 |
License. |
| 10 |
|
| 11 |
The Original Code is copyright 2001-2003 Paul Reeves for IBPhoenix. |
| 12 |
|
| 13 |
The Initial Developer of the Original Code is Paul Reeves for IBPhoenix. |
| 14 |
|
| 15 |
All Rights Reserved. |
| 16 |
|
| 17 |
Helper functions for FB installer |
| 18 |
|
| 19 |
These are / ought to be fairly generic |
| 20 |
It makes more sense if they are independant functions - ie, they don't |
| 21 |
call other functions in the script and they don't need to know about the |
| 22 |
install script itself. |
| 23 |
|
| 24 |
They can call functions in the pascal script library |
| 25 |
|
| 26 |
Function Prototypes |
| 27 |
|
| 28 |
function IsWin32: boolean; |
| 29 |
function Is32BitInstallMode: boolean; |
| 30 |
function IsWinTen: boolean; |
| 31 |
function IsWinEightOne: boolean; |
| 32 |
function IsWinEight: boolean; |
| 33 |
function IsW2K12: boolean; |
| 34 |
function IsVista: boolean; |
| 35 |
function IsVistaSP1: boolean; |
| 36 |
function IsWin2K8R1: boolean; |
| 37 |
function IsWinSeven: boolean; |
| 38 |
function IsWin2K8R2: boolean; |
| 39 |
function IsWin2k3: boolean; |
| 40 |
function IsWinXP: boolean; |
| 41 |
function IsWin2K: boolean; |
| 42 |
function IsWinNT: boolean; |
| 43 |
function IsWinME: boolean; |
| 44 |
function IsWin98: boolean; |
| 45 |
function IsWin95: boolean; |
| 46 |
function CheckWinsock2(): Boolean; |
| 47 |
function GetAppPath: String; |
| 48 |
function GetSysPath: String; |
| 49 |
function WIVersion: string; |
| 50 |
function ReplaceLine(Filename, StringToFind, NewLine,CommentType: string): boolean; |
| 51 |
procedure DecodeVersion( VerStr: String; var VerInt: array of Integer ); |
| 52 |
function CompareVersion( ver1, ver2: String ) : Integer; |
| 53 |
function GetInstalledVersion(BinaryFile: String): Array of Integer; |
| 54 |
function ConvertIBVerStrToFbVerStr( VerStr: String) : String; |
| 55 |
function GetRegistryEntry(RegKey, RegEntry: string): String; |
| 56 |
function SplitKeyValue( AString: String; theKey: Boolean): String; |
| 57 |
function GuessFirebirdPath( Product_ID: Integer; RootKey: Integer; RegKey, RegEntry: string ): String; |
| 58 |
|
| 59 |
*) |
| 60 |
|
| 61 |
(* |
| 62 |
InnoSetup Help Extract on Windows version strings: |
| 63 |
4.0.950 Windows 95 |
| 64 |
4.0.1111 Windows 95 OSR 2 & OSR 2.1 |
| 65 |
4.0.1212 Windows 95 OSR 2.5 |
| 66 |
4.1.1998 Windows 98 |
| 67 |
4.1.2222 Windows 98 Second Edition |
| 68 |
4.9.3000 Windows Me |
| 69 |
|
| 70 |
Windows NT versions: |
| 71 |
4.0.1381 Windows NT 4.0 |
| 72 |
5.0.2195 Windows 2000 |
| 73 |
5.01.2600 Windows XP |
| 74 |
or Windows XP 64-Bit Edition Version 2002 (Itanium) |
| 75 |
5.02.3790 Windows Server 2003 |
| 76 |
or Windows XP x64 Edition (AMD64/EM64T) |
| 77 |
or Windows XP 64-Bit Edition Version 2003 (Itanium) |
| 78 |
6.0.6000 Windows Vista |
| 79 |
6.0.6001 Windows Vista with Service Pack 1 |
| 80 |
or Windows Server 2008 |
| 81 |
6.0.6002 Windows Vista with Service Pack 2 |
| 82 |
6.1.7600 Windows 7 |
| 83 |
or Windows Server 2008 R2 |
| 84 |
6.2.9200 Windows 8 or Windows Server 2012 |
| 85 |
6.3.9200 Windows 8.1 or Windows Server 2012 R2 |
| 86 |
6.3.9600 Windows 8.1 with Update 1 |
| 87 |
10.0.10240 Windows 10 |
| 88 |
|
| 89 |
*) |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
function IsWin32: boolean; |
| 94 |
//helper function to simplify logic of x86/win64 checks. |
| 95 |
begin |
| 96 |
result := not IsWin64; |
| 97 |
end; |
| 98 |
|
| 99 |
function Is32BitInstallMode: boolean; |
| 100 |
//helper function to simplify logic of x86/win64 checks. |
| 101 |
begin |
| 102 |
result := not Is64BitInstallMode; |
| 103 |
end; |
| 104 |
|
| 105 |
|
| 106 |
function IsWinTen: boolean; |
| 107 |
var |
| 108 |
Version: TWindowsVersion; |
| 109 |
begin |
| 110 |
GetWindowsVersionEx(Version); |
| 111 |
if (Version.Major = 10) and (Version.Minor = 0) then |
| 112 |
result := true; |
| 113 |
end; |
| 114 |
|
| 115 |
|
| 116 |
function IsWinEightOne: boolean; |
| 117 |
var |
| 118 |
Version: TWindowsVersion; |
| 119 |
begin |
| 120 |
GetWindowsVersionEx(Version); |
| 121 |
if (Version.Major = 6) and (Version.Minor = 3) then |
| 122 |
result := true; |
| 123 |
end; |
| 124 |
|
| 125 |
function IsWinEight: boolean; |
| 126 |
var |
| 127 |
Version: TWindowsVersion; |
| 128 |
begin |
| 129 |
GetWindowsVersionEx(Version); |
| 130 |
if (Version.Major = 6) and (Version.Minor = 2) then |
| 131 |
result := true; |
| 132 |
end; |
| 133 |
|
| 134 |
//this test is identical to IsWinEight |
| 135 |
function IsW2K12: boolean; |
| 136 |
var |
| 137 |
Version: TWindowsVersion; |
| 138 |
begin |
| 139 |
GetWindowsVersionEx(Version); |
| 140 |
if (Version.Major = 6) and (Version.Minor = 2) then |
| 141 |
result := true; |
| 142 |
end; |
| 143 |
|
| 144 |
|
| 145 |
function IsVista: boolean; |
| 146 |
var |
| 147 |
Version: TWindowsVersion; |
| 148 |
begin |
| 149 |
GetWindowsVersionEx(Version); |
| 150 |
if ( Version.Major = 6 ) and ( Version.Minor = 0 ) and ( Version.build = 6000 ) then |
| 151 |
result := true; |
| 152 |
end; |
| 153 |
|
| 154 |
function IsVistaSP1: boolean; |
| 155 |
var |
| 156 |
Version: TWindowsVersion; |
| 157 |
begin |
| 158 |
GetWindowsVersionEx(Version); |
| 159 |
if ( Version.Major = 6 ) and ( Version.Minor = 0 ) and ( Version.build = 6001 )then |
| 160 |
result := true; |
| 161 |
end; |
| 162 |
|
| 163 |
function IsWin2K8R1: boolean; |
| 164 |
var |
| 165 |
Version: TWindowsVersion; |
| 166 |
begin |
| 167 |
GetWindowsVersionEx(Version); |
| 168 |
if ( Version.Major = 6 ) and ( Version.Minor = 0 ) and ( Version.build = 6001 )then |
| 169 |
result := true; |
| 170 |
end; |
| 171 |
|
| 172 |
function IsWinSeven: boolean; |
| 173 |
var |
| 174 |
Version: TWindowsVersion; |
| 175 |
begin |
| 176 |
GetWindowsVersionEx(Version); |
| 177 |
if (Version.Major = 6) and (Version.Minor = 1) then |
| 178 |
result := true; |
| 179 |
end; |
| 180 |
|
| 181 |
//This test is identical to the test for Win7 |
| 182 |
function IsWin2K8R2: boolean; |
| 183 |
var |
| 184 |
Version: TWindowsVersion; |
| 185 |
begin |
| 186 |
GetWindowsVersionEx(Version); |
| 187 |
if (Version.Major = 6) and (Version.Minor = 1) then |
| 188 |
result := true; |
| 189 |
end; |
| 190 |
|
| 191 |
|
| 192 |
function IsWin2k3: boolean; |
| 193 |
var |
| 194 |
Version: TWindowsVersion; |
| 195 |
begin |
| 196 |
GetWindowsVersionEx(Version); |
| 197 |
if (Version.Major = 5) and (Version.Minor = 2) then |
| 198 |
result := true; |
| 199 |
end; |
| 200 |
|
| 201 |
function IsWinXP: boolean; |
| 202 |
var |
| 203 |
Version: TWindowsVersion; |
| 204 |
begin |
| 205 |
GetWindowsVersionEx(Version); |
| 206 |
if (Version.Major = 5) and (Version.Minor = 1) then |
| 207 |
result := true; |
| 208 |
end; |
| 209 |
|
| 210 |
function IsWin2K: boolean; |
| 211 |
var |
| 212 |
Version: TWindowsVersion; |
| 213 |
begin |
| 214 |
GetWindowsVersionEx(Version); |
| 215 |
if (Version.Major = 5) and (Version.Minor = 0) then |
| 216 |
result := true; |
| 217 |
end; |
| 218 |
|
| 219 |
function IsWinNT: boolean; |
| 220 |
var |
| 221 |
Version: TWindowsVersion; |
| 222 |
begin |
| 223 |
GetWindowsVersionEx(Version); |
| 224 |
if (Version.Major = 4) and (Version.Minor = 0) then |
| 225 |
if Version.NTPlatform then |
| 226 |
result := true; |
| 227 |
end; |
| 228 |
|
| 229 |
function IsWinME: boolean; |
| 230 |
var |
| 231 |
Version: TWindowsVersion; |
| 232 |
begin |
| 233 |
GetWindowsVersionEx(Version); |
| 234 |
if (Version.Major = 4) and (Version.Minor = 9) then |
| 235 |
// if Version.NTPlatform then |
| 236 |
result := true; |
| 237 |
end; |
| 238 |
|
| 239 |
function IsWin98: boolean; |
| 240 |
var |
| 241 |
Version: TWindowsVersion; |
| 242 |
begin |
| 243 |
GetWindowsVersionEx(Version); |
| 244 |
if (Version.Major = 4) and (Version.Minor = 1) then |
| 245 |
// if Version.NTPlatform then |
| 246 |
result := true; |
| 247 |
end; |
| 248 |
|
| 249 |
function IsWin95: boolean; |
| 250 |
var |
| 251 |
Version: TWindowsVersion; |
| 252 |
begin |
| 253 |
GetWindowsVersionEx(Version); |
| 254 |
if (Version.Major = 4) and (Version.Minor = 0) then |
| 255 |
if not Version.NTPlatform then |
| 256 |
result := true; |
| 257 |
end; |
| 258 |
|
| 259 |
|
| 260 |
const |
| 261 |
sWinSock2 = 'ws2_32.dll'; |
| 262 |
sNoWinsock2 = 'Please Install Winsock 2 Update before continuing'; |
| 263 |
sMSWinsock2Update = 'http://www.microsoft.com/windows95/downloads/contents/WUAdminTools/S_WUNetworkingTools/W95Sockets2/Default.asp'; |
| 264 |
sWinsock2Web = 'Winsock 2 is not installed.'#13#13'Would you like to Visit the Winsock 2 Update Home Page?'; |
| 265 |
|
| 266 |
var |
| 267 |
Winsock2Failure: Boolean; |
| 268 |
|
| 269 |
function CheckWinsock2(): Boolean; |
| 270 |
begin |
| 271 |
Result := True; |
| 272 |
//Check if Winsock 2 is installed (win 95 only) |
| 273 |
if (not UsingWinNt) and (not FileExists(AddBackslash(GetSystemDir) + sWinSock2)) then begin |
| 274 |
Winsock2Failure := True; |
| 275 |
Result := False; |
| 276 |
end |
| 277 |
else |
| 278 |
Winsock2Failure := False; |
| 279 |
end; |
| 280 |
|
| 281 |
|
| 282 |
function GetAppPath: String; |
| 283 |
begin |
| 284 |
Result := ExpandConstant('{app}'); |
| 285 |
// Result := '"' + Result +'"'; |
| 286 |
end; |
| 287 |
|
| 288 |
|
| 289 |
function GetSysPath: String; |
| 290 |
begin |
| 291 |
Result := ExpandConstant('{sys}'); |
| 292 |
// Result := '"' + Result +'"'; |
| 293 |
end; |
| 294 |
|
| 295 |
|
| 296 |
function WIVersion: string; |
| 297 |
//Get version of Windows Installer |
| 298 |
var |
| 299 |
VersionStr: string; |
| 300 |
begin |
| 301 |
GetVersionNumbersString(GetSysPath + '\msi.dll', VersionStr); |
| 302 |
result := VersionStr; |
| 303 |
end; |
| 304 |
|
| 305 |
|
| 306 |
(*Based on InnoSetup KB example at http://www13.brinkster.com/vincenzog/isxart.asp?idart=14)*) |
| 307 |
function ReplaceLine(Filename, StringToFind, NewLine,CommentType: string): boolean; |
| 308 |
var |
| 309 |
i: Integer; |
| 310 |
Lines: TArrayOfString; |
| 311 |
CommentSize: Integer; |
| 312 |
ArraySize: Integer; |
| 313 |
FileChanged: Boolean; |
| 314 |
TempStr: String; |
| 315 |
begin |
| 316 |
// Load textfile into string array |
| 317 |
LoadStringsFromFile(Filename, Lines); |
| 318 |
|
| 319 |
FileChanged := false; |
| 320 |
CommentSize := Length(CommentType); |
| 321 |
ArraySize := GetArrayLength(Lines)-1; |
| 322 |
|
| 323 |
// Search through all textlines in reverse order for given text |
| 324 |
// this way we can be sure to only change the active entry |
| 325 |
for i := ArraySize downto 0 do begin |
| 326 |
// Overwrite textline when text searched for is part of it |
| 327 |
if Pos(StringToFind,Lines[i]) > 0 then begin |
| 328 |
// does this line start with a comment ? |
| 329 |
if CommentSize > 0 then begin |
| 330 |
TempStr := TrimLeft(Lines[i]); |
| 331 |
// only replace if line does not start with a comment |
| 332 |
if CompareText(Copy(TempStr,1,CommentSize),CommentType) <> 0 then begin |
| 333 |
Lines[i] := NewLine; |
| 334 |
FileChanged := true; |
| 335 |
Break; |
| 336 |
end |
| 337 |
else begin |
| 338 |
// Otherwise add new line after commented line |
| 339 |
Lines[i] := Lines[i] + #13#10 + NewLine; |
| 340 |
FileChanged := true; |
| 341 |
Break; |
| 342 |
end |
| 343 |
end |
| 344 |
else begin |
| 345 |
Lines[i] := NewLine; |
| 346 |
FileChanged := true; |
| 347 |
Break; |
| 348 |
end; |
| 349 |
// break after first match. |
| 350 |
end |
| 351 |
end; |
| 352 |
|
| 353 |
// Save string array to textfile (overwrite, no append!) |
| 354 |
if FileChanged = true then |
| 355 |
SaveStringsToFile(Filename, Lines, false); |
| 356 |
|
| 357 |
Result := FileChanged; |
| 358 |
end; |
| 359 |
|
| 360 |
|
| 361 |
function FindInFile( Filename, StringToFind: String): Boolean; |
| 362 |
var |
| 363 |
i: Integer; |
| 364 |
AString: AnsiString; |
| 365 |
begin |
| 366 |
Result := False; |
| 367 |
LoadStringFromFile( Filename, Astring ); |
| 368 |
i := Length( Astring ); |
| 369 |
if i <> 0 then |
| 370 |
i := Pos ( StringToFind, Astring ); |
| 371 |
if i <> 0 then Result := True; |
| 372 |
end; |
| 373 |
|
| 374 |
|
| 375 |
procedure DecodeVersion( VerStr: String; var VerInt: array of Integer ); |
| 376 |
var |
| 377 |
i,p: Integer; s: string; |
| 378 |
begin |
| 379 |
VerInt := [0,0,0,0]; |
| 380 |
i := 0; |
| 381 |
while ( (Length(VerStr) > 0) and (i < 4) ) do begin |
| 382 |
p := pos('.', VerStr); |
| 383 |
if p > 0 then begin |
| 384 |
if p = 1 then s:= '0' else s:= Copy( VerStr, 1, p - 1 ); |
| 385 |
VerInt[i] := StrToInt(s); |
| 386 |
i := i + 1; |
| 387 |
VerStr := Copy( VerStr, p+1, Length(VerStr)); |
| 388 |
end |
| 389 |
else begin |
| 390 |
VerInt[i] := StrToInt( VerStr ); |
| 391 |
VerStr := ''; |
| 392 |
end; |
| 393 |
end; |
| 394 |
end; |
| 395 |
|
| 396 |
|
| 397 |
function CompareVersion( ver1, ver2: String; places: Integer ) : Integer; |
| 398 |
// This function compares version strings to number of places |
| 399 |
// ie, if we are only interested in comparing major.minor versions |
| 400 |
// then places = 2 |
| 401 |
// return -1 if ver1 < ver2 |
| 402 |
// return 0 if ver1 = ver2 |
| 403 |
// return 1 if ver1 > ver2 |
| 404 |
// |
| 405 |
var |
| 406 |
verint1, verint2: array of Integer; |
| 407 |
i: integer; |
| 408 |
begin |
| 409 |
|
| 410 |
if places > 4 then |
| 411 |
places := 4; |
| 412 |
|
| 413 |
SetArrayLength( verint1, 4 ); |
| 414 |
DecodeVersion( ver1, verint1 ); |
| 415 |
|
| 416 |
SetArrayLength( verint2, 4 ); |
| 417 |
DecodeVersion( ver2, verint2 ); |
| 418 |
|
| 419 |
Result := 0; i := 0; |
| 420 |
while ( (Result = 0) and ( i < places ) ) do begin |
| 421 |
if verint1[i] > verint2[i] then |
| 422 |
Result := 1 |
| 423 |
else |
| 424 |
if verint1[i] < verint2[i] then |
| 425 |
Result := -1 |
| 426 |
else |
| 427 |
Result := 0; |
| 428 |
|
| 429 |
i := i + 1; |
| 430 |
end; |
| 431 |
|
| 432 |
end; |
| 433 |
|
| 434 |
|
| 435 |
function GetInstalledVersion(BinaryFile: String; var VerInt: Array of Integer): String; |
| 436 |
var |
| 437 |
AString: String; |
| 438 |
begin |
| 439 |
if (BinaryFile<>'') then begin |
| 440 |
GetVersionNumbersString( BinaryFile, Astring ); |
| 441 |
DecodeVersion( AString, VerInt ); |
| 442 |
end; |
| 443 |
result := AString; |
| 444 |
end; |
| 445 |
|
| 446 |
|
| 447 |
function ConvertIBVerStrToFbVerStr( VerStr: String) : String; |
| 448 |
var |
| 449 |
VerInt: array of Integer; |
| 450 |
i: Integer; |
| 451 |
begin |
| 452 |
DecodeVersion(VerStr, VerInt); |
| 453 |
VerInt[0]:=1; |
| 454 |
if VerInt[1]=2 then |
| 455 |
VerInt[1] := 0 |
| 456 |
else |
| 457 |
if VerInt[1]=3 then |
| 458 |
VerInt[1]:=5; |
| 459 |
|
| 460 |
Result := ''; |
| 461 |
for i:=0 to 3 do begin |
| 462 |
Result := Result+IntToStr(VerInt[i]); |
| 463 |
if i<3 then |
| 464 |
Result:=Result+'.' |
| 465 |
end; |
| 466 |
|
| 467 |
end; |
| 468 |
|
| 469 |
|
| 470 |
function GetRegistryEntry(RootKey: Integer; RegKey, RegEntry: string): String; |
| 471 |
begin |
| 472 |
Result := ''; |
| 473 |
//if not win64 and RootKey is HKLM64 then we are on a 32-bit box, |
| 474 |
//so skip looking in registry |
| 475 |
if ( (RootKey = HKLM64) AND (isWin32) ) then |
| 476 |
//do nothing |
| 477 |
Result := '' |
| 478 |
else |
| 479 |
RegQueryStringValue(RootKey, RegKey, RegEntry, Result); |
| 480 |
end; |
| 481 |
|
| 482 |
|
| 483 |
// Split a key value pair in two and return the value by default |
| 484 |
function SplitKeyValue( AString: String; theKey: Boolean): String; |
| 485 |
var |
| 486 |
apos: integer; |
| 487 |
akey: String; |
| 488 |
avalue: String; |
| 489 |
begin |
| 490 |
Result := ''; |
| 491 |
apos := pos( '=', AString ); |
| 492 |
if apos <> 0 then begin |
| 493 |
akey := Copy( Astring, 1, apos - 1 ); |
| 494 |
aValue := Copy ( AString, apos + 1, length (Astring) - apos ); |
| 495 |
end; |
| 496 |
if theKey then |
| 497 |
Result := aKey |
| 498 |
else |
| 499 |
Result := aValue; |
| 500 |
end; |
| 501 |
|
| 502 |
|
| 503 |
function GuessFirebirdPath( Product_ID: Integer; RootKey: Integer; RegKey, RegEntry: string ): String; |
| 504 |
begin |
| 505 |
Result := GetRegistryEntry( RootKey, RegKey, RegEntry ); |
| 506 |
|
| 507 |
if Result = '' then |
| 508 |
Result := ExpandConstant('{pf}') + '\Firebird\Firebird_' + IntToStr( Product_ID) + '_0'; |
| 509 |
end; |
| 510 |
|
| 511 |
|
| 512 |
|