summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs15
1 files changed, 10 insertions, 5 deletions
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 {
26 Some(p) => String::from(p), 26 Some(p) => String::from(p),
27 None => dirs::config_dir() 27 None => dirs::config_dir()
28 .unwrap() 28 .unwrap()
29 .join("modlist.toml") 29 .join("modlist")
30 .join("config.toml")
30 .to_string_lossy() 31 .to_string_lossy()
31 .to_string(), 32 .to_string(),
32 }; 33 };
@@ -50,7 +51,6 @@ impl Cfg {
50 create_cache(&config.cache)?; 51 create_cache(&config.cache)?;
51 }; 52 };
52 //Check database 53 //Check database
53 //TODO check file
54 let datafile = format!("{}/data.db", config.data); 54 let datafile = format!("{}/data.db", config.data);
55 match File::open(&datafile) { 55 match File::open(&datafile) {
56 Ok(..) => (), 56 Ok(..) => (),
@@ -64,14 +64,19 @@ fn create_config(path: &str) -> MLE<()> {
64 print!("No config file found, create default"); 64 print!("No config file found, create default");
65 //Force flush of stdout, else print! doesn't print instantly 65 //Force flush of stdout, else print! doesn't print instantly
66 std::io::stdout().flush()?; 66 std::io::stdout().flush()?;
67 let cache_dir = dirs::cache_dir()
68 .unwrap()
69 .join("modlist")
70 .to_string_lossy()
71 .to_string();
67 let default_cfg = Cfg { 72 let default_cfg = Cfg {
68 //TODO get home dir 73 data: cache_dir.clone(),
69 data: String::from("$HOME/.cache/modlist/"), 74 cache: format!("{}/cache", cache_dir),
70 cache: String::from("$HOME/.cache/modlist/cache"),
71 apis: Apis { 75 apis: Apis {
72 modrinth: String::from("https://api.modrinth.com/v2/"), 76 modrinth: String::from("https://api.modrinth.com/v2/"),
73 }, 77 },
74 }; 78 };
79 create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?;
75 let mut file = File::create(path)?; 80 let mut file = File::create(path)?;
76 file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; 81 file.write_all(toml::to_string(&default_cfg)?.as_bytes())?;
77 println!(" ✓"); 82 println!(" ✓");