Skip to content

Commit c4ffa8c

Browse files
Timi007johnb432
authored andcommitted
Common - Fix retrieving the version of an addon when searching for mismatches (#10377)
* Fix version retrieval * Correct spelling * Correct spelling 2 * Optimize --------- Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
1 parent a18bc4c commit c4ffa8c

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

addons/common/functions/fnc_checkVersionNumber.sqf

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "..\script_component.hpp"
22
/*
3-
* Author: commy2, johnb43
3+
* Author: commy2, johnb43, Timi007
44
* Compares version numbers from loaded addons.
55
*
66
* Arguments:
@@ -32,8 +32,37 @@ private _cfgPatches = configFile >> "CfgPatches";
3232
private _versions = [];
3333

3434
{
35-
(getText (_cfgPatches >> _x >> "version") splitString ".") params [["_major", "0"], ["_minor", "0"]];
36-
private _version = parseNumber _major + parseNumber _minor / 100;
35+
// Determine the version of the addon. Parse it into a floating point number for comparison. Only major and minor are used.
36+
// If no version is found or a parsing error occurs, the version is zero.
37+
private _addonCfgPatches = _cfgPatches >> _x;
38+
private _versionCfg = _addonCfgPatches >> "version";
39+
private _version = switch (true) do {
40+
// Normal case. Version is defined as a floating point number -> MAJOR.MINOR
41+
case (isNumber _versionCfg): {
42+
getNumber _versionCfg
43+
};
44+
// Addon Builder converts the version into a string if it is an invalid float -> "MAJOR.MINOR.PATCH"
45+
case (isText _versionCfg): {
46+
(getText _versionCfg splitString ".") params [["_major", "0"], ["_minor", "0"]];
47+
48+
parseNumber _major + parseNumber _minor / 100
49+
};
50+
// Fallback 1 (maybe versionAr is defined)
51+
case (isArray (_addonCfgPatches >> "versionAr")): {
52+
(getArray (_addonCfgPatches >> "versionAr")) params [["_major", 0], ["_minor", 0]];
53+
54+
_major + _minor / 100
55+
};
56+
// Fallback 2 (maybe versionStr is defined)
57+
case (isText (_addonCfgPatches >> "versionStr")): {
58+
(getText (_addonCfgPatches >> "versionStr") splitString ".") params [["_major", "0"], ["_minor", "0"]];
59+
60+
parseNumber _major + parseNumber _minor / 100
61+
};
62+
// No version found
63+
default { 0 };
64+
};
65+
3766
_versions pushBack _version;
3867
} forEach _files;
3968

0 commit comments

Comments
 (0)