From b76e0bea839fe3c5d59e2490713d0caba029b0ca Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Tue, 2 Jul 2019 14:58:18 +0530 Subject: [PATCH] Ensure the version comparision should be correct for windows installer. Fixes #4421 --- docs/en_US/release_notes_4_10.rst | 5 +- pkg/win32/installer.iss.in | 78 ++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/docs/en_US/release_notes_4_10.rst b/docs/en_US/release_notes_4_10.rst index 85b773862..76cc4af25 100644 --- a/docs/en_US/release_notes_4_10.rst +++ b/docs/en_US/release_notes_4_10.rst @@ -2,7 +2,7 @@ Version 4.10 ************ -Release date: 2019-07-02 +Release date: 2019-07-04 This release contains a number of bug fixes and new features since the release of pgAdmin4 4.9. @@ -17,4 +17,5 @@ Bug fixes | `Bug #4403 `_ - Ensure the browser close confirmation is only shown when closing a Query Tool which is running in a separate browser tab. | `Bug #4404 `_ - Prevent an error that may occur when editing data with an integer primary key. -| `Bug #4407 `_ - Fix a quoting issue that caused a blank UI to be displayed when running in French. \ No newline at end of file +| `Bug #4407 `_ - Fix a quoting issue that caused a blank UI to be displayed when running in French. +| `Bug #4421 `_ - Ensure the version comparision should be correct for windows installer. \ No newline at end of file diff --git a/pkg/win32/installer.iss.in b/pkg/win32/installer.iss.in index 299d7e271..7fda5b0d7 100644 --- a/pkg/win32/installer.iss.in +++ b/pkg/win32/installer.iss.in @@ -64,6 +64,82 @@ Root: HKLM; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; ValueType: string; var UpgradeMode: Boolean; +// Procedure to split a string into an array of integers +procedure Explode(var Dest: TArrayOfInteger; Text: String; Separator: String); +var + i, p: Integer; +begin + i := 0; + repeat + SetArrayLength(Dest, i+1); + p := Pos(Separator,Text); + if p > 0 then begin + Dest[i] := StrToInt(Copy(Text, 1, p-1)); + Text := Copy(Text, p + Length(Separator), Length(Text)); + i := i + 1; + end else begin + Dest[i] := StrToInt(Text); + Text := ''; + end; + until Length(Text)=0; +end; + +// Function compares version strings numerically: +// * when v1 = v2, result = 0 +// * when v1 < v2, result = -1 +// * when v1 > v2, result = 1 +// +// Supports version numbers with trailing zeroes, for example 1.02.05. +// Supports comparison of two version number of different lengths, +// for example CompareVersions('1.2', '2.0.3') +// When any of the parameters is '' (empty string) it considers version +// number as 0 +function CompareVersions(v1: String; v2: String): Integer; +var + v1parts: TArrayOfInteger; + v2parts: TArrayOfInteger; + i: Integer; +begin + if v1 = '' then + begin + v1 := '0'; + end; + + if v2 = '' then + begin + v2 := '0'; + end; + + Explode(v1parts, v1, '.'); + Explode(v2parts, v2, '.'); + + if (GetArrayLength(v1parts) > GetArrayLength(v2parts)) then + begin + SetArrayLength(v2parts, GetArrayLength(v1parts)) + end else if (GetArrayLength(v2parts) > GetArrayLength(v1parts)) then + begin + SetArrayLength(v1parts, GetArrayLength(v2parts)) + end; + + for i := 0 to GetArrayLength(v1parts) - 1 do + begin + if v1parts[i] > v2parts[i] then + begin + { v1 is greater } + Result := 1; + exit; + end else if v1parts[i] < v2parts[i] then + begin + { v2 is greater } + Result := -1; + exit; + end; + end; + + { Are Equal } + Result := 0; +end; + function IsPathValid(Path: string): Boolean; var I: Integer; @@ -103,7 +179,7 @@ begin begin UpgradeMode := True; RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version); - if Version > '{#MyAppFullVersion}' then + if CompareVersions(Version, '{#MyAppFullVersion}') = -1 then begin MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK); Result := False;