use std::path::PathBuf;
use directories::ProjectDirs;
use once_cell::sync::Lazy;
pub const MAX_PIPE_CHUNK_SIZE: usize = 16384;
const SOCKET_FILE_STR: &str = "distant.sock";
pub mod user {
use super::*;
static PROJECT_DIR: Lazy<ProjectDirs> = Lazy::new(|| {
ProjectDirs::from("", "", "distant").expect("Could not determine valid $HOME path")
});
pub static CONFIG_FILE_PATH: Lazy<PathBuf> =
Lazy::new(|| PROJECT_DIR.config_dir().join("config.toml"));
pub static CACHE_FILE_PATH: Lazy<PathBuf> =
Lazy::new(|| PROJECT_DIR.cache_dir().join("cache.toml"));
pub static CACHE_FILE_PATH_STR: Lazy<String> =
Lazy::new(|| CACHE_FILE_PATH.to_string_lossy().to_string());
pub static CLIENT_LOG_FILE_PATH: Lazy<PathBuf> =
Lazy::new(|| PROJECT_DIR.cache_dir().join("client.log"));
pub static MANAGER_LOG_FILE_PATH: Lazy<PathBuf> =
Lazy::new(|| PROJECT_DIR.cache_dir().join("manager.log"));
pub static SERVER_LOG_FILE_PATH: Lazy<PathBuf> =
Lazy::new(|| PROJECT_DIR.cache_dir().join("server.log"));
pub static GENERATE_LOG_FILE_PATH: Lazy<PathBuf> =
Lazy::new(|| PROJECT_DIR.cache_dir().join("generate.log"));
pub static UNIX_SOCKET_PATH: Lazy<PathBuf> = Lazy::new(|| {
let mut file_name = whoami::username_os();
file_name.push(".");
file_name.push(SOCKET_FILE_STR);
PROJECT_DIR
.runtime_dir()
.map(std::path::Path::to_path_buf)
.unwrap_or_else(std::env::temp_dir)
.join(file_name)
});
pub static WINDOWS_PIPE_NAME: Lazy<String> =
Lazy::new(|| format!("{}.distant", whoami::username()));
}
pub mod global {
use super::*;
#[cfg(windows)]
static PROGRAM_DATA_DIR: Lazy<PathBuf> = Lazy::new(|| {
PathBuf::from(std::env::var("ProgramData").expect("Could not determine %ProgramData%"))
});
#[cfg(windows)]
static CONFIG_DIR: Lazy<PathBuf> = Lazy::new(|| PROGRAM_DATA_DIR.join("distant"));
#[cfg(unix)]
static CONFIG_DIR: Lazy<PathBuf> = Lazy::new(|| PathBuf::from("/etc").join("distant"));
pub static CONFIG_FILE_PATH: Lazy<PathBuf> = Lazy::new(|| CONFIG_DIR.join("config.toml"));
pub static UNIX_SOCKET_PATH: Lazy<PathBuf> = Lazy::new(|| {
if cfg!(target_os = "macos") {
std::env::temp_dir().join(SOCKET_FILE_STR)
} else if cfg!(any(
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
)) {
PathBuf::from("/var").join("run").join(SOCKET_FILE_STR)
} else if cfg!(target_os = "android") {
PathBuf::from("@TERMUX_PREFIX@/var")
.join("run")
.join(SOCKET_FILE_STR)
} else {
PathBuf::from("/run").join(SOCKET_FILE_STR)
}
});
pub static WINDOWS_PIPE_NAME: Lazy<String> = Lazy::new(|| "distant".to_string());
}