fix: get steamvr bin dir by parsing libraryfolders.vdf
Some checks are pending
/ cargo-fmtcheck (push) Waiting to run
/ cargo-clippy (push) Waiting to run
/ cargo-test (push) Waiting to run
/ appimage (push) Waiting to run

fixes #171
This commit is contained in:
Gabriele Musco 2025-01-02 11:42:43 +01:00
commit e5a59ebf62
2 changed files with 69 additions and 49 deletions

View file

@ -1,4 +1,6 @@
use crate::{constants::CMD_NAME, xdg::XDG}; use anyhow::bail;
use crate::{constants::CMD_NAME, util::steam_library_folder::SteamLibraryFolder, xdg::XDG};
use std::{ use std::{
env, env,
fs::create_dir_all, fs::create_dir_all,
@ -83,9 +85,24 @@ pub fn get_exec_prefix() -> PathBuf {
.into() .into()
} }
pub fn get_steamvr_bin_dir_path() -> PathBuf { const STEAMVR_STEAM_APPID: u32 = 250820;
XDG.get_data_home()
.join("Steam/steamapps/common/SteamVR/bin/linux64") fn get_steamvr_base_dir() -> anyhow::Result<PathBuf> {
SteamLibraryFolder::get_folders()?
.into_iter()
.find(|(_, lf)| lf.apps.contains_key(&STEAMVR_STEAM_APPID))
.map(|(_, lf)| PathBuf::from(lf.path))
.ok_or(anyhow::Error::msg(
"Could not find SteamVR in Steam libraryfolders.vdf",
))
}
pub fn get_steamvr_bin_dir_path() -> anyhow::Result<PathBuf> {
let res = get_steamvr_base_dir()?.join("bin/linux64");
if !res.is_dir() {
bail!("SteamVR bin dir `{}` does not exist", res.to_string_lossy());
}
Ok(res)
} }
pub fn get_plugins_dir() -> PathBuf { pub fn get_plugins_dir() -> PathBuf {

View file

@ -10,7 +10,6 @@ use relm4::{
}; };
use std::{ use std::{
collections::{HashMap, VecDeque}, collections::{HashMap, VecDeque},
path::Path,
thread::sleep, thread::sleep,
time::Duration, time::Duration,
}; };
@ -145,12 +144,14 @@ impl SimpleComponent for SteamVrCalibrationBox {
} }
Self::Input::RunCalibration => { Self::Input::RunCalibration => {
self.set_calibration_result(None); self.set_calibration_result(None);
let steamvr_bin_dir = get_steamvr_bin_dir_path().to_string_lossy().to_string(); match get_steamvr_bin_dir_path() {
if !Path::new(&steamvr_bin_dir).is_dir() { Err(e) => {
error!("could not get SteamVR bin dir: {e}");
self.set_calibration_success(false); self.set_calibration_success(false);
self.set_calibration_result(Some("SteamVR not found".into())); self.set_calibration_result(Some("SteamVR not found".into()));
return;
} }
Ok(bin_dir_p) => {
let steamvr_bin_dir = bin_dir_p.to_string_lossy().to_string();
let mut env: HashMap<String, String> = HashMap::new(); let mut env: HashMap<String, String> = HashMap::new();
env.insert("LD_LIBRARY_PATH".into(), steamvr_bin_dir.clone()); env.insert("LD_LIBRARY_PATH".into(), steamvr_bin_dir.clone());
let vrcmd = format!("{steamvr_bin_dir}/vrcmd"); let vrcmd = format!("{steamvr_bin_dir}/vrcmd");
@ -191,6 +192,8 @@ impl SimpleComponent for SteamVrCalibrationBox {
self.server_worker = Some(server_worker); self.server_worker = Some(server_worker);
self.calibration_worker = Some(cal_worker); self.calibration_worker = Some(cal_worker);
} }
};
}
Self::Input::OnServerWorkerExit(code) => { Self::Input::OnServerWorkerExit(code) => {
if code != 0 { if code != 0 {
error!("calibration exited with code {code}"); error!("calibration exited with code {code}");