40 lines
1.3 KiB
Rust
40 lines
1.3 KiB
Rust
use std::{env, path::PathBuf};
|
|
|
|
fn main() {
|
|
let config_path = get_config_path();
|
|
|
|
println!("Using config file: {}", config_path.display());
|
|
|
|
if !config_path.exists() {
|
|
println!("Config file does not exist, creating...");
|
|
filesorters::Config::create(&config_path).unwrap();
|
|
}
|
|
|
|
match filesorters::Config::parse(config_path) {
|
|
Ok(config) => {
|
|
println!("{:#?}", config);
|
|
}
|
|
Err(err) => {
|
|
println!("Error: {}", err);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn get_config_path() -> PathBuf {
|
|
if cfg!(target_os = "windows") {
|
|
let username = env::var("USERNAME").unwrap_or_else(|_| "Default".to_string());
|
|
PathBuf::from(format!(
|
|
"C:\\Users\\{}\\AppData\\Local\\filesorters\\filesorters.toml",
|
|
username
|
|
))
|
|
} else {
|
|
let xdg_config_home = env::var("XDG_CONFIG_HOME").ok();
|
|
let home = env::var("HOME").ok();
|
|
let user = env::var("USER").unwrap_or_else(|_| "default".to_string());
|
|
|
|
xdg_config_home
|
|
.map(|x| PathBuf::from(format!("{}/filesorters.toml", x)))
|
|
.or_else(|| home.map(|h| PathBuf::from(format!("{}/.config/filesorters.toml", h))))
|
|
.unwrap_or_else(|| PathBuf::from(format!("/home/{}/.config/filesorters.toml", user)))
|
|
}
|
|
}
|