Fix: fix and improve get_config_path function

This commit is contained in:
MeexReay 2025-06-19 14:59:14 +03:00
parent c8b2c7e541
commit 5b23a3bd70

View File

@ -66,44 +66,25 @@ pub struct Config {
pub debug_logs: bool, pub debug_logs: bool,
} }
#[cfg(target_os = "windows")]
pub fn get_config_path() -> PathBuf { pub fn get_config_path() -> PathBuf {
let mut config_dir = PathBuf::from_str(".").unwrap(); use std::env;
env::var("APPDATA")
.ok()
.and_then(|o| Some(PathBuf::from_str(&o).ok()?.join("bRAC")))
.unwrap_or("bRAC/config.yml".into())
}
#[cfg(not(target_os = "windows"))] #[cfg(any(target_os = "macos", target_os = "linux"))]
if let Some(dir) = { pub fn get_config_path() -> PathBuf {
let home_dir = { use homedir::my_home;
use homedir::my_home; my_home()
my_home().ok().flatten() .ok()
}; .flatten()
.map(|o| o.join(".config"))
#[cfg(target_os = "linux")] .map(|o| o.join("bRAC"))
let config_dir = { .unwrap_or("bRAC".into())
let home_dir = home_dir.map(|o| o.join("bRAC")); .join("config.yml")
home_dir.map(|o| o.join(".config"))
};
#[cfg(target_os = "macos")]
let config_dir = {
let home_dir = home_dir.map(|o| o.join("bRAC"));
home_dir.map(|o| o.join(".config"))
};
config_dir
} {
config_dir = dir;
}
#[cfg(target_os = "windows")]
if let Some(dir) = {
use std::env;
env::var("APPDATA")
.ok()
.and_then(|o| Some(PathBuf::from_str(&o).ok()?.join("bRAC")))
} {
config_dir = dir;
}
config_dir.join("config.yml")
} }
pub fn load_config(path: PathBuf) -> Config { pub fn load_config(path: PathBuf) -> Config {