mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
Added support for defining multiple %INJECT% launch command variables
This commit is contained in:
parent
d576cbc03f
commit
3fa89261b4
|
@ -1374,95 +1374,103 @@ void FileData::launchGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string injectFile;
|
std::string injectFile;
|
||||||
const size_t injectPos {command.find("%INJECT%")};
|
size_t injectPos {command.find("%INJECT%")};
|
||||||
|
|
||||||
if (injectPos != std::string::npos) {
|
while (injectPos != std::string::npos) {
|
||||||
bool invalidEntry {false};
|
if (injectPos != std::string::npos) {
|
||||||
|
bool invalidEntry {false};
|
||||||
|
|
||||||
if (injectPos + 10 >= command.size())
|
if (injectPos + 10 >= command.size())
|
||||||
invalidEntry = true;
|
|
||||||
else if (command[injectPos + 8] != '=')
|
|
||||||
invalidEntry = true;
|
|
||||||
|
|
||||||
if (!invalidEntry && command[injectPos + 9] == '\"') {
|
|
||||||
size_t closingQuotation {command.find("\"", injectPos + 10)};
|
|
||||||
|
|
||||||
if (closingQuotation != std::string::npos) {
|
|
||||||
injectFile = command.substr(injectPos + 10, closingQuotation - injectPos - 10);
|
|
||||||
command = command.replace(injectPos, closingQuotation - injectPos + 2, "");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
invalidEntry = true;
|
invalidEntry = true;
|
||||||
|
else if (command[injectPos + 8] != '=')
|
||||||
|
invalidEntry = true;
|
||||||
|
|
||||||
|
if (!invalidEntry && command[injectPos + 9] == '\"') {
|
||||||
|
size_t closingQuotation {command.find("\"", injectPos + 10)};
|
||||||
|
|
||||||
|
if (closingQuotation != std::string::npos) {
|
||||||
|
injectFile = command.substr(injectPos + 10, closingQuotation - injectPos - 10);
|
||||||
|
command = command.replace(injectPos, closingQuotation - injectPos + 2, "");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
invalidEntry = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (!invalidEntry) {
|
||||||
else if (!invalidEntry) {
|
const size_t spacePos {command.find(" ", injectPos)};
|
||||||
const size_t spacePos {command.find(" ", injectPos)};
|
if (spacePos != std::string::npos) {
|
||||||
if (spacePos != std::string::npos) {
|
injectFile = command.substr(injectPos + 9, spacePos - injectPos - 9);
|
||||||
injectFile = command.substr(injectPos + 9, spacePos - injectPos - 9);
|
command = command.replace(injectPos, spacePos - injectPos + 1, "");
|
||||||
command = command.replace(injectPos, spacePos - injectPos + 1, "");
|
}
|
||||||
|
else {
|
||||||
|
injectFile = command.substr(injectPos + 9, command.size() - injectPos);
|
||||||
|
command = command.replace(injectPos, command.size() - injectPos, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
injectFile = command.substr(injectPos + 9, command.size() - injectPos);
|
if (invalidEntry) {
|
||||||
command = command.replace(injectPos, command.size() - injectPos, "");
|
LOG(LogError) << "Couldn't launch game, invalid %INJECT% entry";
|
||||||
|
LOG(LogError) << "Raw emulator launch command:";
|
||||||
|
LOG(LogError) << commandRaw;
|
||||||
|
|
||||||
|
window->queueInfoPopup("ERROR: INVALID %INJECT% VARIABLE ENTRY", 6000);
|
||||||
|
window->setAllowTextScrolling(true);
|
||||||
|
window->setAllowFileAnimation(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalidEntry) {
|
if (injectFile != "") {
|
||||||
LOG(LogError) << "Couldn't launch game, invalid %INJECT% entry";
|
|
||||||
LOG(LogError) << "Raw emulator launch command:";
|
|
||||||
LOG(LogError) << commandRaw;
|
|
||||||
|
|
||||||
window->queueInfoPopup("ERROR: INVALID %INJECT% VARIABLE ENTRY", 6000);
|
|
||||||
window->setAllowTextScrolling(true);
|
|
||||||
window->setAllowFileAnimation(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (injectFile != "") {
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
injectFile = Utils::String::replace(injectFile, "\\", "/");
|
injectFile = Utils::String::replace(injectFile, "\\", "/");
|
||||||
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
|
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
|
||||||
Utils::String::replace(baseName, "\"", ""));
|
Utils::String::replace(baseName, "\"", ""));
|
||||||
if (injectFile.size() < 3 || !(injectFile[1] == ':' && injectFile[2] == '/'))
|
if (injectFile.size() < 3 || !(injectFile[1] == ':' && injectFile[2] == '/'))
|
||||||
injectFile = Utils::FileSystem::getParent(Utils::String::replace(romPath, "\"", "")) +
|
injectFile =
|
||||||
"/" + injectFile;
|
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\"", "")) + "/" +
|
||||||
injectFile = Utils::String::replace(injectFile, "/", "\\");
|
injectFile;
|
||||||
|
injectFile = Utils::String::replace(injectFile, "/", "\\");
|
||||||
#else
|
#else
|
||||||
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
|
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
|
||||||
Utils::String::replace(baseName, "\\", ""));
|
Utils::String::replace(baseName, "\\", ""));
|
||||||
if (injectFile.front() != '/')
|
if (injectFile.front() != '/')
|
||||||
injectFile = Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) +
|
injectFile =
|
||||||
"/" + injectFile;
|
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) + "/" +
|
||||||
|
injectFile;
|
||||||
#endif
|
#endif
|
||||||
if (Utils::FileSystem::isRegularFile(injectFile) ||
|
if (Utils::FileSystem::isRegularFile(injectFile) ||
|
||||||
Utils::FileSystem::isSymlink(injectFile)) {
|
Utils::FileSystem::isSymlink(injectFile)) {
|
||||||
LOG(LogDebug) << "FileData::launchGame(): Injecting from file \"" << injectFile << "\"";
|
LOG(LogDebug) << "FileData::launchGame(): Injecting from file \"" << injectFile
|
||||||
std::string arguments;
|
<< "\"";
|
||||||
std::ifstream injectFileStream;
|
std::string arguments;
|
||||||
injectFileStream.open(injectFile);
|
std::ifstream injectFileStream;
|
||||||
for (std::string line; getline(injectFileStream, line);)
|
injectFileStream.open(injectFile);
|
||||||
arguments += line;
|
for (std::string line; getline(injectFileStream, line);)
|
||||||
injectFileStream.close();
|
arguments += line;
|
||||||
|
injectFileStream.close();
|
||||||
|
|
||||||
if (arguments.empty()) {
|
if (arguments.empty()) {
|
||||||
LOG(LogDebug) << "FileData::launchGame(): File empty or insufficient permissions, "
|
LOG(LogDebug)
|
||||||
"nothing to inject";
|
<< "FileData::launchGame(): File empty or insufficient permissions, "
|
||||||
}
|
"nothing to inject";
|
||||||
else if (arguments.size() > 4096) {
|
}
|
||||||
LOG(LogWarning)
|
else if (arguments.size() > 4096) {
|
||||||
<< "FileData::launchGame(): Injection file exceeding maximum allowed size of "
|
LOG(LogWarning) << "FileData::launchGame(): Injection file exceeding maximum "
|
||||||
"4096 bytes, skipping \""
|
"allowed size of "
|
||||||
<< injectFile << "\"";
|
"4096 bytes, skipping \""
|
||||||
|
<< injectFile << "\"";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command.insert(injectPos, arguments + " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
command.insert(injectPos, arguments + " ");
|
LOG(LogDebug) << "FileData::launchGame(): File \"" << injectFile
|
||||||
|
<< "\" does not exist, nothing to inject";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
LOG(LogDebug) << "FileData::launchGame(): File \"" << injectFile
|
injectPos = command.find("%INJECT%");
|
||||||
<< "\" does not exist, nothing to inject";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
|
|
Loading…
Reference in a new issue