Skip to content

Commit

Permalink
Merge pull request #899 from chris579/patch-1
Browse files Browse the repository at this point in the history
Add FILE_EXISTS macro to common macros
  • Loading branch information
Killswitch00 committed Apr 14, 2018
2 parents 626fb6b + 024db62 commit f1bd2cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
33 changes: 33 additions & 0 deletions addons/main/script_macros_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,3 +1725,36 @@ Macro: IS_ADMIN_LOGGED
commy2
------------------------------------------- */
#define IS_ADMIN_LOGGED serverCommandAvailable "#shutdown"

/* -------------------------------------------
Macro: 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.
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 _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;\
};\
};\
_return\
})
9 changes: 0 additions & 9 deletions addons/settings/fnc_initDisplay3DEN.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
9 changes: 0 additions & 9 deletions addons/settings/fnc_initDisplayGameOptions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 1 addition & 12 deletions addons/settings/fnc_initDisplayMain.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f1bd2cd

Please sign in to comment.