From c4ffa8c90e09e30eb0e9282e4677c7d5e42b0021 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 25 Oct 2024 09:35:59 +0200 Subject: [PATCH] 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> --- .../functions/fnc_checkVersionNumber.sqf | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/addons/common/functions/fnc_checkVersionNumber.sqf b/addons/common/functions/fnc_checkVersionNumber.sqf index 61ed7f62313..5fc5ea22fda 100644 --- a/addons/common/functions/fnc_checkVersionNumber.sqf +++ b/addons/common/functions/fnc_checkVersionNumber.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: commy2, johnb43 + * Author: commy2, johnb43, Timi007 * Compares version numbers from loaded addons. * * Arguments: @@ -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;