mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-04 23:29:00 +00:00
fix: move some paths from file_utils to paths
This commit is contained in:
parent
4b95a22045
commit
4fb3d37551
12 changed files with 127 additions and 120 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::{constants::pkg_data_dir, file_utils::get_cache_dir, profile::Profile, runner::Runner};
|
use crate::{constants::pkg_data_dir, paths::get_cache_dir, profile::Profile, runner::Runner};
|
||||||
|
|
||||||
pub fn get_build_mercury_runner(profile: Profile) -> Runner {
|
pub fn get_build_mercury_runner(profile: Profile) -> Runner {
|
||||||
let args = vec![profile.prefix, get_cache_dir()];
|
let args = vec![profile.prefix, get_cache_dir()];
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::{
|
use crate::{constants::CMD_NAME, file_utils::get_writer, paths::get_config_dir, profile::Profile};
|
||||||
constants::CMD_NAME,
|
|
||||||
file_utils::{get_config_dir, get_writer}, profile::Profile,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fs::File, io::BufReader};
|
use std::{fs::File, io::BufReader};
|
||||||
|
|
||||||
|
@ -25,7 +22,10 @@ impl Default for Config {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn get_selected_profile(&self, profiles: &Vec<Profile>) -> Profile {
|
pub fn get_selected_profile(&self, profiles: &Vec<Profile>) -> Profile {
|
||||||
match profiles.iter().find(|p| {p.uuid == self.selected_profile_uuid}) {
|
match profiles
|
||||||
|
.iter()
|
||||||
|
.find(|p| p.uuid == self.selected_profile_uuid)
|
||||||
|
{
|
||||||
Some(p) => p.clone(),
|
Some(p) => p.clone(),
|
||||||
None => profiles.get(0).expect("No profiles found").clone(),
|
None => profiles.get(0).expect("No profiles found").clone(),
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) {
|
pub fn save(&self) {
|
||||||
self.save_to_path(&Self::config_file_path()).expect("Failed to save config");
|
self.save_to_path(&Self::config_file_path())
|
||||||
|
.expect("Failed to save config");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_config() -> Self {
|
pub fn get_config() -> Self {
|
||||||
|
@ -66,7 +67,11 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_profiles(&mut self, profiles: &Vec<Profile>) {
|
pub fn set_profiles(&mut self, profiles: &Vec<Profile>) {
|
||||||
self.user_profiles = profiles.iter().filter(|p| p.editable).map(Profile::clone).collect();
|
self.user_profiles = profiles
|
||||||
|
.iter()
|
||||||
|
.filter(|p| p.editable)
|
||||||
|
.map(Profile::clone)
|
||||||
|
.collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::file_utils::get_exec_prefix;
|
use crate::paths::get_exec_prefix;
|
||||||
|
|
||||||
pub const APP_NAME: &str = "@PRETTY_NAME@";
|
pub const APP_NAME: &str = "@PRETTY_NAME@";
|
||||||
pub const APP_ID: &str = "@APP_ID@";
|
pub const APP_ID: &str = "@APP_ID@";
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
file_utils::{
|
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||||
copy_file, deserialize_file, get_backup_dir, get_writer, get_xdg_config_dir,
|
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir, SYSTEM_PREFIX},
|
||||||
get_xdg_data_dir, set_file_readonly,
|
|
||||||
},
|
|
||||||
paths::SYSTEM_PREFIX,
|
|
||||||
profile::{Profile, XRServiceType},
|
profile::{Profile, XRServiceType},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -74,8 +71,7 @@ pub fn get_current_active_runtime() -> Option<ActiveRuntime> {
|
||||||
|
|
||||||
fn dump_active_runtime_to_path(active_runtime: &ActiveRuntime, path_s: &String) {
|
fn dump_active_runtime_to_path(active_runtime: &ActiveRuntime, path_s: &String) {
|
||||||
let writer = get_writer(path_s);
|
let writer = get_writer(path_s);
|
||||||
serde_json::to_writer_pretty(writer, active_runtime)
|
serde_json::to_writer_pretty(writer, active_runtime).expect("Unable to save active runtime");
|
||||||
.expect("Unable to save active runtime");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_current_active_runtime(active_runtime: &ActiveRuntime) {
|
pub fn dump_current_active_runtime(active_runtime: &ActiveRuntime) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
use crate::{
|
||||||
|
file_utils::{deserialize_file, get_writer},
|
||||||
|
paths::get_xdg_config_dir,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::file_utils::{deserialize_file, get_writer, get_xdg_config_dir};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct MonadoAutorun {
|
pub struct MonadoAutorun {
|
||||||
pub exec: String,
|
pub exec: String,
|
||||||
|
@ -44,8 +46,7 @@ pub fn get_monado_autorun_config() -> MonadoAutorunConfig {
|
||||||
|
|
||||||
fn dump_monado_autorun_config_to_path(config: &MonadoAutorunConfig, path_s: &String) {
|
fn dump_monado_autorun_config_to_path(config: &MonadoAutorunConfig, path_s: &String) {
|
||||||
let writer = get_writer(path_s);
|
let writer = get_writer(path_s);
|
||||||
serde_json::to_writer_pretty(writer, config)
|
serde_json::to_writer_pretty(writer, config).expect("Unable to save Monado Autorun config");
|
||||||
.expect("Unable to save Monado Autorun config");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_monado_autorun_config(config: &MonadoAutorunConfig) {
|
pub fn dump_monado_autorun_config(config: &MonadoAutorunConfig) {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
file_utils::{
|
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||||
copy_file, deserialize_file, get_backup_dir, get_writer, get_xdg_config_dir,
|
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir},
|
||||||
get_xdg_data_dir, set_file_readonly,
|
|
||||||
},
|
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use crate::file_utils::{deserialize_file, get_writer, get_xdg_config_dir};
|
use crate::{
|
||||||
|
file_utils::{deserialize_file, get_writer},
|
||||||
|
paths::get_xdg_config_dir,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Display, slice::Iter};
|
use std::{fmt::Display, slice::Iter};
|
||||||
|
|
||||||
|
|
|
@ -52,70 +52,6 @@ pub fn deserialize_file<T: serde::de::DeserializeOwned>(path_s: &String) -> Opti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_home_dir() -> String {
|
|
||||||
env::var("HOME").expect("HOME env var not defined")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_xdg_config_dir() -> String {
|
|
||||||
match env::var("XDG_CONFIG_HOME") {
|
|
||||||
Ok(conf_home) => conf_home,
|
|
||||||
Err(_) => format!("{home}/.config", home = get_home_dir()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_xdg_data_dir() -> String {
|
|
||||||
match env::var("XDG_DATA_HOME") {
|
|
||||||
Ok(data_home) => data_home,
|
|
||||||
Err(_) => format!("{home}/.local/share", home = get_home_dir()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_xdg_cache_dir() -> String {
|
|
||||||
match env::var("XDG_CACHE_HOME") {
|
|
||||||
Ok(cache_home) => cache_home,
|
|
||||||
Err(_) => format!("{home}/.cache", home = get_home_dir()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_xdg_runtime_dir() -> String {
|
|
||||||
env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_config_dir() -> String {
|
|
||||||
format!(
|
|
||||||
"{config}/{name}",
|
|
||||||
config = get_xdg_config_dir(),
|
|
||||||
name = CMD_NAME
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_data_dir() -> String {
|
|
||||||
format!("{data}/{name}", data = get_xdg_data_dir(), name = CMD_NAME)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_cache_dir() -> String {
|
|
||||||
format!(
|
|
||||||
"{cache}/{name}",
|
|
||||||
cache = get_xdg_cache_dir(),
|
|
||||||
name = CMD_NAME
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_backup_dir() -> String {
|
|
||||||
let p_s = format!("{data}/backups", data = get_data_dir());
|
|
||||||
let p = Path::new(&p_s);
|
|
||||||
if !p.is_dir() {
|
|
||||||
if p.is_file() {
|
|
||||||
panic!(
|
|
||||||
"{} is a file but it should be a directory!",
|
|
||||||
p.to_str().unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
create_dir_all(p).expect("Failed to create backups dir");
|
|
||||||
}
|
|
||||||
p.to_str().unwrap().to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_file_readonly(path_s: &String, readonly: bool) {
|
pub fn set_file_readonly(path_s: &String, readonly: bool) {
|
||||||
let path = Path::new(&path_s);
|
let path = Path::new(&path_s);
|
||||||
if !path.is_file() {
|
if !path.is_file() {
|
||||||
|
@ -139,23 +75,6 @@ pub fn setcap_cap_sys_nice_eip(file: String) {
|
||||||
runner.join();
|
runner.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_exec_prefix() -> String {
|
|
||||||
let p = Path::new("/proc/self/exe");
|
|
||||||
if !p.is_symlink() {
|
|
||||||
panic!("/proc/self/exe is not a symlink!");
|
|
||||||
}
|
|
||||||
p.read_link()
|
|
||||||
.unwrap()
|
|
||||||
.as_path()
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rm_rf(path_s: &String) {
|
pub fn rm_rf(path_s: &String) {
|
||||||
match remove_dir_all(path_s) {
|
match remove_dir_all(path_s) {
|
||||||
Err(_) => println!("Failed to remove path {}", path_s),
|
Err(_) => println!("Failed to remove path {}", path_s),
|
||||||
|
|
84
src/paths.rs
84
src/paths.rs
|
@ -1,4 +1,5 @@
|
||||||
use crate::file_utils::{get_data_dir, get_cache_dir};
|
use std::{env, path::Path, fs::create_dir_all};
|
||||||
|
use crate::constants::CMD_NAME;
|
||||||
|
|
||||||
pub fn data_opencomposite_path() -> String {
|
pub fn data_opencomposite_path() -> String {
|
||||||
format!("{data}/opencomposite", data = get_data_dir())
|
format!("{data}/opencomposite", data = get_data_dir())
|
||||||
|
@ -24,3 +25,84 @@ pub const SYSTEM_PREFIX: &str = "/usr";
|
||||||
|
|
||||||
/** System prefix inside a bubblewrap environment (flatpak or pressure vessel) */
|
/** System prefix inside a bubblewrap environment (flatpak or pressure vessel) */
|
||||||
pub const BWRAP_SYSTEM_PREFIX: &str = "/run/host/usr";
|
pub const BWRAP_SYSTEM_PREFIX: &str = "/run/host/usr";
|
||||||
|
|
||||||
|
pub fn get_home_dir() -> String {
|
||||||
|
env::var("HOME").expect("HOME env var not defined")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_xdg_config_dir() -> String {
|
||||||
|
match env::var("XDG_CONFIG_HOME") {
|
||||||
|
Ok(conf_home) => conf_home,
|
||||||
|
Err(_) => format!("{home}/.config", home = get_home_dir()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_xdg_data_dir() -> String {
|
||||||
|
match env::var("XDG_DATA_HOME") {
|
||||||
|
Ok(data_home) => data_home,
|
||||||
|
Err(_) => format!("{home}/.local/share", home = get_home_dir()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_xdg_cache_dir() -> String {
|
||||||
|
match env::var("XDG_CACHE_HOME") {
|
||||||
|
Ok(cache_home) => cache_home,
|
||||||
|
Err(_) => format!("{home}/.cache", home = get_home_dir()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_xdg_runtime_dir() -> String {
|
||||||
|
env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_config_dir() -> String {
|
||||||
|
format!(
|
||||||
|
"{config}/{name}",
|
||||||
|
config = get_xdg_config_dir(),
|
||||||
|
name = CMD_NAME
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_data_dir() -> String {
|
||||||
|
format!("{data}/{name}", data = get_xdg_data_dir(), name = CMD_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_cache_dir() -> String {
|
||||||
|
format!(
|
||||||
|
"{cache}/{name}",
|
||||||
|
cache = get_xdg_cache_dir(),
|
||||||
|
name = CMD_NAME
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_backup_dir() -> String {
|
||||||
|
let p_s = format!("{data}/backups", data = get_data_dir());
|
||||||
|
let p = Path::new(&p_s);
|
||||||
|
if !p.is_dir() {
|
||||||
|
if p.is_file() {
|
||||||
|
panic!(
|
||||||
|
"{} is a file but it should be a directory!",
|
||||||
|
p.to_str().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
create_dir_all(p).expect("Failed to create backups dir");
|
||||||
|
}
|
||||||
|
p.to_str().unwrap().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_exec_prefix() -> String {
|
||||||
|
let p = Path::new("/proc/self/exe");
|
||||||
|
if !p.is_symlink() {
|
||||||
|
panic!("/proc/self/exe is not a symlink!");
|
||||||
|
}
|
||||||
|
p.read_link()
|
||||||
|
.unwrap()
|
||||||
|
.as_path()
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
file_utils::{get_data_dir, get_writer},
|
file_utils::get_writer,
|
||||||
paths::{data_monado_path, data_opencomposite_path, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX},
|
paths::{
|
||||||
|
data_monado_path, data_opencomposite_path, get_data_dir, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader, slice::Iter, path::Path};
|
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader, path::Path, slice::Iter};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
@ -201,10 +203,7 @@ impl Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_survive_cli_path(&self) -> Option<String> {
|
pub fn get_survive_cli_path(&self) -> Option<String> {
|
||||||
let path_s = format!(
|
let path_s = format!("{pfx}/bin/survive-cli", pfx = self.prefix);
|
||||||
"{pfx}/bin/survive-cli",
|
|
||||||
pfx = self.prefix
|
|
||||||
);
|
|
||||||
if Path::new(&path_s).is_file() {
|
if Path::new(&path_s).is_file() {
|
||||||
return Some(path_s);
|
return Some(path_s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::APP_NAME,
|
constants::APP_NAME,
|
||||||
file_utils::get_data_dir,
|
paths::{data_libsurvive_path, data_monado_path, data_opencomposite_path, get_data_dir},
|
||||||
paths::{data_libsurvive_path, data_monado_path, data_opencomposite_path},
|
|
||||||
profile::{Profile, ProfileFeature, ProfileFeatureType, ProfileFeatures, XRServiceType},
|
profile::{Profile, ProfileFeature, ProfileFeatureType, ProfileFeatures, XRServiceType},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -15,7 +14,10 @@ pub fn valve_index_profile() -> Profile {
|
||||||
environment.insert("XRT_COMPOSITOR_COMPUTE".into(), "1".into());
|
environment.insert("XRT_COMPOSITOR_COMPUTE".into(), "1".into());
|
||||||
environment.insert("SURVIVE_GLOBALSCENESOLVER".into(), "0".into());
|
environment.insert("SURVIVE_GLOBALSCENESOLVER".into(), "0".into());
|
||||||
environment.insert("SURVIVE_TIMECODE_OFFSET_MS".into(), "-6.94".into());
|
environment.insert("SURVIVE_TIMECODE_OFFSET_MS".into(), "-6.94".into());
|
||||||
environment.insert("LD_LIBRARY_PATH".into(), format!("{pfx}/lib:{pfx}/lib64", pfx = prefix));
|
environment.insert(
|
||||||
|
"LD_LIBRARY_PATH".into(),
|
||||||
|
format!("{pfx}/lib:{pfx}/lib64", pfx = prefix),
|
||||||
|
);
|
||||||
Profile {
|
Profile {
|
||||||
uuid: "valve-index-default".into(),
|
uuid: "valve-index-default".into(),
|
||||||
name: format!("Valve Index - {name} Default", name = APP_NAME),
|
name: format!("Valve Index - {name} Default", name = APP_NAME),
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::APP_NAME,
|
constants::APP_NAME,
|
||||||
file_utils::get_data_dir,
|
paths::{data_opencomposite_path, data_wivrn_path, get_data_dir},
|
||||||
paths::{data_opencomposite_path, data_wivrn_path},
|
|
||||||
profile::{Profile, ProfileFeatures, XRServiceType},
|
profile::{Profile, ProfileFeatures, XRServiceType},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -10,7 +9,10 @@ pub fn wivrn_profile() -> Profile {
|
||||||
let data_dir = get_data_dir();
|
let data_dir = get_data_dir();
|
||||||
let prefix = format!("{data}/prefixes/wivrn_default", data = data_dir);
|
let prefix = format!("{data}/prefixes/wivrn_default", data = data_dir);
|
||||||
let mut environment: HashMap<String, String> = HashMap::new();
|
let mut environment: HashMap<String, String> = HashMap::new();
|
||||||
environment.insert("LD_LIBRARY_PATH".into(), format!("{pfx}/lib:{pfx}/lib64", pfx = prefix));
|
environment.insert(
|
||||||
|
"LD_LIBRARY_PATH".into(),
|
||||||
|
format!("{pfx}/lib:{pfx}/lib64", pfx = prefix),
|
||||||
|
);
|
||||||
Profile {
|
Profile {
|
||||||
uuid: "wivrn-default".into(),
|
uuid: "wivrn-default".into(),
|
||||||
name: format!("WiVRn - {name} Default", name = APP_NAME),
|
name: format!("WiVRn - {name} Default", name = APP_NAME),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue