From 6e24c8d77b81860f0ab4a44e996f59764e45141c Mon Sep 17 00:00:00 2001 From: Leon Styhre <leon@leonstyhre.com> Date: Sun, 5 Dec 2021 11:25:11 +0100 Subject: [PATCH] Increased the amount of custom event arguments from two to four. --- es-core/src/Scripting.cpp | 34 ++++++++++++++++++++++++++-------- es-core/src/Scripting.h | 12 +++++++----- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/es-core/src/Scripting.cpp b/es-core/src/Scripting.cpp index 300ea7cdf..82f27e9a2 100644 --- a/es-core/src/Scripting.cpp +++ b/es-core/src/Scripting.cpp @@ -3,12 +3,12 @@ // EmulationStation Desktop Edition // Scripting.cpp // -// Executes custom scripts for various events in EmulationStation. +// Executes custom scripts for various events. // By calling fireEvent() the scripts inside the directory corresponding to the -// argument 'eventName' will be executed with arg1 and arg2 as the script arguments. +// argument "eventName" will be executed with arg1, arg2, arg3 and arg4 as arguments. // // The scripts are searched for in ~/.emulationstation/scripts/<eventName> -// For example, if the event is called 'game-start', all scripts inside the directory +// For example, if the event is called "game-start", all scripts inside the directory // ~/.emulationstation/scripts/game-start/ will be executed. // @@ -21,13 +21,17 @@ namespace Scripting { - void fireEvent(const std::string& eventName, const std::string& arg1, const std::string& arg2) + void fireEvent(const std::string& eventName, + const std::string& arg1, + const std::string& arg2, + const std::string& arg3, + const std::string& arg4) { if (!Settings::getInstance()->getBool("CustomEventScripts")) return; LOG(LogDebug) << "Scripting::fireEvent(): " << eventName << " \"" << arg1 << "\" \"" << arg2 - << "\""; + << "\" \"" << arg3 << "\" \"" << arg4 << "\""; std::list<std::string> scriptDirList; std::string scriptDir; @@ -42,12 +46,18 @@ namespace Scripting for (auto it = scripts.cbegin(); it != scripts.cend(); ++it) { std::string arg1Quotation; std::string arg2Quotation; + std::string arg3Quotation; + std::string arg4Quotation; // Add quotation marks around the arguments as long as these are not already // present (i.e. for arguments with spaces in them). - if (arg1.front() != '\"') + if (!arg1.empty() && arg1.front() != '\"') arg1Quotation = "\""; - if (arg2.front() != '\"') + if (!arg2.empty() && arg2.front() != '\"') arg2Quotation = "\""; + if (!arg3.empty() && arg3.front() != '\"') + arg3Quotation = "\""; + if (!arg4.empty() && arg4.front() != '\"') + arg4Quotation = "\""; std::string script; script.append(*it) .append(" ") @@ -57,7 +67,15 @@ namespace Scripting .append(" ") .append(arg2Quotation) .append(arg2) - .append(arg2Quotation); + .append(arg2Quotation) + .append(" ") + .append(arg3Quotation) + .append(arg3) + .append(arg3Quotation) + .append(" ") + .append(arg4Quotation) + .append(arg4) + .append(arg4Quotation); LOG(LogDebug) << "Executing: " << script; runSystemCommand(script); } diff --git a/es-core/src/Scripting.h b/es-core/src/Scripting.h index 9df4ab399..b2217228e 100644 --- a/es-core/src/Scripting.h +++ b/es-core/src/Scripting.h @@ -3,12 +3,12 @@ // EmulationStation Desktop Edition // Scripting.h // -// Executes custom scripts for various events in EmulationStation. +// Executes custom scripts for various events. // By calling fireEvent() the scripts inside the directory corresponding to the -// argument 'eventName' will be executed with arg1 and arg2 as the script arguments. +// argument "eventName" will be executed with arg1, arg2, arg3 and arg4 as arguments. // // The scripts are searched for in ~/.emulationstation/scripts/<eventName> -// For example, if the event is called 'game-start', all scripts inside the directory +// For example, if the event is called "game-start", all scripts inside the directory // ~/.emulationstation/scripts/game-start/ will be executed. // @@ -21,7 +21,9 @@ namespace Scripting { void fireEvent(const std::string& eventName, const std::string& arg1 = "", - const std::string& arg2 = ""); -} + const std::string& arg2 = "", + const std::string& arg3 = "", + const std::string& arg4 = ""); +} // namespace Scripting #endif // ES_CORE_SCRIPTING_H