From da1b38e6eba9c022cc3ba2c22ccefa7df82812dc Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Fri, 9 Aug 2024 22:11:04 +0200 Subject: [PATCH] feat: refactor getting end paths for xr services related .so files --- src/file_builders/active_runtime_json.rs | 38 ++++-------------------- src/profile.rs | 14 +++++++++ 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/file_builders/active_runtime_json.rs b/src/file_builders/active_runtime_json.rs index 1b100c6..ad1e17a 100644 --- a/src/file_builders/active_runtime_json.rs +++ b/src/file_builders/active_runtime_json.rs @@ -1,35 +1,12 @@ use crate::{ file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly}, paths::{get_backup_dir, SYSTEM_PREFIX}, - profile::{Profile, XRServiceType}, + profile::Profile, xdg::XDG, }; use serde::{ser::Error, Deserialize, Serialize}; 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)] pub struct ActiveRuntimeInnerRuntime { #[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 { - let info = RuntimePathInfo::get_for(profile.xrservice_type.clone()); - let path_to = |end_path: &str| { ["lib", "lib64"].iter().find_map(|lib| { let p = profile.prefix.clone().join(lib).join(end_path); @@ -136,19 +111,18 @@ pub fn build_profile_active_runtime(profile: &Profile) -> anyhow::Result 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 {