diff --git a/src/config.rs b/src/config.rs index ea131cc..aac8283 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,6 +44,7 @@ impl Error for MissingParameter {} impl ConfigToml { pub fn new(path: &str) -> Result> { let config = fs::read_to_string(path)?; + log::info!("using config: \"{path}\""); Ok(toml::from_str::<_>(&config)?) } } @@ -77,10 +78,25 @@ pub struct Config { impl Config { pub fn new() -> Result> { - let config_path = "config.toml"; - let config_toml = match ConfigToml::new(config_path) { + let config_file = "config.toml"; + #[cfg(unix)] let config_path = { + let xdg_config_home = env::var("XDG_CONFIG_HOME") + .unwrap_or(format!("{}/.config", env::var("HOME")?)); + format!("{xdg_config_home}/lan-mouse/{config_file}") + }; + + #[cfg(not(unix))] let config_path = { + let app_data = env::var("LOCALAPPDATA") + .unwrap_or(format!("{}/.config", env::var("USERPROFILE")?)); + format!("{app_data}\\lan-mouse\\{config_file}") + }; + + // --config overrules default location + let config_path = find_arg("--config")?.unwrap_or(config_path); + + let config_toml = match ConfigToml::new(config_path.as_str()) { Err(e) => { - log::error!("config.toml: {e}"); + log::error!("{config_path}: {e}"); log::warn!("Continuing without config file ..."); None },