Skip to content

Commit

Permalink
Common - Fix retrieving the version of an addon when searching for mi…
Browse files Browse the repository at this point in the history
…smatches (#10377)

* Fix version retrieval

* Correct spelling

* Correct spelling 2

* Optimize

---------

Co-authored-by: johnb432 <[email protected]>
  • Loading branch information
2 people authored and LinkIsGrim committed Nov 2, 2024
1 parent a18bc4c commit c4ffa8c
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions addons/common/functions/fnc_checkVersionNumber.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"
/*
* Author: commy2, johnb43
* Author: commy2, johnb43, Timi007
* Compares version numbers from loaded addons.
*
* Arguments:
Expand Down Expand Up @@ -32,8 +32,37 @@ private _cfgPatches = configFile >> "CfgPatches";
private _versions = [];

{
(getText (_cfgPatches >> _x >> "version") splitString ".") params [["_major", "0"], ["_minor", "0"]];
private _version = parseNumber _major + parseNumber _minor / 100;
// Determine the version of the addon. Parse it into a floating point number for comparison. Only major and minor are used.
// If no version is found or a parsing error occurs, the version is zero.
private _addonCfgPatches = _cfgPatches >> _x;
private _versionCfg = _addonCfgPatches >> "version";
private _version = switch (true) do {
// Normal case. Version is defined as a floating point number -> MAJOR.MINOR
case (isNumber _versionCfg): {
getNumber _versionCfg
};
// Addon Builder converts the version into a string if it is an invalid float -> "MAJOR.MINOR.PATCH"
case (isText _versionCfg): {
(getText _versionCfg splitString ".") params [["_major", "0"], ["_minor", "0"]];

parseNumber _major + parseNumber _minor / 100
};
// Fallback 1 (maybe versionAr is defined)
case (isArray (_addonCfgPatches >> "versionAr")): {
(getArray (_addonCfgPatches >> "versionAr")) params [["_major", 0], ["_minor", 0]];

_major + _minor / 100
};
// Fallback 2 (maybe versionStr is defined)
case (isText (_addonCfgPatches >> "versionStr")): {
(getText (_addonCfgPatches >> "versionStr") splitString ".") params [["_major", "0"], ["_minor", "0"]];

parseNumber _major + parseNumber _minor / 100
};
// No version found
default { 0 };
};

_versions pushBack _version;
} forEach _files;

Expand Down

0 comments on commit c4ffa8c

Please sign in to comment.