Increased the amount of custom event arguments from two to four.

This commit is contained in:
Leon Styhre 2021-12-05 11:25:11 +01:00
parent 0b79c19883
commit 6e24c8d77b
2 changed files with 33 additions and 13 deletions

View file

@ -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);
}

View file

@ -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