Add null to disable OpenVR configuration

This commit is contained in:
Patrick Nicolas
2025-04-29 19:40:35 +02:00
parent 81f2617d84
commit acd35e3ebd
4 changed files with 36 additions and 16 deletions
+1 -1
View File
@@ -189,4 +189,4 @@ Provides the path to the directory of an OpenVR compatibility tool (such as Open
If unset, WiVRn will autodetect the path of such a tool as usual (see [the SteamVR guide](./steamvr.md)).
If set to an empty string, it is assumed detection failed ; the OpenVR configuration will not be modified and the pressure-vessel configuration won't be adjusted.
If set to an null, WiVRn will not manage the OpenVR configuration.
+27 -13
View File
@@ -20,6 +20,7 @@
#include "active_runtime.h"
#include "driver/configuration.h"
#include "utils/flatpak.h"
#include "utils/overloaded.h"
#include "utils/xdg_base_directory.h"
#include "wivrn_config.h"
#include <filesystem>
@@ -49,20 +50,33 @@ std::filesystem::path active_runtime::manifest_path()
std::filesystem::path active_runtime::openvr_compat_path()
{
// config can override compat path (i.e. to debug changes to OpenComposite)
std::optional<std::string> path_override = configuration::read_user_configuration().openvr_compat_path;
if (path_override.has_value())
return std::filesystem::path(path_override.value());
return std::visit(
utils::overloaded{
[](std::monostate) {
// no user configuration: return default
std::optional<std::filesystem::path> flatpak_root = flatpak_key(flatpak::section::instance, "app-path");
// flatpak default
if (flatpak_root)
return *flatpak_root / "OpenComposite";
// otherwise, prefer flatpak copy if present or otherwise try to find it on the system
if (auto path = flatpak_key(flatpak::section::instance, "app-path"))
return std::filesystem::path(*path) / "OpenComposite";
for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":")))
{
if (auto res = std::string_view(path); std::filesystem::exists(res))
return res;
}
return {};
for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":")))
{
if (std::filesystem::path res = std::string_view(path); std::filesystem::exists(res))
return res;
}
return std::filesystem::path();
},
[](const std::string & path) {
// exlicit value, use it
std::optional<std::filesystem::path> flatpak_root = flatpak_key(flatpak::section::instance, "app-path");
return flatpak_root.value_or("") / path;
},
[](std::nullptr_t) {
// explicit null, don't set any compat path
return std::filesystem::path();
},
},
configuration::read_user_configuration().openvr_compat_path);
}
static std::filesystem::path backup_name(std::filesystem::path file)
+4 -1
View File
@@ -154,7 +154,10 @@ configuration configuration::read_user_configuration()
if (auto it = json.find("openvr-compat-path"); it != json.end())
{
result.openvr_compat_path = *it;
if (it->is_null())
result.openvr_compat_path = nullptr;
else
result.openvr_compat_path = *it;
}
}
catch (const std::exception & e)
+4 -1
View File
@@ -25,6 +25,7 @@
#include <map>
#include <optional>
#include <string>
#include <variant>
#include "wivrn_packets.h"
@@ -60,7 +61,9 @@ struct configuration
std::vector<std::string> application;
bool tcp_only = false;
service_publication publication = service_publication::avahi;
std::optional<std::string> openvr_compat_path;
// monostate: default value, string: user defined, nullptr: disabled
std::variant<std::monostate, std::string, std::nullptr_t> openvr_compat_path;
static void set_config_file(const std::filesystem::path &);
static const std::filesystem::path & get_config_file();