mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 14:49:04 +00:00
feat: refactor getting end paths for xr services related .so files
This commit is contained in:
parent
39d47f2109
commit
da1b38e6eb
2 changed files with 20 additions and 32 deletions
|
@ -1,35 +1,12 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||||
paths::{get_backup_dir, SYSTEM_PREFIX},
|
paths::{get_backup_dir, SYSTEM_PREFIX},
|
||||||
profile::{Profile, XRServiceType},
|
profile::Profile,
|
||||||
xdg::XDG,
|
xdg::XDG,
|
||||||
};
|
};
|
||||||
use serde::{ser::Error, Deserialize, Serialize};
|
use serde::{ser::Error, Deserialize, Serialize};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
struct RuntimePathInfo {
|
|
||||||
libopenxr_path: &'static str,
|
|
||||||
libmonado_path: Option<&'static str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RuntimePathInfo {
|
|
||||||
const RUNTIME_PATH_INFO: [RuntimePathInfo; 2] = [
|
|
||||||
RuntimePathInfo {
|
|
||||||
libopenxr_path: "libopenxr_monado.so",
|
|
||||||
libmonado_path: Some("libmonado.so"),
|
|
||||||
},
|
|
||||||
RuntimePathInfo {
|
|
||||||
libopenxr_path: "wivrn/libopenxr_wivrn.so",
|
|
||||||
libmonado_path: Some("wivrn/libmonado.so"),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
fn get_for(xr_service_type: XRServiceType) -> Self {
|
|
||||||
Self::RUNTIME_PATH_INFO[xr_service_type as usize]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct ActiveRuntimeInnerRuntime {
|
pub struct ActiveRuntimeInnerRuntime {
|
||||||
#[serde(rename = "VALVE_runtime_is_steamvr")]
|
#[serde(rename = "VALVE_runtime_is_steamvr")]
|
||||||
|
@ -123,8 +100,6 @@ pub fn set_current_active_runtime_to_steam() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_profile_active_runtime(profile: &Profile) -> anyhow::Result<ActiveRuntime> {
|
pub fn build_profile_active_runtime(profile: &Profile) -> anyhow::Result<ActiveRuntime> {
|
||||||
let info = RuntimePathInfo::get_for(profile.xrservice_type.clone());
|
|
||||||
|
|
||||||
let path_to = |end_path: &str| {
|
let path_to = |end_path: &str| {
|
||||||
["lib", "lib64"].iter().find_map(|lib| {
|
["lib", "lib64"].iter().find_map(|lib| {
|
||||||
let p = profile.prefix.clone().join(lib).join(end_path);
|
let p = profile.prefix.clone().join(lib).join(end_path);
|
||||||
|
@ -136,19 +111,18 @@ pub fn build_profile_active_runtime(profile: &Profile) -> anyhow::Result<ActiveR
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(oxr_so) = path_to(info.libopenxr_path) else {
|
let libopenxr_end_path = profile.xrservice_type.libopenxr_path();
|
||||||
anyhow::bail!("Could not find path to {}!", info.libopenxr_path);
|
let Some(libopenxr_path) = path_to(libopenxr_end_path) else {
|
||||||
|
anyhow::bail!("Could not find path to {}!", libopenxr_end_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
let mnd_so = info.libmonado_path.and_then(path_to);
|
|
||||||
|
|
||||||
Ok(ActiveRuntime {
|
Ok(ActiveRuntime {
|
||||||
file_format_version: "1.0.0".into(),
|
file_format_version: "1.0.0".into(),
|
||||||
runtime: ActiveRuntimeInnerRuntime {
|
runtime: ActiveRuntimeInnerRuntime {
|
||||||
name: None,
|
name: None,
|
||||||
valve_runtime_is_steamvr: None,
|
valve_runtime_is_steamvr: None,
|
||||||
libmonado_path: mnd_so,
|
libmonado_path: path_to(profile.xrservice_type.libmonado_path()),
|
||||||
library_path: oxr_so,
|
library_path: libopenxr_path,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,20 @@ impl XRServiceType {
|
||||||
_ => panic!("XRServiceType index out of bounds"),
|
_ => panic!("XRServiceType index out of bounds"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn libopenxr_path(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Monado => "libopenxr_monado.so",
|
||||||
|
Self::Wivrn => "wivrn/libopenxr_wivrn.so"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn libmonado_path(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Monado => "libmonado.so",
|
||||||
|
Self::Wivrn => "wivrn/libmonado.so"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for XRServiceType {
|
impl Display for XRServiceType {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue