From e8e74659354bb349b8dc4ed024a49f96eff78bb4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 19 May 2022 23:36:12 +0200 Subject: [PATCH] Added a %GAMEDIR% variable that expands to the game directory. Also fixed an issue where the %BASENAME% variable would not work with directories interpreted as files. --- es-app/src/FileData.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 9b7e6fd42..4b151b7a7 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -871,6 +871,7 @@ void FileData::launchGame() std::string commandRaw {command}; std::string romPath {Utils::FileSystem::getEscapedPath(mPath)}; + std::string baseName {Utils::FileSystem::getStem(mPath)}; // For the special case where a directory has a supported file extension and is therefore // interpreted as a file, check if there is a matching filename inside the directory. @@ -880,12 +881,12 @@ void FileData::launchGame() if (Utils::FileSystem::getFileName(file) == Utils::FileSystem::getFileName(mPath) && (Utils::FileSystem::isRegularFile(file) || Utils::FileSystem::isSymlink(file))) { romPath = Utils::FileSystem::getEscapedPath(file); + baseName = baseName.substr(0, baseName.find(".")); break; } } } - const std::string baseName {Utils::FileSystem::getStem(mPath)}; const std::string romRaw {Utils::FileSystem::getPreferredPath(mPath)}; const std::string esPath {Utils::FileSystem::getExePath()}; bool runInBackground {false}; @@ -1313,11 +1314,17 @@ void FileData::launchGame() command = Utils::String::replace(command, "%EMUDIR%", Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent( Utils::String::replace(binaryPath, "\"", "")))); + command = Utils::String::replace(command, "%GAMEDIR%", + Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent( + Utils::String::replace(romPath, "\"", "")))); #else command = Utils::String::replace(command, "%ESPATH%", Utils::FileSystem::getExePath()); command = Utils::String::replace(command, "%EMUDIR%", Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent( Utils::String::replace(binaryPath, "\\", "")))); + command = Utils::String::replace(command, "%GAMEDIR%", + Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent( + Utils::String::replace(romPath, "\\", "")))); #endif // Trim any leading and trailing whitespace characters as they could cause launch issues.