From 472a973f66fe60e0f941b1877a82e2eab8249587 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 10 Jul 2020 20:58:53 +0200 Subject: [PATCH] Added %ESPATH% variable support and fixed some other minor issues with the launch command. --- INSTALL.md | 8 +++++++- es-app/src/FileData.cpp | 22 ++++++++++++++-------- es-app/src/SystemData.cpp | 7 ------- es-app/src/guis/GuiMetaDataEd.cpp | 2 +- es-core/src/utils/FileSystemUtil.cpp | 9 +++++++++ es-core/src/utils/FileSystemUtil.h | 1 + 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index fbc895f7f..de188040b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -512,7 +512,11 @@ Here's an overview of the file layout: configuration as the %EMUPATH% will expand to the path of the emulator binary, which will of course also include the spaces. --> "C:\My Games\RetroArch\retroarch.exe" -L "%EMUPATH%\cores\snes9x_libretro.dll" %ROM% - + "%ESPATH%\..\RetroArch\retroarch.exe" -L "%ESPATH%\..\RetroArch\cores\snes9x_libretro.dll" %ROM% + + snes @@ -533,6 +537,8 @@ The following variables are expanded by ES for the `command` tag: `%EMUPATH%` - Replaced with the path to the emulator binary. This is expanded either using the PATH environmental variable of the operating system, or if an absolute emulator path is defined, this will be used instead. This variable is mostly useful to define the emulator core path for Windows, as this operating system does not have a standardized program installation directory structure. +`%ESPATH%` - Replaced with the path to the EmulationStation binary. Mostly useful for portable emulator installations, for example on a USB memory stick. + For the `path` tag, the following variable is expanded by ES: `%ROMPATH%` - Replaced with the path defined for the setting ROMDirectory in `es_settings.cfg`. diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 1f4c777ff..c21168461 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -24,7 +24,6 @@ #include "Window.h" #include -#include FileData::FileData( FileType type, @@ -110,12 +109,9 @@ const std::string FileData::getROMDirectory() } else { romDirPath = romDirSetting; + // Expand home path if ~ is used. + romDirPath = Utils::FileSystem::expandHomePath(romDirPath); - // Expand home symbol if the path starts with ~ - if (romDirPath[0] == '~') { - romDirPath.erase(0, 1); - romDirPath.insert(0, Utils::FileSystem::getHomePath()); - } if (romDirPath.back() != '/') romDirPath = romDirPath + "/"; } @@ -446,7 +442,7 @@ void FileData::launchGame(Window* window) std::string command = ""; - // Check if there is a launch string override for the game + // Check if there is a launch command override for the game // and the corresponding option to use it has been set. if (Settings::getInstance()->getBool("LaunchCommandOverride") && !metadata.get("launchcommand").empty()) @@ -464,6 +460,10 @@ void FileData::launchGame(Window* window) command = Utils::String::replace(command, "%ROM%", rom); command = Utils::String::replace(command, "%BASENAME%", basename); command = Utils::String::replace(command, "%ROM_RAW%", rom_raw); + command = Utils::String::replace(command, "%ESPATH%", emupath); + + // Expand home path if ~ is used. + command = Utils::FileSystem::expandHomePath(command); #ifdef _WIN64 std::wstring commandWide = Utils::String::stringToWideString(command); @@ -517,7 +517,13 @@ void FileData::launchGame(Window* window) } } #else - std::string exePath = Utils::FileSystem::getPathToBinary(emuExecutable); + std::string exePath; + if (Utils::FileSystem::isRegularFile(emuExecutable) || + Utils::FileSystem::isSymlink(emuExecutable)) + exePath = Utils::FileSystem::getParent(emuExecutable); + else + exePath = Utils::FileSystem::getPathToBinary(emuExecutable); + command = Utils::String::replace(command, "%EMUPATH%", exePath); #endif } diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index e7fca0e47..d3457a1e2 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -307,13 +307,6 @@ bool SystemData::loadConfig() // Convert path to generic directory seperators. path = Utils::FileSystem::getGenericPath(path); - // Expand home symbol if the startpath contains ~ - if (path[0] == '~') - { - path.erase(0, 1); - path.insert(0, Utils::FileSystem::getHomePath()); - } - // Create the system runtime environment data. SystemEnvironmentData* envData = new SystemEnvironmentData; envData->mStartPath = path; diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index f9cb71738..4aa88db67 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -75,7 +75,7 @@ GuiMetaDataEd::GuiMetaDataEd( if (iter->isStatistic) continue; - // Don't show the launch string override entry if this option has been disabled. + // Don't show the launch command override entry if this option has been disabled. if (!Settings::getInstance()->getBool("LaunchCommandOverride") && iter->type == MD_LAUNCHCOMMAND) { ed = std::make_shared(window, "", Font::get(FONT_SIZE_SMALL, diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 43ec6859a..8d195650b 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -438,6 +438,15 @@ namespace Utils return "."; } + std::string expandHomePath(const std::string& _path) + { + // Expand home path if ~ is used. + std::string expandedPath = _path; + + expandedPath = Utils::String::replace(_path, "~", Utils::FileSystem::getHomePath()); + return expandedPath; + } + std::string resolveRelativePath(const std::string& _path, const std::string& _relativeTo, const bool _allowHome) { diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index 0ed6aa91a..be9739225 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -39,6 +39,7 @@ namespace Utils std::string getFileName(const std::string& _path); std::string getStem(const std::string& _path); std::string getExtension(const std::string& _path); + std::string expandHomePath(const std::string& _path); std::string resolveRelativePath(const std::string& _path, const std::string& _relativeTo, const bool _allowHome); std::string createRelativePath(const std::string& _path,