From f5da2181ae8e3b80cfeca4a9df9832c7dda51016 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 31 Jul 2016 10:46:46 +0200 Subject: [PATCH 1/3] add optional pbo to load settings from userconfig file --- optionals/auto_load_settings_file/$PBOPREFIX$ | 1 + .../CfgEventHandlers.hpp | 6 ++++++ .../auto_load_settings_file/XEH_preInit.sqf | 12 ++++++++++++ optionals/auto_load_settings_file/config.cpp | 17 +++++++++++++++++ .../loadSettingsFile.sqf | 9 +++++++++ .../script_component.hpp | 16 ++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 optionals/auto_load_settings_file/$PBOPREFIX$ create mode 100644 optionals/auto_load_settings_file/CfgEventHandlers.hpp create mode 100644 optionals/auto_load_settings_file/XEH_preInit.sqf create mode 100644 optionals/auto_load_settings_file/config.cpp create mode 100644 optionals/auto_load_settings_file/loadSettingsFile.sqf create mode 100644 optionals/auto_load_settings_file/script_component.hpp diff --git a/optionals/auto_load_settings_file/$PBOPREFIX$ b/optionals/auto_load_settings_file/$PBOPREFIX$ new file mode 100644 index 000000000..2ded54d25 --- /dev/null +++ b/optionals/auto_load_settings_file/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\auto_load_settings_file diff --git a/optionals/auto_load_settings_file/CfgEventHandlers.hpp b/optionals/auto_load_settings_file/CfgEventHandlers.hpp new file mode 100644 index 000000000..f0a9f14d9 --- /dev/null +++ b/optionals/auto_load_settings_file/CfgEventHandlers.hpp @@ -0,0 +1,6 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; diff --git a/optionals/auto_load_settings_file/XEH_preInit.sqf b/optionals/auto_load_settings_file/XEH_preInit.sqf new file mode 100644 index 000000000..a45666c5d --- /dev/null +++ b/optionals/auto_load_settings_file/XEH_preInit.sqf @@ -0,0 +1,12 @@ +#include "script_component.hpp" + +ADDON = false; + +// frame after preInit, but before postInit +0 spawn { + { + #include "loadSettingsFile.sqf" + } call CBA_fnc_directCall; +}; + +ADDON = true; diff --git a/optionals/auto_load_settings_file/config.cpp b/optionals/auto_load_settings_file/config.cpp new file mode 100644 index 000000000..f1368fcce --- /dev/null +++ b/optionals/auto_load_settings_file/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + author = "$STR_CBA_Author"; + name = ECSTRING(settings,component); + url = "$STR_CBA_URL"; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"cba_settings"}; + version = VERSION; + authors[] = {"commy2"}; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/optionals/auto_load_settings_file/loadSettingsFile.sqf b/optionals/auto_load_settings_file/loadSettingsFile.sqf new file mode 100644 index 000000000..651dfd2b4 --- /dev/null +++ b/optionals/auto_load_settings_file/loadSettingsFile.sqf @@ -0,0 +1,9 @@ + +if (isFilePatchingEnabled) then { + private _source = ["client", "server"] select (isMultiplayer && isServer); + + [loadFile PATH_SETTINGS_FILE, _source] call FUNC(import); + diag_log text "[CBA] (settings): Settings file loaded."; +} else { + diag_log text "[CBA] (settings): Cannot load settings file. File patching disabled. Use -filePatching flag."; +}; diff --git a/optionals/auto_load_settings_file/script_component.hpp b/optionals/auto_load_settings_file/script_component.hpp new file mode 100644 index 000000000..cf81d3488 --- /dev/null +++ b/optionals/auto_load_settings_file/script_component.hpp @@ -0,0 +1,16 @@ +#define COMPONENT auto_load_settings_file +#include "\x\cba\addons\main\script_mod.hpp" + +//#define DEBUG_ENABLED_AUTO_LOAD_SETTINGS_FILE + +#ifdef DEBUG_ENABLED_AUTO_LOAD_SETTINGS_FILE + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_AUTO_LOAD_SETTINGS_FILE + #define DEBUG_SETTINGS DEBUG_SETTINGS_AUTO_LOAD_SETTINGS_FILE +#endif + +#include "\x\cba\addons\main\script_macros.hpp" + +#define PATH_SETTINGS_FILE "userconfig\cba\settings.sqf" From a28ff0cc8f4250457165bc5534c65a640553e29e Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 31 Jul 2016 10:57:36 +0200 Subject: [PATCH 2/3] improve logging in case file is not present --- .../auto_load_settings_file/loadSettingsFile.sqf | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/optionals/auto_load_settings_file/loadSettingsFile.sqf b/optionals/auto_load_settings_file/loadSettingsFile.sqf index 651dfd2b4..a3d542b12 100644 --- a/optionals/auto_load_settings_file/loadSettingsFile.sqf +++ b/optionals/auto_load_settings_file/loadSettingsFile.sqf @@ -1,9 +1,14 @@ if (isFilePatchingEnabled) then { - private _source = ["client", "server"] select (isMultiplayer && isServer); + private _source = ["client", "server"] select (isMultiplayer && isServer); + private _file = loadFile PATH_SETTINGS_FILE; - [loadFile PATH_SETTINGS_FILE, _source] call FUNC(import); - diag_log text "[CBA] (settings): Settings file loaded."; + if (_file != "") then { + [_file, _source] call FUNC(import); + diag_log text "[CBA] (settings): Settings file loaded."; + } else { + diag_log text "[CBA] (settings): Settings file not loaded. File empty or does not exist."; + }; } else { diag_log text "[CBA] (settings): Cannot load settings file. File patching disabled. Use -filePatching flag."; }; From 391895ebca0ce306df0962dcd567c8332e12f56b Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 6 Aug 2016 14:44:42 +0200 Subject: [PATCH 3/3] fix undefined function calls --- addons/settings/fnc_import.sqf | 4 +++- optionals/auto_load_settings_file/loadSettingsFile.sqf | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/settings/fnc_import.sqf b/addons/settings/fnc_import.sqf index 173e3130c..f651ba849 100644 --- a/addons/settings/fnc_import.sqf +++ b/addons/settings/fnc_import.sqf @@ -27,4 +27,6 @@ _info = _info call FUNC(parse); SET_TEMP_NAMESPACE_FORCED(_setting,_force,_source); } forEach _info; -call FUNC(gui_refresh); +if (!isNull (uiNamespace getVariable [QGVAR(display), displayNull])) then { + call FUNC(gui_refresh); +}; diff --git a/optionals/auto_load_settings_file/loadSettingsFile.sqf b/optionals/auto_load_settings_file/loadSettingsFile.sqf index a3d542b12..bfcf002ad 100644 --- a/optionals/auto_load_settings_file/loadSettingsFile.sqf +++ b/optionals/auto_load_settings_file/loadSettingsFile.sqf @@ -4,7 +4,7 @@ if (isFilePatchingEnabled) then { private _file = loadFile PATH_SETTINGS_FILE; if (_file != "") then { - [_file, _source] call FUNC(import); + [_file, _source] call EFUNC(settings,import); diag_log text "[CBA] (settings): Settings file loaded."; } else { diag_log text "[CBA] (settings): Settings file not loaded. File empty or does not exist.";