Added a function to FileSystemUtil to return the ES-DE binary path

Also fixed an issue where the fallback to argv[0] in FileSystemUtil::setExePath() was not working correctly
This commit is contained in:
Leon Styhre 2023-07-02 23:16:39 +02:00
parent 923b6b2ed1
commit 15e5a8b305
2 changed files with 13 additions and 1 deletions

View file

@ -65,6 +65,7 @@ namespace Utils
{
static std::string homePath;
static std::string exePath;
static std::string esBinary;
StringList getDirContent(const std::string& path, const bool recursive)
{
@ -326,11 +327,15 @@ namespace Utils
if (readlink("/proc/self/exe", &result[0], pathMax) != -1)
exePath = result;
#endif
exePath.erase(std::find(exePath.begin(), exePath.end(), '\0'), exePath.end());
esBinary = exePath;
exePath = getCanonicalPath(exePath);
// Fallback to argv[0] if everything else fails.
if (exePath.empty())
if (exePath.empty()) {
esBinary = path;
exePath = getCanonicalPath(path);
}
if (isRegularFile(exePath))
exePath = getParent(exePath);
}
@ -341,6 +346,12 @@ namespace Utils
return exePath;
}
std::string getEsBinary()
{
// Return the absolute path to the ES-DE binary.
return esBinary;
}
std::string getProgramDataPath()
{
#if defined(__unix__)

View file

@ -29,6 +29,7 @@ namespace Utils
std::string getPathToBinary(const std::string& executable);
void setExePath(const std::string& path);
std::string getExePath();
std::string getEsBinary();
std::string getProgramDataPath();
std::string getPreferredPath(const std::string& path);
std::string getGenericPath(const std::string& path);