patches for envision
1use anyhow::bail;
2use lazy_static::lazy_static;
3
4use crate::{
5 constants::CMD_NAME,
6 util::steam_library_folder::SteamLibraryFolder,
7 xdg::{XDG_CACHE_HOME, XDG_CONFIG_HOME, XDG_DATA_HOME},
8};
9use std::{
10 env,
11 fs::create_dir_all,
12 path::{Path, PathBuf},
13};
14
15pub fn data_ovr_comp_path() -> PathBuf {
16 get_data_dir().join("ovr_comp")
17}
18
19pub fn data_monado_path() -> PathBuf {
20 get_data_dir().join("monado")
21}
22
23pub fn data_libsurvive_path() -> PathBuf {
24 get_data_dir().join("libsurvive")
25}
26
27pub fn data_openhmd_path() -> PathBuf {
28 get_data_dir().join("openhmd")
29}
30
31pub fn data_basalt_path() -> PathBuf {
32 get_data_dir().join("basalt")
33}
34
35pub const SYSTEM_PREFIX: &str = "/usr";
36
37lazy_static! {
38 pub static ref SYSTEM_PREFIX_PATH: PathBuf = PathBuf::from(SYSTEM_PREFIX);
39}
40
41/// System prefix inside a bubblewrap environment (flatpak or pressure vessel)
42pub const BWRAP_SYSTEM_PREFIX: &str = "/run/host/usr";
43
44pub fn get_home_dir() -> PathBuf {
45 env::var("HOME").expect("HOME env var not defined").into()
46}
47
48pub fn get_config_dir() -> PathBuf {
49 XDG_CONFIG_HOME.join(CMD_NAME)
50}
51
52pub fn get_data_dir() -> PathBuf {
53 XDG_DATA_HOME.join(CMD_NAME)
54}
55
56pub fn get_cache_dir() -> PathBuf {
57 XDG_CACHE_HOME.join(CMD_NAME)
58}
59
60pub fn get_logs_dir() -> PathBuf {
61 get_cache_dir().join("logs")
62}
63
64pub fn get_backup_dir() -> PathBuf {
65 let p = get_data_dir().join("backups");
66 if !p.is_dir() {
67 if p.is_file() {
68 panic!(
69 "{} is a file but it should be a directory!",
70 p.to_str().unwrap()
71 );
72 }
73 create_dir_all(&p).expect("Failed to create backups dir");
74 }
75 p
76}
77
78pub fn get_exec_prefix() -> PathBuf {
79 let p = Path::new("/proc/self/exe");
80 if !p.is_symlink() {
81 panic!("/proc/self/exe is not a symlink!");
82 }
83 p.read_link()
84 .unwrap()
85 .as_path()
86 .parent()
87 .unwrap()
88 .parent()
89 .unwrap()
90 .into()
91}
92
93const STEAMVR_STEAM_APPID: u32 = 250820;
94
95fn get_steamvr_base_dir() -> anyhow::Result<PathBuf> {
96 SteamLibraryFolder::get_folders()?
97 .into_iter()
98 .find(|lf| lf.apps.contains_key(&STEAMVR_STEAM_APPID))
99 .map(|lf| PathBuf::from(lf.path).join("steamapps/common/SteamVR"))
100 .ok_or(anyhow::Error::msg(
101 "Could not find SteamVR in Steam libraryfolders.vdf",
102 ))
103}
104
105pub fn get_steamvr_bin_dir_path() -> anyhow::Result<PathBuf> {
106 let res = get_steamvr_base_dir()?.join("bin/linux64");
107 if !res.is_dir() {
108 bail!("SteamVR bin dir `{}` does not exist", res.to_string_lossy());
109 }
110 Ok(res)
111}
112
113pub fn get_plugins_dir() -> PathBuf {
114 get_data_dir().join("plugins")
115}