mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 22:25:38 +00:00
(Linux) Yet another ugly hack to detect installed emulators when running as a Flatpak.
This commit is contained in:
parent
9a91e782fc
commit
7eecf6bb41
|
@ -20,6 +20,7 @@
|
||||||
#include "utils/FileSystemUtil.h"
|
#include "utils/FileSystemUtil.h"
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "utils/PlatformUtil.h"
|
||||||
#include "utils/StringUtil.h"
|
#include "utils/StringUtil.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -256,15 +257,44 @@ namespace Utils
|
||||||
return "";
|
return "";
|
||||||
#else
|
#else
|
||||||
#if defined(FLATPAK_BUILD)
|
#if defined(FLATPAK_BUILD)
|
||||||
// Ugly hack for the Flatpak build to find emulators installed as Flatpaks and Snaps.
|
// Ugly hack to compensate for the Flatpak sandbox restrictions. We traverse
|
||||||
// Note that due to limitations of this package format anything installed under /usr
|
// this hardcoded list of paths and use the "which" command to check outside the
|
||||||
// and similar system directories will not be possible to launch as they are shadowed
|
// sandbox if the emulator binary exists.
|
||||||
// by the Flatpak sandbox directories. Therefore they are excluded here.
|
std::string pathVariable {"/var/lib/flatpak/exports/bin:/usr/bin:/usr/local/"
|
||||||
std::string pathVariable {
|
"bin:/usr/local/sbin:/usr/sbin:/sbin:/bin:/usr/games:/usr/"
|
||||||
"/var/lib/flatpak/exports/bin:/snap/bin:/var/lib/snapd/snap/bin"};
|
"local/games:/snap/bin:/var/lib/snapd/snap/bin"};
|
||||||
|
|
||||||
|
std::vector<std::string> pathList {
|
||||||
|
Utils::String::delimitedStringToVector(pathVariable, ":")};
|
||||||
|
|
||||||
|
// Using a temporary file is the only viable solution I've found to communicate
|
||||||
|
// between the sandbox and the outside world.
|
||||||
|
std::string tempFile {Utils::FileSystem::getHomePath() + "/.emulationstation/" +
|
||||||
|
".flatpak_emulator_binary_path.tmp"};
|
||||||
|
|
||||||
|
std::string emulatorPath;
|
||||||
|
|
||||||
|
for (auto it = pathList.cbegin(); it != pathList.cend(); ++it) {
|
||||||
|
Utils::Platform::runSystemCommand("flatpak-spawn --host which " + *it + "/" +
|
||||||
|
executable + " > " + tempFile);
|
||||||
|
std::ifstream tempFileStream;
|
||||||
|
tempFileStream.open(tempFile);
|
||||||
|
getline(tempFileStream, emulatorPath);
|
||||||
|
tempFileStream.close();
|
||||||
|
|
||||||
|
if (emulatorPath != "") {
|
||||||
|
emulatorPath = getParent(emulatorPath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists(tempFile))
|
||||||
|
removeFile(tempFile);
|
||||||
|
|
||||||
|
return emulatorPath;
|
||||||
#else
|
#else
|
||||||
std::string pathVariable {std::string(getenv("PATH"))};
|
std::string pathVariable {std::string(getenv("PATH"))};
|
||||||
#endif
|
|
||||||
std::vector<std::string> pathList {
|
std::vector<std::string> pathList {
|
||||||
Utils::String::delimitedStringToVector(pathVariable, ":")};
|
Utils::String::delimitedStringToVector(pathVariable, ":")};
|
||||||
|
|
||||||
|
@ -277,6 +307,7 @@ namespace Utils
|
||||||
return it->c_str();
|
return it->c_str();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue