From b54bdf424a014eb8cbe44fa38f30eb45c8c28654 Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 19:51:12 +0100 Subject: [PATCH 01/10] Added FILE_EXISTS macro to common macros --- addons/main/script_macros_common.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 4a5c7a76d..8880a8ff4 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1725,3 +1725,31 @@ Macro: IS_ADMIN_LOGGED commy2 ------------------------------------------- */ #define IS_ADMIN_LOGGED serverCommandAvailable "#shutdown" + + +/* ------------------------------------------- +Macro: FILE_EXISTS + Check if a file exists + + Reports "false" if the file does not exist. + +Parameters: + FILE - Path to the file + +Example: + (begin example) + // print "true" if file exists + systemChat str FILE_EXISTS("\A3\ui_f\data\igui\cfg\cursors\weapon_ca.paa"); + (end) + +Author: + commy2 +------------------------------------------- */ +#define FILE_EXISTS(FILE) \ +call {\ + private _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\ + _control htmlLoad FILE;\ + private _return = ctrlHTMLLoaded _control;\ + ctrlDelete _control;\ + _return\ +}; From 04912189d529c4090f05386bbf2e6543d79dd61e Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 19:56:01 +0100 Subject: [PATCH 02/10] Removed macro definition --- addons/settings/fnc_initDisplay3DEN.sqf | 9 --------- 1 file changed, 9 deletions(-) diff --git a/addons/settings/fnc_initDisplay3DEN.sqf b/addons/settings/fnc_initDisplay3DEN.sqf index 9251e9b41..7447415c2 100644 --- a/addons/settings/fnc_initDisplay3DEN.sqf +++ b/addons/settings/fnc_initDisplay3DEN.sqf @@ -71,15 +71,6 @@ add3DENEventHandler ["OnMissionLoad", _fnc_resetMissionSettingsMissionChanged]; #define MESSAGE_EXPORTED_SP 5 #define MESSAGE_EXPORTED_MP 6 -#define FILE_EXISTS(file) \ -call {\ - private _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\ - _control htmlLoad file;\ - private _return = ctrlHTMLLoaded _control;\ - ctrlDelete _control;\ - _return\ -}; - add3DENEventHandler ["OnMessage", { params ["_message"]; From 48f18cc4b20f237ba48af4a7964fe7cfbdbeae70 Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 19:56:48 +0100 Subject: [PATCH 03/10] Removed macro definition --- addons/settings/fnc_initDisplayGameOptions.sqf | 9 --------- 1 file changed, 9 deletions(-) diff --git a/addons/settings/fnc_initDisplayGameOptions.sqf b/addons/settings/fnc_initDisplayGameOptions.sqf index 2b355a2c7..d4f3ba857 100644 --- a/addons/settings/fnc_initDisplayGameOptions.sqf +++ b/addons/settings/fnc_initDisplayGameOptions.sqf @@ -35,15 +35,6 @@ if (isServer) then { }; // ----- reload settings file if in editor -#define FILE_EXISTS(file) \ -call {\ - private _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\ - _control htmlLoad file;\ - private _return = ctrlHTMLLoaded _control;\ - ctrlDelete _control;\ - _return\ -}; - if (is3DEN && {FILE_EXISTS(MISSION_SETTINGS_FILE)}) then { GVAR(missionConfig) call CBA_fnc_deleteNamespace; GVAR(missionConfig) = [] call CBA_fnc_createNamespace; From b50ab245549e47ed1d74bf4d2399cbbe5a1004ac Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 20:03:47 +0100 Subject: [PATCH 04/10] Removed newline --- addons/main/script_macros_common.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 8880a8ff4..5b2efeebf 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1726,7 +1726,6 @@ Macro: IS_ADMIN_LOGGED ------------------------------------------- */ #define IS_ADMIN_LOGGED serverCommandAvailable "#shutdown" - /* ------------------------------------------- Macro: FILE_EXISTS Check if a file exists From 745b36725bb06966cb51de61640a0b6d9d4688f1 Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 20:14:09 +0100 Subject: [PATCH 05/10] Adjusted description --- addons/main/script_macros_common.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 5b2efeebf..be88b0373 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1730,7 +1730,7 @@ Macro: IS_ADMIN_LOGGED Macro: FILE_EXISTS Check if a file exists - Reports "false" if the file does not exist. + Reports "false" if the file does not exist and throws an error in RPT. Parameters: FILE - Path to the file From e8c71bbb885a713cc0a0aa523afd517b301c404b Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 21:12:41 +0100 Subject: [PATCH 06/10] DisplayMain added --- addons/main/script_macros_common.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index be88b0373..0ab958d05 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1728,7 +1728,7 @@ Macro: IS_ADMIN_LOGGED /* ------------------------------------------- Macro: FILE_EXISTS - Check if a file exists + Check if a file exists on machines with interface Reports "false" if the file does not exist and throws an error in RPT. @@ -1747,6 +1747,9 @@ Macro: FILE_EXISTS #define FILE_EXISTS(FILE) \ call {\ private _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\ + if (isNull _control) then {\ + _control = findDisplay 0 ctrlCreate ["RscHTML", -1];\ + };\ _control htmlLoad FILE;\ private _return = ctrlHTMLLoaded _control;\ ctrlDelete _control;\ From 291414b9a1b94426f18fb97fec9e492f7282e334 Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 21:19:46 +0100 Subject: [PATCH 07/10] Added loadFile fallback --- addons/main/script_macros_common.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 0ab958d05..9bd2858b2 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1750,6 +1750,9 @@ call {\ if (isNull _control) then {\ _control = findDisplay 0 ctrlCreate ["RscHTML", -1];\ };\ + if (isNull _control) exitWith {\ + loadFile FILE != "";\ + };\ _control htmlLoad FILE;\ private _return = ctrlHTMLLoaded _control;\ ctrlDelete _control;\ From ee23861710e2917aec24f60579296c1d05f6479d Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Sun, 11 Mar 2018 21:20:51 +0100 Subject: [PATCH 08/10] Replaced file check with macro --- addons/settings/fnc_initDisplayMain.sqf | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/addons/settings/fnc_initDisplayMain.sqf b/addons/settings/fnc_initDisplayMain.sqf index e368600cc..42801da60 100644 --- a/addons/settings/fnc_initDisplayMain.sqf +++ b/addons/settings/fnc_initDisplayMain.sqf @@ -16,18 +16,7 @@ if (isClass (configFile >> "CfgPatches" >> QGVAR(userconfig))) then { private _userconfig = ""; if (_file != "") then { - private _fileExists = false; - - if (!isNull _display) then { - private _control = _display ctrlCreate ["RscHTML", -1]; - _control htmlLoad _file; - _fileExists = ctrlHTMLLoaded _control; - ctrlDelete _control; - } else { - _fileExists = loadFile _file != ""; - }; - - if (_fileExists) then { + if (FILE_EXISTS(_file)) then { INFO_1("Userconfig: File [%1] loaded successfully.",_file); _userconfig = _file; } else { From 156efeb526301690956a64527b94574a34dcd7bf Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 12 Mar 2018 11:25:49 +0100 Subject: [PATCH 09/10] get main menu display from ui namespace --- addons/main/script_macros_common.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 9bd2858b2..2a9de67a1 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1744,12 +1744,8 @@ Macro: FILE_EXISTS Author: commy2 ------------------------------------------- */ -#define FILE_EXISTS(FILE) \ -call {\ - private _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\ - if (isNull _control) then {\ - _control = findDisplay 0 ctrlCreate ["RscHTML", -1];\ - };\ +#define FILE_EXISTS(FILE) (call {\ + private _control = (uiNamespace getVariable ["RscDisplayMain", displayNull]) ctrlCreate ["RscHTML", -1];\ if (isNull _control) exitWith {\ loadFile FILE != "";\ };\ @@ -1757,4 +1753,4 @@ call {\ private _return = ctrlHTMLLoaded _control;\ ctrlDelete _control;\ _return\ -}; +}) From 024db621d96f964780c4c912f50f72c06b1fc4ae Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 17 Mar 2018 17:42:57 +0100 Subject: [PATCH 10/10] unscheduled to avoid serialization pop up, parenthesis around arg --- addons/main/script_macros_common.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 2a9de67a1..f65aef899 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1745,12 +1745,16 @@ Macro: FILE_EXISTS commy2 ------------------------------------------- */ #define FILE_EXISTS(FILE) (call {\ - private _control = (uiNamespace getVariable ["RscDisplayMain", displayNull]) ctrlCreate ["RscHTML", -1];\ - if (isNull _control) exitWith {\ - loadFile FILE != "";\ + private _return = false;\ + isNil {\ + private _control = (uiNamespace getVariable ["RscDisplayMain", displayNull]) ctrlCreate ["RscHTML", -1];\ + if (isNull _control) then {\ + _return = loadFile (FILE) != "";\ + } else {\ + _control htmlLoad (FILE);\ + _return = ctrlHTMLLoaded _control;\ + ctrlDelete _control;\ + };\ };\ - _control htmlLoad FILE;\ - private _return = ctrlHTMLLoaded _control;\ - ctrlDelete _control;\ _return\ })