summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-12-28 13:15:10 +0100
committerfxqnlr <[email protected]>2022-12-28 13:15:10 +0100
commit5326d48f6e0a88ad42005c39b73f7baaf91c9b86 (patch)
tree154ff8715a2e0f121b285870d52c50f1737f7abc /src/config.rs
parente1c79889d3bf02c8d131d642fed8ba7ef9521bf4 (diff)
downloadmodlist-5326d48f6e0a88ad42005c39b73f7baaf91c9b86.tar
modlist-5326d48f6e0a88ad42005c39b73f7baaf91c9b86.tar.gz
modlist-5326d48f6e0a88ad42005c39b73f7baaf91c9b86.zip
added devdir; better config dir
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs14
1 files changed, 9 insertions, 5 deletions
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}};
2 2
3use serde::{Serialize, Deserialize}; 3use serde::{Serialize, Deserialize};
4 4
5use crate::error::MLE; 5use crate::{error::MLE, devdir};
6 6
7#[derive(Debug, Clone, Serialize, Deserialize)] 7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Cfg { 8pub struct Cfg {
@@ -16,16 +16,20 @@ pub struct Apis {
16} 16}
17 17
18impl Cfg { 18impl Cfg {
19 pub fn init(path: &str) -> MLE<Self> { 19 pub fn init(filename: &str) -> MLE<Self> {
20 let mut file = match File::open(path) { 20 let configfile = dirs::config_dir().unwrap().join(filename);
21
22 let mut file = match File::open(devdir(configfile.to_str().unwrap())) {
21 Ok(file) => file, 23 Ok(file) => file,
22 Err(err) => { 24 Err(err) => {
23 if err.kind() == std::io::ErrorKind::NotFound { 25 if err.kind() == std::io::ErrorKind::NotFound {
24 println!("No config file found, creating one"); 26 println!("No config file found, creating one");
25 let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } }; 27 let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } };
26 let mut file = File::create(path)?; 28 //TODO Error
29 let mut file = File::create(devdir(configfile.to_str().unwrap()))?;
30 println!("Created config file");
27 file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?; 31 file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?;
28 File::open(path)? 32 File::open(devdir(configfile.to_str().unwrap()))?
29 } else { 33 } else {
30 return Err(err.into()); 34 return Err(err.into());
31 } 35 }