From 06f933dac333d58b2cc3ae7ab0c285e5015a0257 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 30 Apr 2023 19:20:29 +0200 Subject: fixed config directories, moved to own folder --- src/config.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 61db1c7..9064548 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,7 +26,8 @@ impl Cfg { Some(p) => String::from(p), None => dirs::config_dir() .unwrap() - .join("modlist.toml") + .join("modlist") + .join("config.toml") .to_string_lossy() .to_string(), }; @@ -50,7 +51,6 @@ impl Cfg { create_cache(&config.cache)?; }; //Check database - //TODO check file let datafile = format!("{}/data.db", config.data); match File::open(&datafile) { Ok(..) => (), @@ -64,14 +64,19 @@ fn create_config(path: &str) -> MLE<()> { print!("No config file found, create default"); //Force flush of stdout, else print! doesn't print instantly std::io::stdout().flush()?; + let cache_dir = dirs::cache_dir() + .unwrap() + .join("modlist") + .to_string_lossy() + .to_string(); let default_cfg = Cfg { - //TODO get home dir - data: String::from("$HOME/.cache/modlist/"), - cache: String::from("$HOME/.cache/modlist/cache"), + data: cache_dir.clone(), + cache: format!("{}/cache", cache_dir), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/"), }, }; + create_dir_all(path.split("config.toml").collect::>()[0])?; let mut file = File::create(path)?; file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; println!(" ✓"); -- cgit v1.2.3