use std::path::PathBuf;
use crate::app;
const LINUX: &str = "linux";
const MAC_OS: &str = "macos";
const WINDOWS: &str = "windows";
pub const UNIX_INVALID_FILE_NAME_CHARS: &str = r":/\\";
pub const WINDOWS_INVALID_FILE_NAME_CHARS: &str = r#"<>:"/\\|?*"#;
#[derive(Debug, PartialEq, PartialOrd)]
pub enum OS {
Linux,
MacOs,
Windows,
}
pub fn get_os() -> Option<OS> {
let os_name = std::env::consts::OS;
if os_name.eq_ignore_ascii_case(LINUX) {
Some(OS::Linux)
} else if os_name.eq_ignore_ascii_case(MAC_OS) {
Some(OS::MacOs)
} else if os_name.eq_ignore_ascii_case(WINDOWS) {
Some(OS::Windows)
} else {
None
}
}
pub fn download_directory() -> PathBuf {
match dirs::home_dir() {
Some(home_dir) => home_dir.join("Downloads"),
None => PathBuf::new()
.join(".")
.join(app::APP_NAME)
.join("Downloads"),
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_os_type() {
let os = get_os();
match os {
Some(OS::Linux) => assert_eq!(Some(OS::Linux), os),
Some(OS::MacOs) => assert_eq!(Some(OS::MacOs), os),
Some(OS::Windows) => assert_eq!(Some(OS::Windows), os),
None => assert_eq!(None, os),
}
}
}