From 5326d48f6e0a88ad42005c39b73f7baaf91c9b86 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 28 Dec 2022 13:15:10 +0100 Subject: added devdir; better config dir --- src/config.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 99d2ec2..383e7ee 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,7 +2,7 @@ use std::{fs::File, io::{Read, Write}}; use serde::{Serialize, Deserialize}; -use crate::error::MLE; +use crate::{error::MLE, devdir}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Cfg { @@ -16,16 +16,20 @@ pub struct Apis { } impl Cfg { - pub fn init(path: &str) -> MLE { - let mut file = match File::open(path) { + pub fn init(filename: &str) -> MLE { + let configfile = dirs::config_dir().unwrap().join(filename); + + let mut file = match File::open(devdir(configfile.to_str().unwrap())) { Ok(file) => file, Err(err) => { if err.kind() == std::io::ErrorKind::NotFound { println!("No config file found, creating one"); let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } }; - let mut file = File::create(path)?; + //TODO Error + let mut file = File::create(devdir(configfile.to_str().unwrap()))?; + println!("Created config file"); file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?; - File::open(path)? + File::open(devdir(configfile.to_str().unwrap()))? } else { return Err(err.into()); } -- cgit v1.2.3