Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 855ec65

Browse files
committed
New utility functions for comparing version numbers
1 parent a4fed6f commit 855ec65

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/util.iss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ begin
6060
Delete(URL, 1, Pos('://', URL) + 2);
6161
Result := GetURLFilePartRec(URL);
6262
end;
63+
64+
function CompareVersions(VerL, VerR: String): Integer;
65+
var
66+
VerLExplode: TStrings;
67+
VerRExplode: TStrings;
68+
i: Integer;
69+
MinCount: Integer;
70+
begin
71+
Result := 0;
72+
VerLExplode := SplitString(VerL, '.');
73+
VerRExplode := SplitString(VerR, '.');
74+
75+
if VerLExplode.Count < VerRExplode.Count then begin
76+
MinCount := VerLExplode.Count;
77+
end else begin
78+
MinCount := VerRExplode.Count;
79+
end;
80+
81+
for i := 0 to MinCount - 1 do begin
82+
if StrToIntDef(VerLExplode[i], 0) < StrToIntDef(VerRExplode[i], 0) then begin
83+
Result := 1;
84+
exit;
85+
end else if StrToIntDef(VerLExplode[i], 0) > StrToIntDef(VerLExplode[i], 0) then begin
86+
Result := -1;
87+
exit;
88+
end;
89+
end;
90+
end;
91+
92+
function GetLatestVersion(Versions: TArrayOfString): String;
93+
var
94+
i: Integer;
95+
begin
96+
Result := Versions[0];
97+
for i := 0 to GetArrayLength(Versions) - 1 do begin
98+
if CompareVersions(Result, Versions[i]) = 1 then
99+
Result := Versions[i];
100+
end;
101+
end;

0 commit comments

Comments
 (0)