use std::path::PathBuf;
use std::env::var;
pub fn home_dir() -> PathBuf {
#[cfg(target_family = "windows")]
let envstr = var("USERPROFILE");
#[cfg(target_family = "unix")]
let envstr = var("HOME");
PathBuf::from(envstr.unwrap_or_default())
}
fn xdg_path(xdg: &str, home_alt: &str, win: &str) -> PathBuf {
if cfg!(target_family = "unix") {
let confighome = match var(xdg) {
Ok(s) => PathBuf::from(s),
Err(_) => home_dir().join(home_alt),
};
confighome
} else {
PathBuf::from(var(win).unwrap_or_default())
}
}
pub fn config_home() -> PathBuf {
xdg_path("XDG_CONFIG_HOME", ".config", "APPDATA")
}
pub fn cache_home() -> PathBuf {
xdg_path("XDG_CACHE_HOME", ".cache", "TEMP")
}
pub fn data_home() -> PathBuf {
xdg_path("XDG_DATA_HOME", ".local/share", "APPDATA")
}
pub fn state_home() -> PathBuf {
xdg_path("XDG_STATE_HOME", ".local/state", "LOCALAPPDATA")
}