diff options
author | fxqnlr <[email protected]> | 2022-12-28 13:15:10 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-12-28 13:15:10 +0100 |
commit | 5326d48f6e0a88ad42005c39b73f7baaf91c9b86 (patch) | |
tree | 154ff8715a2e0f121b285870d52c50f1737f7abc /src/config.rs | |
parent | e1c79889d3bf02c8d131d642fed8ba7ef9521bf4 (diff) | |
download | modlist-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.rs | 14 |
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 | ||
3 | use serde::{Serialize, Deserialize}; | 3 | use serde::{Serialize, Deserialize}; |
4 | 4 | ||
5 | use crate::error::MLE; | 5 | use crate::{error::MLE, devdir}; |
6 | 6 | ||
7 | #[derive(Debug, Clone, Serialize, Deserialize)] | 7 | #[derive(Debug, Clone, Serialize, Deserialize)] |
8 | pub struct Cfg { | 8 | pub struct Cfg { |
@@ -16,16 +16,20 @@ pub struct Apis { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | impl Cfg { | 18 | impl 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 | } |