Added %EMUPATH% logic for Unix.

This commit is contained in:
Leon Styhre 2020-07-10 19:53:33 +02:00
parent 31da561695
commit 3cad68be13
3 changed files with 24 additions and 1 deletions

View file

@ -24,6 +24,7 @@
#include "Window.h"
#include <assert.h>
#include <filesystem>
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
}

View file

@ -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<std::string> 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;

View file

@ -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();