Added support for defining multiple %INJECT% launch command variables

This commit is contained in:
Leon Styhre 2023-10-02 20:02:29 +02:00
parent d576cbc03f
commit 3fa89261b4

View file

@ -1374,8 +1374,9 @@ void FileData::launchGame()
}
std::string injectFile;
const size_t injectPos {command.find("%INJECT%")};
size_t injectPos {command.find("%INJECT%")};
while (injectPos != std::string::npos) {
if (injectPos != std::string::npos) {
bool invalidEntry {false};
@ -1425,19 +1426,22 @@ void FileData::launchGame()
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
Utils::String::replace(baseName, "\"", ""));
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;
injectFile = Utils::String::replace(injectFile, "/", "\\");
#else
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
Utils::String::replace(baseName, "\\", ""));
if (injectFile.front() != '/')
injectFile = Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) +
"/" + injectFile;
injectFile =
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) + "/" +
injectFile;
#endif
if (Utils::FileSystem::isRegularFile(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;
injectFileStream.open(injectFile);
@ -1446,12 +1450,13 @@ void FileData::launchGame()
injectFileStream.close();
if (arguments.empty()) {
LOG(LogDebug) << "FileData::launchGame(): File empty or insufficient permissions, "
LOG(LogDebug)
<< "FileData::launchGame(): File empty or insufficient permissions, "
"nothing to inject";
}
else if (arguments.size() > 4096) {
LOG(LogWarning)
<< "FileData::launchGame(): Injection file exceeding maximum allowed size of "
LOG(LogWarning) << "FileData::launchGame(): Injection file exceeding maximum "
"allowed size of "
"4096 bytes, skipping \""
<< injectFile << "\"";
}
@ -1465,6 +1470,9 @@ void FileData::launchGame()
}
}
injectPos = command.find("%INJECT%");
}
#if defined(_WIN64)
if (escapeSpecials) {
bool foundSpecial {false};