use anyhow::Result;
use directories::ProjectDirs;
use std::fs;
use std::path::{Path, PathBuf};
use tracing::debug;
#[allow(unused)]
pub(crate) fn get_config_dir() -> Result<PathBuf> {
let config_dir = if let Some(proj_dirs) = ProjectDirs::from("dev", "nonebot", "nbr") {
proj_dirs.config_dir().to_path_buf()
} else {
let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
Path::new(&home).join(".config").join("nbr")
};
if !config_dir.exists() {
fs::create_dir_all(&config_dir)?;
debug!("Created config directory: {}", config_dir.display());
}
Ok(config_dir)
}
pub(crate) fn get_cache_dir() -> Result<PathBuf> {
let cache_dir = if let Some(proj_dirs) = ProjectDirs::from("dev", "nonebot", "nbr") {
proj_dirs.cache_dir().to_path_buf()
} else {
let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
Path::new(&home).join(".cache").join("nbr")
};
if !cache_dir.exists() {
fs::create_dir_all(&cache_dir)?;
debug!("Created cache directory: {}", cache_dir.display());
}
Ok(cache_dir)
}