Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FILE_EXISTS macro to common macros #899

Merged
merged 10 commits into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 _control = findDisplay 313 ctrlCreate ["RscHTML", -1];\
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;\
_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 {
Copy link
Contributor

@commy2 commy2 Mar 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initDisplayMain.sqf is executed in the onLoad event of RscDisplayMain/idd=0. findDisplay 0 will report null, because findDisplay is bugged and only reports displays that were created at least one frame* earlier.
This will cause the macro script to fall back to loadFile. And if loadFile fails, it will create an error message.
This leads to this branch of CBA to create an error pop up when loaded without cba_settings.sqf file in the main directory and file patching enabled. Try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this stay how it was or should there be a macro like FILE_EXISTS_CUSTOM also accepting a display as param to handle such cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could read the main display from uiNamespace:

uiNamespace getVariable "RscDisplayMain"

That should work even during this onLoad event as XEH DisplayLoaded is executed after the BIS_fnc_initDisplay script that sets these variables.
You should also drop the 313 display completely, as the main menu display does exist in 3den.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the main menu also exist when a mission is loaded? If not, does display 313 exist there? How would this behave when neither in 3DEN nor in main menu?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure the main menu display survives the whole session, but not 100% as I haven't messed around with it a lot in (dedicated client) MP.
Display3den is created once you enter the editor and it survives even through previews until you leave the editor back to the main menu.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. But just calling disableSerialization would have the side effect of disabling serilization for the script. Which cannot be intended.
Should wrap the thing into an isNil block to force unscheduled environment I'd say. Or alternatively store the control inside an array or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't disableSerialization scope based? However, in my tests I got no error without disableSerialization which is strange but the macro still seems to work fine. And I think you also didn't use disableSerialization in the settings scoped macro.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chris579 Script based. VM based.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't disableSerialization scope based?

No.

in my tests I got no error

The error requires serialization to be enabled in the first place. Local variables in unscheduled environment are not affected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think you also didn't use disableSerialization in the settings scoped macro.

Yes, because it was for this specific component, and I don't ever use the scheduled environment.

INFO_1("Userconfig: File [%1] loaded successfully.",_file);
_userconfig = _file;
} else {
Expand Down