More accurate flatpak info parser

This commit is contained in:
Patrick Nicolas
2024-11-07 19:41:35 +01:00
parent 7983745317
commit 8400a03fde
7 changed files with 20 additions and 8 deletions
+7 -2
View File
@@ -29,14 +29,19 @@ bool wivrn::is_flatpak()
return std::filesystem::exists(info_path); return std::filesystem::exists(info_path);
} }
std::optional<std::string> wivrn::flatpak_key(std::string key) std::optional<std::string> wivrn::flatpak_key(std::string section, std::string key)
{ {
section = "[" + section + "]";
key += "="; key += "=";
std::string line; std::string line;
std::ifstream info(info_path); std::ifstream info(info_path);
bool in_section = false;
while (std::getline(info, line)) while (std::getline(info, line))
{ {
if (line.starts_with(key)) if (line.starts_with("["))
in_section = section == line;
if (in_section and line.starts_with(key))
return line.substr(key.size()); return line.substr(key.size());
} }
return {}; return {};
+8 -1
View File
@@ -24,6 +24,13 @@
namespace wivrn namespace wivrn
{ {
namespace flatpak::section
{
inline const char * instance = "Instance";
inline const char * session_bus_policy = "Session Bus Policy";
}; // namespace flatpak::section
bool is_flatpak(); bool is_flatpak();
std::optional<std::string> flatpak_key(std::string key); std::optional<std::string> flatpak_key(std::string section, std::string key);
} // namespace wivrn } // namespace wivrn
+1 -1
View File
@@ -33,7 +33,7 @@ std::unique_ptr<QProcess> escape_sandbox(const std::string & executable, Args &&
auto process = std::make_unique<QProcess>(); auto process = std::make_unique<QProcess>();
QStringList args; QStringList args;
if (wivrn::flatpak_key("org.freedesktop.Flatpak") == "talk") if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk")
{ {
process->setProgram("flatpak-spawn"); process->setProgram("flatpak-spawn");
args.push_back("--host"); args.push_back("--host");
+1 -1
View File
@@ -35,7 +35,7 @@ std::string read_vr_manifest()
std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"; std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest";
if (wivrn::flatpak_key("org.freedesktop.Flatpak") == "talk") if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk")
{ {
QProcess flatpak_spawn; QProcess flatpak_spawn;
flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)});
+1 -1
View File
@@ -31,7 +31,7 @@ std::filesystem::path active_runtime::manifest_path()
{ {
const std::filesystem::path install_location = "share/openxr/1/openxr_wivrn.json"; const std::filesystem::path install_location = "share/openxr/1/openxr_wivrn.json";
// Check if in a flatpak // Check if in a flatpak
if (auto path = flatpak_key("app-path")) if (auto path = flatpak_key(flatpak::section::instance, "app-path"))
return *path / install_location.relative_path(); return *path / install_location.relative_path();
// Check if running from build directory // Check if running from build directory
+1 -1
View File
@@ -133,7 +133,7 @@ void display_child_status(int wstatus, const std::string & name)
static std::filesystem::path flatpak_app_path() static std::filesystem::path flatpak_app_path()
{ {
if (auto value = flatpak_key("app-path")) if (auto value = flatpak_key(flatpak::section::instance, "app-path"))
{ {
std::filesystem::path path = *value; std::filesystem::path path = *value;
while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn") while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn")
+1 -1
View File
@@ -235,7 +235,7 @@ int wivrn::exec_application(configuration config)
std::string executable; std::string executable;
std::vector<std::string> args; std::vector<std::string> args;
if (flatpak_key("org.freedesktop.Flatpak") == "talk") if (flatpak_key(flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk")
{ {
executable = "flatpak-spawn"; executable = "flatpak-spawn";
args.push_back("flatpak-spawn"); args.push_back("flatpak-spawn");