From 5c73f00aeeb73cac9edc488378770926fe1a7263 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Wed, 9 Oct 2024 00:32:56 +0200 Subject: [PATCH 1/4] Fix version retrieval --- .../functions/fnc_checkVersionNumber.sqf | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/addons/common/functions/fnc_checkVersionNumber.sqf b/addons/common/functions/fnc_checkVersionNumber.sqf index 61ed7f62313..b6e803736ba 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,36 @@ private _cfgPatches = configFile >> "CfgPatches"; private _versions = []; { - (getText (_cfgPatches >> _x >> "version") splitString ".") params [["_major", "0"], ["_minor", "0"]]; - private _version = parseNumber _major + parseNumber _minor / 100; + // Determine version of addon. Parse it to 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 _versionCfg = _cfgPatches >> _x >> "version"; + private _version = switch (true) do { + // Normal case. Version is defined as floating point number -> MAJOR.MINOR + case (isNumber _versionCfg): { + getNumber _versionCfg + }; + // Addon Builder convert the version to 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 (_cfgPatches >> _x >> "versionAr")): { + (getArray (_cfgPatches >> _x >> "versionAr")) params [["_major", 0], ["_minor", 0]]; + + _major + _minor / 100 + }; + // Fallback 2 (maybe versionStr is defined) + case (isText (_cfgPatches >> _x >> "versionStr")): { + (getText (_cfgPatches >> _x >> "versionStr") splitString ".") params [["_major", "0"], ["_minor", "0"]]; + + parseNumber _major + parseNumber _minor / 100 + }; + // No version found + default { 0 }; + }; + _versions pushBack _version; } forEach _files; From 9014fbdff8b52a3427a5462ae76f42d6a9178e48 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Wed, 9 Oct 2024 00:42:03 +0200 Subject: [PATCH 2/4] Correct spelling --- addons/common/functions/fnc_checkVersionNumber.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/common/functions/fnc_checkVersionNumber.sqf b/addons/common/functions/fnc_checkVersionNumber.sqf index b6e803736ba..0f6539e48b3 100644 --- a/addons/common/functions/fnc_checkVersionNumber.sqf +++ b/addons/common/functions/fnc_checkVersionNumber.sqf @@ -32,15 +32,15 @@ private _cfgPatches = configFile >> "CfgPatches"; private _versions = []; { - // Determine version of addon. Parse it to a floating point number for comparison. Only major and minor are used. + // Determine the version of 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 _versionCfg = _cfgPatches >> _x >> "version"; private _version = switch (true) do { - // Normal case. Version is defined as floating point number -> MAJOR.MINOR + // Normal case. Version is defined as a floating point number -> MAJOR.MINOR case (isNumber _versionCfg): { getNumber _versionCfg }; - // Addon Builder convert the version to a string if it is an invalid float -> "MAJOR.MINOR.PATCH" + // Addon Builder converts the version to a string if it is an invalid float -> "MAJOR.MINOR.PATCH" case (isText _versionCfg): { (getText _versionCfg splitString ".") params [["_major", "0"], ["_minor", "0"]]; From 771c90abdf0fa357b6d2ddbbf651e871497114f3 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Wed, 9 Oct 2024 00:46:51 +0200 Subject: [PATCH 3/4] Correct spelling 2 --- addons/common/functions/fnc_checkVersionNumber.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_checkVersionNumber.sqf b/addons/common/functions/fnc_checkVersionNumber.sqf index 0f6539e48b3..a4492692c26 100644 --- a/addons/common/functions/fnc_checkVersionNumber.sqf +++ b/addons/common/functions/fnc_checkVersionNumber.sqf @@ -32,7 +32,7 @@ private _cfgPatches = configFile >> "CfgPatches"; private _versions = []; { - // Determine the version of addon. Parse it into a floating point number for comparison. Only major and minor are used. + // 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 _versionCfg = _cfgPatches >> _x >> "version"; private _version = switch (true) do { @@ -40,7 +40,7 @@ private _versions = []; case (isNumber _versionCfg): { getNumber _versionCfg }; - // Addon Builder converts the version to a string if it is an invalid float -> "MAJOR.MINOR.PATCH" + // 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"]]; From 0be8442a9adc2b668a89cc896d1ae76ddb1553c4 Mon Sep 17 00:00:00 2001 From: Timi007 Date: Wed, 9 Oct 2024 01:20:51 +0200 Subject: [PATCH 4/4] Optimize --- addons/common/functions/fnc_checkVersionNumber.sqf | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/common/functions/fnc_checkVersionNumber.sqf b/addons/common/functions/fnc_checkVersionNumber.sqf index a4492692c26..5fc5ea22fda 100644 --- a/addons/common/functions/fnc_checkVersionNumber.sqf +++ b/addons/common/functions/fnc_checkVersionNumber.sqf @@ -34,7 +34,8 @@ private _versions = []; { // 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 _versionCfg = _cfgPatches >> _x >> "version"; + 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): { @@ -47,14 +48,14 @@ private _versions = []; parseNumber _major + parseNumber _minor / 100 }; // Fallback 1 (maybe versionAr is defined) - case (isArray (_cfgPatches >> _x >> "versionAr")): { - (getArray (_cfgPatches >> _x >> "versionAr")) params [["_major", 0], ["_minor", 0]]; + case (isArray (_addonCfgPatches >> "versionAr")): { + (getArray (_addonCfgPatches >> "versionAr")) params [["_major", 0], ["_minor", 0]]; _major + _minor / 100 }; // Fallback 2 (maybe versionStr is defined) - case (isText (_cfgPatches >> _x >> "versionStr")): { - (getText (_cfgPatches >> _x >> "versionStr") splitString ".") params [["_major", "0"], ["_minor", "0"]]; + case (isText (_addonCfgPatches >> "versionStr")): { + (getText (_addonCfgPatches >> "versionStr") splitString ".") params [["_major", "0"], ["_minor", "0"]]; parseNumber _major + parseNumber _minor / 100 };