diff --git a/src/file_builders/mod.rs b/src/file_builders/mod.rs index 33c9829..02faad6 100644 --- a/src/file_builders/mod.rs +++ b/src/file_builders/mod.rs @@ -1,6 +1,5 @@ pub mod active_runtime_json; pub mod monado_autorun; -pub mod openvrpaths_vrpath; pub mod wayvr_dashboard_config; pub mod wivrn_config; pub mod wivrn_encoder_presets; diff --git a/src/file_builders/openvrpaths_vrpath.rs b/src/file_builders/openvrpaths_vrpath.rs deleted file mode 100644 index 7bd431b..0000000 --- a/src/file_builders/openvrpaths_vrpath.rs +++ /dev/null @@ -1,146 +0,0 @@ -use crate::{ - paths::get_backup_dir, - profile::Profile, - util::file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly}, - xdg::XDG, -}; -use serde::{ser::Error, Deserialize, Serialize}; -use std::path::{Path, PathBuf}; - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct OpenVrPaths { - config: Vec, - external_drivers: Option>, // never seen it populated - jsonid: String, - log: Vec, - runtime: Vec, - version: u32, -} - -pub fn get_openvr_conf_dir() -> PathBuf { - XDG.get_config_home().join("openvr") -} - -fn get_openvrpaths_vrpath_path() -> PathBuf { - get_openvr_conf_dir().join("openvrpaths.vrpath") -} - -pub fn is_steam(ovr_paths: &OpenVrPaths) -> bool { - ovr_paths.runtime.iter().any(|rt| { - rt.to_string_lossy() - .to_lowercase() - .ends_with("/steam/steamapps/common/steamvr") - }) -} - -fn get_backup_steam_openvrpaths_path() -> PathBuf { - get_backup_dir().join("openvrpaths.vrpath.steam.bak") -} - -fn get_backed_up_steam_openvrpaths() -> Option { - get_openvrpaths_from_path(&get_backup_steam_openvrpaths_path()) -} - -fn backup_steam_openvrpaths() { - if let Some(openvrpaths) = get_current_openvrpaths() { - if is_steam(&openvrpaths) { - copy_file( - &get_openvrpaths_vrpath_path(), - &get_backup_steam_openvrpaths_path(), - ); - } - } -} - -fn get_openvrpaths_from_path(path: &Path) -> Option { - deserialize_file(path) -} - -pub fn get_current_openvrpaths() -> Option { - get_openvrpaths_from_path(&get_openvrpaths_vrpath_path()) -} - -fn dump_openvrpaths_to_path(ovr_paths: &OpenVrPaths, path: &Path) -> Result<(), serde_json::Error> { - let writer = get_writer(path).map_err(serde_json::Error::custom)?; - serde_json::to_writer_pretty(writer, ovr_paths) -} - -pub fn dump_current_openvrpaths(ovr_paths: &OpenVrPaths) -> Result<(), serde_json::Error> { - dump_openvrpaths_to_path(ovr_paths, &get_openvrpaths_vrpath_path()) -} - -fn build_steam_openvrpaths() -> OpenVrPaths { - if let Some(backup) = get_backed_up_steam_openvrpaths() { - return backup; - } - let datadir = XDG.get_data_home(); - OpenVrPaths { - config: vec![datadir.join("Steam/config")], - external_drivers: None, - jsonid: "vrpathreg".into(), - log: vec![datadir.join("Steam/logs")], - runtime: vec![datadir.join("Steam/steamapps/common/SteamVR")], - version: 1, - } -} - -pub fn set_current_openvrpaths_to_steam() -> anyhow::Result<()> { - set_file_readonly(&get_openvrpaths_vrpath_path(), false)?; - dump_current_openvrpaths(&build_steam_openvrpaths())?; - Ok(()) -} - -pub fn build_profile_openvrpaths(profile: &Profile) -> OpenVrPaths { - let datadir = XDG.get_data_home(); - OpenVrPaths { - config: vec![datadir.join("Steam/config")], - external_drivers: None, - jsonid: "vrpathreg".into(), - log: vec![datadir.join("Steam/logs")], - runtime: vec![profile.ovr_comp.runtime_dir()], - version: 1, - } -} - -pub fn set_current_openvrpaths_to_profile(profile: &Profile) -> anyhow::Result<()> { - let dest = get_openvrpaths_vrpath_path(); - set_file_readonly(&dest, false)?; - backup_steam_openvrpaths(); - dump_current_openvrpaths(&build_profile_openvrpaths(profile))?; - set_file_readonly(&dest, true)?; - Ok(()) -} - -#[cfg(test)] -mod tests { - use std::path::Path; - - use super::{dump_openvrpaths_to_path, get_openvrpaths_from_path, OpenVrPaths}; - - #[test] - fn can_read_openvrpaths_vrpath_steamvr() { - let ovrp = get_openvrpaths_from_path(Path::new("./test/files/openvrpaths.vrpath")).unwrap(); - assert_eq!(ovrp.config.len(), 1); - assert_eq!( - ovrp.config.first().unwrap(), - &Path::new("/home/user/.local/share/Steam/config") - ); - assert_eq!(ovrp.external_drivers, None); - assert_eq!(ovrp.jsonid, "vrpathreg"); - assert_eq!(ovrp.version, 1); - } - - #[test] - fn can_dump_openvrpaths_vrpath() { - let ovrp = OpenVrPaths { - config: vec!["/home/user/.local/share/Steam/config".into()], - external_drivers: None, - jsonid: "vrpathreg".into(), - log: vec!["/home/user/.local/share/Steam/logs".into()], - runtime: vec!["/home/user/.local/share/Steam/steamapps/common/SteamVR".into()], - version: 1, - }; - dump_openvrpaths_to_path(&ovrp, Path::new("./target/testout/openvrpaths.vrpath")) - .expect("could not dump openvrpaths to path"); - } -} diff --git a/src/main.rs b/src/main.rs index bb72425..82638f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,6 @@ use anyhow::Result; use constants::{resources, APP_ID, APP_NAME, GETTEXT_PACKAGE, LOCALE_DIR, RESOURCES_BASE_PATH}; -use file_builders::{ - active_runtime_json::restore_active_runtime_backup, - openvrpaths_vrpath::{get_current_openvrpaths, set_current_openvrpaths_to_steam}, -}; +use file_builders::active_runtime_json::restore_active_runtime_backup; use gettextrs::LocaleCategory; use paths::get_logs_dir; use relm4::{ @@ -52,17 +49,9 @@ pub mod xdg; pub mod xr_devices; fn restore_steam_xr_files() { - let openvrpaths = get_current_openvrpaths(); if let Err(e) = restore_active_runtime_backup() { warn!("failed to restore active runtime to steam: {e}"); } - if let Some(ovrp) = openvrpaths { - if !file_builders::openvrpaths_vrpath::is_steam(&ovrp) { - if let Err(e) = set_current_openvrpaths_to_steam() { - warn!("failed to restore openvrpaths to steam: {e}"); - } - } - } restore_runtime_entrypoint(); } diff --git a/src/ui/app.rs b/src/ui/app.rs index 9910d2d..e1a4196 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -26,14 +26,9 @@ use crate::{ config::{Config, PluginConfig}, constants::APP_NAME, depcheck::common::dep_pkexec, - file_builders::{ - active_runtime_json::{ - remove_current_active_runtime, restore_active_runtime_backup, - set_current_active_runtime_to_profile, - }, - openvrpaths_vrpath::{ - set_current_openvrpaths_to_profile, set_current_openvrpaths_to_steam, - }, + file_builders::active_runtime_json::{ + remove_current_active_runtime, restore_active_runtime_backup, + set_current_active_runtime_to_profile, }, linux_distro::LinuxDistro, openxr_prober::is_openxr_ready, @@ -197,16 +192,6 @@ impl App { ); return; } - if let Err(e) = set_current_openvrpaths_to_profile(&prof) { - alert( - "Failed to start XR Service", - Some(&format!( - "Error setting current openvrpaths file to profile: {e}" - )), - Some(&self.app_win.clone().upcast::()), - ); - return; - }; self.debug_view.sender().emit(DebugViewMsg::ClearLog); self.xr_devices = vec![]; { @@ -312,13 +297,6 @@ impl App { Some(&self.app_win.clone().upcast::()), ); } - if let Err(e) = set_current_openvrpaths_to_steam() { - alert( - "Could not restore Steam openvrpaths", - Some(&format!("{e}")), - Some(&self.app_win.clone().upcast::()), - ); - }; } pub fn shutdown_xrservice(&mut self) {