diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/config.rs b/src/config.rs index a952d40..54cf768 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -4,6 +4,7 @@ use std::{ | |||
4 | path::Path, | 4 | path::Path, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use indicatif::{ProgressBar, ProgressStyle}; | ||
7 | use serde::{Deserialize, Serialize}; | 8 | use serde::{Deserialize, Serialize}; |
8 | 9 | ||
9 | use crate::{db::db_setup, error::MLE, Modloader, VersionLevel, check_game_versions}; | 10 | use crate::{db::db_setup, error::MLE, Modloader, VersionLevel, check_game_versions}; |
@@ -79,9 +80,10 @@ impl Cfg { | |||
79 | } | 80 | } |
80 | 81 | ||
81 | fn create_config(path: &str) -> MLE<()> { | 82 | fn create_config(path: &str) -> MLE<()> { |
82 | print!("No config file found, create default"); | 83 | let p = ProgressBar::new(1); |
83 | //Force flush of stdout, else print! doesn't print instantly | 84 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); |
84 | std::io::stdout().flush()?; | 85 | p.set_message("Create default config"); |
86 | |||
85 | let cache_dir = dirs::cache_dir() | 87 | let cache_dir = dirs::cache_dir() |
86 | .unwrap() | 88 | .unwrap() |
87 | .join("modlist") | 89 | .join("modlist") |
@@ -102,37 +104,36 @@ fn create_config(path: &str) -> MLE<()> { | |||
102 | create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?; | 104 | create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?; |
103 | let mut file = File::create(path)?; | 105 | let mut file = File::create(path)?; |
104 | file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; | 106 | file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; |
105 | println!(" ✓"); | 107 | p.finish_with_message(format!("Created default config ({})", path)); |
106 | Ok(()) | 108 | Ok(()) |
107 | } | 109 | } |
108 | 110 | ||
109 | fn create_database(path: &str) -> MLE<()> { | 111 | fn create_database(path: &str) -> MLE<()> { |
110 | print!("No database found, create base"); | 112 | let p = ProgressBar::new(1); |
111 | //Force flush of stdout, else print! doesn't print instantly | 113 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); |
112 | std::io::stdout().flush()?; | 114 | p.set_message("Create database"); |
113 | 115 | ||
114 | File::create(path)?; | 116 | File::create(path)?; |
115 | db_setup(path)?; | 117 | db_setup(path)?; |
116 | println!(" ✓"); | 118 | p.finish_with_message(format!("Created database ({})", path)); |
117 | Ok(()) | 119 | Ok(()) |
118 | } | 120 | } |
119 | 121 | ||
120 | fn create_cache(path: &str) -> MLE<()> { | 122 | fn create_cache(path: &str) -> MLE<()> { |
121 | print!("No cache direcory found, create one"); | 123 | let p = ProgressBar::new(1); |
122 | //Force flush of stdout, else print! doesn't print instantly | 124 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); |
123 | std::io::stdout().flush()?; | 125 | p.set_message("Create cache"); |
124 | 126 | ||
125 | create_dir_all(path)?; | 127 | create_dir_all(path)?; |
126 | println!(" ✓"); | 128 | p.finish_with_message(format!("Created cache ({})", path)); |
127 | Ok(()) | 129 | Ok(()) |
128 | } | 130 | } |
129 | 131 | ||
130 | async fn create_versions_dummy(path: &str) -> MLE<()> { | 132 | async fn create_versions_dummy(path: &str) -> MLE<()> { |
131 | print!("No version file found, create dummy"); | 133 | let p = ProgressBar::new(1); |
132 | //Force flush of stdout, else print! doesn't print instantly | 134 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); |
133 | std::io::stdout().flush()?; | 135 | p.set_message("Create version file"); |
134 | |||
135 | File::create(path)?; | 136 | File::create(path)?; |
136 | println!(" ✓"); | 137 | p.finish_with_message(format!("Created version file ({})", path)); |
137 | Ok(()) | 138 | Ok(()) |
138 | } | 139 | } |