use crate::thread_log;
use std::path::PathBuf;
#[cfg(not(target_os = "windows"))]
mod unix;
#[allow(unused_imports)]
#[cfg(not(target_os = "windows"))]
pub use self::unix::*;
#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
pub use self::windows::*;
pub const USER_CONFIG_DIR_NAME: &str = ".ntap";
pub const DOWNLOAD_DIR_NAME: &str = "Downloads";
#[cfg(target_os = "windows")]
pub fn get_os_type() -> String {
"windows".to_owned()
}
#[cfg(target_os = "linux")]
pub fn get_os_type() -> String {
"linux".to_owned()
}
#[cfg(target_os = "macos")]
pub fn get_os_type() -> String {
"macos".to_owned()
}
pub fn get_sysdate() -> String {
let now = chrono::Local::now();
now.to_rfc3339()
}
pub fn get_config_dir_path() -> Option<PathBuf> {
match home::home_dir() {
Some(mut path) => {
path.push(USER_CONFIG_DIR_NAME);
if !path.exists() {
match std::fs::create_dir_all(&path) {
Ok(_) => {}
Err(e) => {
thread_log!(error, "{:?}", e);
return None;
}
}
}
Some(path)
}
None => None,
}
}
pub fn get_user_file_path(file_name: &str) -> Option<PathBuf> {
match get_config_dir_path() {
Some(mut path) => {
path.push(file_name);
Some(path)
}
None => None,
}
}
pub fn get_download_dir_path() -> Option<PathBuf> {
match home::home_dir() {
Some(mut path) => {
path.push(DOWNLOAD_DIR_NAME);
Some(path)
}
None => None,
}
}