From 3cad68be13f0126427f63d73507d227f5278a4c3 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 10 Jul 2020 19:53:33 +0200 Subject: [PATCH] Added %EMUPATH% logic for Unix. --- es-app/src/FileData.cpp | 4 +++- es-core/src/utils/FileSystemUtil.cpp | 20 ++++++++++++++++++++ es-core/src/utils/FileSystemUtil.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index f6df6cc25..1f4c777ff 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -24,6 +24,7 @@ #include "Window.h" #include +#include FileData::FileData( FileType type, @@ -516,7 +517,8 @@ void FileData::launchGame(Window* window) } } #else - // TODO for Unix. + std::string exePath = Utils::FileSystem::getPathToBinary(emuExecutable); + command = Utils::String::replace(command, "%EMUPATH%", exePath); #endif } diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index c51ff22d9..43ec6859a 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -176,6 +176,26 @@ namespace Utils #endif } + std::string getPathToBinary(const std::string& executable) + { + #ifdef _WIN64 + return ""; + #else + std::string pathVariable = std::string(getenv("PATH")); + std::vector pathList = + Utils::String::delimitedStringToVector(pathVariable, ":"); + + std::string pathTest; + + for (auto it = pathList.cbegin(); it != pathList.cend(); it++) { + pathTest = it->c_str() + ("/" + executable); + if (exists(pathTest)) + return it->c_str(); + } + return ""; + #endif + } + void setExePath(const std::string& _path) { constexpr int path_max = 32767; diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index 3958e2e16..0ed6aa91a 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -25,6 +25,7 @@ namespace Utils void setHomePath(const std::string& _path); std::string getHomePath(); std::string getCWDPath(); + std::string getPathToBinary(const std::string& executable); void setExePath(const std::string& _path); std::string getExePath(); std::string getProgramDataPath();