From 89faf24dde39c28c34f7e4dbe179209e866e86ac Mon Sep 17 00:00:00 2001 From: Liquid <116100070+Liquidwe@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20fix=20the=20issue=20of=20?= =?UTF-8?q?not=20finding=20the=20configuration=20file.=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/src/config.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gui/src/config.rs b/gui/src/config.rs index f465f4a..65758ca 100644 --- a/gui/src/config.rs +++ b/gui/src/config.rs @@ -42,6 +42,13 @@ lazy_static! { impl Settings { pub fn new() -> Result { let mut builder = Config::builder(); + + let default_config = include_str!("../config/default.yaml"); + builder = builder + .add_source(config::File::from_str( + default_config, + config::FileFormat::Yaml + )); let exe_path = std::env::current_exe() .unwrap_or_else(|_| std::path::PathBuf::from(".")); @@ -52,27 +59,16 @@ impl Settings { "../config/default.yaml".to_string(), "../../config/default.yaml".to_string(), format!("{}/config/default.yaml", exe_dir.display()), - format!("{}/config/default.yaml", - std::env::var("OUT_DIR").unwrap_or_else(|_| String::from("target/debug"))), ]; - let mut config_loaded = false; for location in config_locations { let path = Path::new(&location); if path.exists() { - let file = File::with_name(&location).format(FileFormat::Yaml); - builder = builder.add_source(file); - config_loaded = true; + builder = builder.add_source(File::with_name(&location).format(FileFormat::Yaml)); break; - } else { - println!("Configuration file not found: {}", location); } } - if !config_loaded { - return Err(ConfigError::NotFound("Could not find config file".into())); - } - builder.build()?.try_deserialize() }