mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-20 11:35:48 +00:00
Merge branch 'feat/removeOpenvrPathsHandling' into 'main'
feat: remove openvrpaths handling See merge request gabmus/envision!123
This commit is contained in:
commit
ec5dd35ac0
4 changed files with 4 additions and 184 deletions
|
@ -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;
|
||||
|
|
|
@ -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<PathBuf>,
|
||||
external_drivers: Option<Vec<String>>, // never seen it populated
|
||||
jsonid: String,
|
||||
log: Vec<PathBuf>,
|
||||
runtime: Vec<PathBuf>,
|
||||
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<OpenVrPaths> {
|
||||
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<OpenVrPaths> {
|
||||
deserialize_file(path)
|
||||
}
|
||||
|
||||
pub fn get_current_openvrpaths() -> Option<OpenVrPaths> {
|
||||
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");
|
||||
}
|
||||
}
|
13
src/main.rs
13
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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::<gtk::Window>()),
|
||||
);
|
||||
return;
|
||||
};
|
||||
self.debug_view.sender().emit(DebugViewMsg::ClearLog);
|
||||
self.xr_devices = vec![];
|
||||
{
|
||||
|
@ -312,13 +297,6 @@ impl App {
|
|||
Some(&self.app_win.clone().upcast::<gtk::Window>()),
|
||||
);
|
||||
}
|
||||
if let Err(e) = set_current_openvrpaths_to_steam() {
|
||||
alert(
|
||||
"Could not restore Steam openvrpaths",
|
||||
Some(&format!("{e}")),
|
||||
Some(&self.app_win.clone().upcast::<gtk::Window>()),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
pub fn shutdown_xrservice(&mut self) {
|
||||
|
|
Loading…
Add table
Reference in a new issue