From bdebe0133c0fc9e1ded605b6448720fb022bafdd Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 3 Jun 2024 20:45:26 +0200 Subject: [PATCH] Improved the %ROM% and %INJECT% variable logic and added support for Windows --- es-app/src/FileData.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 4b36003ad..b818d19f7 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -1574,19 +1574,30 @@ void FileData::launchGame() injectFile = Utils::String::replace(injectFile, "\\", "/"); 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; + if (injectFile == "%ROM%") { + injectFile = Utils::String::replace(injectFile, "%ROM%", + Utils::String::replace(romRaw, "\"", "")); + } + else { + if (injectFile.size() < 3 || !(injectFile[1] == ':' && injectFile[2] == '/')) + 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, "\\", "")); - injectFile = Utils::String::replace(injectFile, "%ROM%", romRaw); - if (injectFile.front() != '/') - injectFile = - Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) + "/" + - injectFile; + if (injectFile == "%ROM%") { + injectFile = Utils::String::replace(injectFile, "%ROM%", + Utils::String::replace(romRaw, "\\", "")); + } + else { + if (injectFile.front() != '/') + injectFile = + Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) + + "/" + injectFile; + } #endif if (Utils::FileSystem::isRegularFile(injectFile) || Utils::FileSystem::isSymlink(injectFile)) {