From 3e65975227baa511f570e8223fccda5607cf905e Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 23 Apr 2023 21:47:37 +0200 Subject: added config argument, remove devdir --- src/config.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index a9a937e..23c7796 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,7 @@ use std::{ use serde::{Deserialize, Serialize}; -use crate::{devdir, error::MLE}; +use crate::error::MLE; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Cfg { @@ -20,10 +20,13 @@ pub struct Apis { } impl Cfg { - pub fn init(filename: &str) -> MLE { - let configfile = dirs::config_dir().unwrap().join(filename); + pub fn init(path: Option) -> MLE { + let configfile = match path { + Some(p) => String::from(p), + None => dirs::config_dir().unwrap().join("modlist.toml").to_string_lossy().into(), + }; - let mut file = match File::open(devdir(configfile.to_str().unwrap())) { + let mut file = match File::open(&configfile) { Ok(file) => file, Err(err) => { if err.kind() == std::io::ErrorKind::NotFound { @@ -35,10 +38,10 @@ impl Cfg { modrinth: String::from("https://api.modrinth.com/v2/"), }, }; - let mut file = File::create(devdir(configfile.to_str().unwrap()))?; + let mut file = File::create(&configfile)?; println!("Created config file"); file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; - File::open(devdir(configfile.to_str().unwrap()))? + File::open(&configfile)? } else { return Err(err.into()); } -- cgit v1.2.3