diff --git a/src/file_builders/active_runtime_json.rs b/src/file_builders/active_runtime_json.rs index ad1e17a..4a8dd5d 100644 --- a/src/file_builders/active_runtime_json.rs +++ b/src/file_builders/active_runtime_json.rs @@ -100,20 +100,11 @@ pub fn set_current_active_runtime_to_steam() -> anyhow::Result<()> { } pub fn build_profile_active_runtime(profile: &Profile) -> anyhow::Result { - let path_to = |end_path: &str| { - ["lib", "lib64"].iter().find_map(|lib| { - let p = profile.prefix.clone().join(lib).join(end_path); - if p.exists() { - Some(p) - } else { - None - } - }) - }; - - let libopenxr_end_path = profile.xrservice_type.libopenxr_path(); - let Some(libopenxr_path) = path_to(libopenxr_end_path) else { - anyhow::bail!("Could not find path to {}!", libopenxr_end_path); + let Some(libopenxr_path) = profile.libopenxr_so() else { + anyhow::bail!( + "Could not find path to {}!", + profile.xrservice_type.libopenxr_path() + ); }; Ok(ActiveRuntime { @@ -121,7 +112,7 @@ pub fn build_profile_active_runtime(profile: &Profile) -> anyhow::Result &'static str { match self { Self::Monado => "libopenxr_monado.so", @@ -55,6 +56,7 @@ impl XRServiceType { } } + /// relative path from the prefix lib dir of the libmonado shared object pub fn libmonado_path(&self) -> &'static str { match self { Self::Monado => "libmonado.so", @@ -506,22 +508,25 @@ impl Profile { } pub fn can_start(&self) -> bool { - Path::new(&self.xrservice_binary()).is_file() + self.xrservice_binary().is_file() } + /// absolute path to a given shared object in the profile prefix + pub fn find_so(&self, rel_path: &str) -> Option { + ["lib", "lib64"] + .into_iter() + .map(|lib| self.prefix.join(lib).join(rel_path)) + .find(|path| path.is_file()) + } + + /// absolute path to the libmonado shared object pub fn libmonado_so(&self) -> Option { - let paths = [ - self.prefix.join("lib/libmonado.so"), - self.prefix.join("lib64/libmonado.so"), - self.prefix.join("lib/wivrn/libmonado.so"), - self.prefix.join("lib64/wivrn/libmonado.so"), - ]; - - paths.into_iter().find(|path| path.is_file()) + self.find_so(self.xrservice_type.libmonado_path()) } - pub fn has_libmonado(&self) -> bool { - self.libmonado_so().is_some() + /// absolute path to the libopenxr shared object + pub fn libopenxr_so(&self) -> Option { + self.find_so(self.xrservice_type.libopenxr_path()) } }