diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs index 3538a69..6280932 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -8,7 +8,7 @@ use indicatif::{ProgressBar, ProgressStyle}; | |||
8 | use serde::{Deserialize, Serialize}; | 8 | use serde::{Deserialize, Serialize}; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | check_game_versions, db::db_setup, error::MLE, Modloader, VersionLevel, | 11 | check_game_versions, db::setup, error::{EType, MLErr, MLE}, Modloader, VersionLevel, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | #[derive(Debug, Clone, Serialize, Deserialize)] | 14 | #[derive(Debug, Clone, Serialize, Deserialize)] |
@@ -32,11 +32,12 @@ pub struct Defaults { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | impl Cfg { | 34 | impl Cfg { |
35 | /// # Errors | ||
35 | pub async fn init(path: Option<String>) -> MLE<Self> { | 36 | pub async fn init(path: Option<String>) -> MLE<Self> { |
36 | let configfile = match path.clone() { | 37 | let configfile = match path.clone() { |
37 | Some(p) => p, | 38 | Some(p) => p, |
38 | None => dirs::config_dir() | 39 | None => dirs::config_dir() |
39 | .unwrap() | 40 | .ok_or(MLErr::new(EType::Other, "config_dir"))? |
40 | .join("modlist") | 41 | .join("modlist") |
41 | .join("config.toml") | 42 | .join("config.toml") |
42 | .to_string_lossy() | 43 | .to_string_lossy() |
@@ -70,8 +71,8 @@ impl Cfg { | |||
70 | }; | 71 | }; |
71 | //Check versions | 72 | //Check versions |
72 | let versionfile = format!("{}/versions.json", config.versions); | 73 | let versionfile = format!("{}/versions.json", config.versions); |
73 | if let Ok(..) = File::open(&versionfile) { } else { | 74 | if File::open(&versionfile).is_err() { |
74 | create_versions_dummy(&versionfile).await?; | 75 | create_versions_dummy(&versionfile)?; |
75 | check_game_versions(&versionfile, true).await?; | 76 | check_game_versions(&versionfile, true).await?; |
76 | } | 77 | } |
77 | 78 | ||
@@ -114,7 +115,7 @@ fn create_database(path: &str) -> MLE<()> { | |||
114 | p.set_message("Create database"); | 115 | p.set_message("Create database"); |
115 | 116 | ||
116 | File::create(path)?; | 117 | File::create(path)?; |
117 | db_setup(path)?; | 118 | setup(path)?; |
118 | p.finish_with_message(format!("Created database ({path})")); | 119 | p.finish_with_message(format!("Created database ({path})")); |
119 | Ok(()) | 120 | Ok(()) |
120 | } | 121 | } |
@@ -129,7 +130,7 @@ fn create_cache(path: &str) -> MLE<()> { | |||
129 | Ok(()) | 130 | Ok(()) |
130 | } | 131 | } |
131 | 132 | ||
132 | async fn create_versions_dummy(path: &str) -> MLE<()> { | 133 | fn create_versions_dummy(path: &str) -> MLE<()> { |
133 | let p = ProgressBar::new(1); | 134 | let p = ProgressBar::new(1); |
134 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); | 135 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); |
135 | p.set_message("Create version file"); | 136 | p.set_message("Create version file"); |