diff options
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/files.rs b/src/files.rs index 565d2b6..2830a5f 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -14,24 +14,27 @@ use crate::{ | |||
14 | db::{mods_get_info, userlist_add_disabled_versions}, | 14 | db::{mods_get_info, userlist_add_disabled_versions}, |
15 | error::{ErrorType, MLError, MLE}, | 15 | error::{ErrorType, MLError, MLE}, |
16 | modrinth::Version, | 16 | modrinth::Version, |
17 | List, PROGRESS_CHARS, | 17 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, STYLE_BAR_BYTE, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) -> MLE<()> { | 20 | pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>, progress: &MultiProgress, progress_before: Option<&ProgressBar>) -> MLE<()> { |
21 | let cached = get_cached_versions(&config.cache); | 21 | let cached = get_cached_versions(&config.cache); |
22 | 22 | ||
23 | let mp = MultiProgress::new(); | ||
24 | |||
25 | let mut js = JoinSet::new(); | 23 | let mut js = JoinSet::new(); |
26 | 24 | ||
27 | let style_spinner = ProgressStyle::with_template("{spinner:.green}{wide_msg}").unwrap(); | 25 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); |
26 | |||
27 | let all = match progress_before { | ||
28 | Some(p) => progress.insert_before(p, ProgressBar::new(versions.len().try_into().unwrap())), | ||
29 | None => progress.add(ProgressBar::new(versions.len().try_into().unwrap())), | ||
28 | 30 | ||
29 | let all = mp.add(ProgressBar::new(versions.len().try_into().unwrap())); | 31 | |
30 | all.set_style(ProgressStyle::with_template("{wide_msg}{pos}/{len} [{bar:.green/lime}]").unwrap().progress_chars(PROGRESS_CHARS)); | 32 | }; |
33 | all.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); | ||
31 | all.set_message("Downloading"); | 34 | all.set_message("Downloading"); |
32 | 35 | ||
33 | for ver in versions { | 36 | for ver in versions { |
34 | let p = mp.insert_before(&all, ProgressBar::new(1)); | 37 | let p = progress.insert_before(&all, ProgressBar::new(1)); |
35 | p.set_style(style_spinner.clone()); | 38 | p.set_style(style_spinner.clone()); |
36 | js.spawn(download_version(config.clone(), list.clone(), ver, cached.clone(), p)); | 39 | js.spawn(download_version(config.clone(), list.clone(), ver, cached.clone(), p)); |
37 | // std::thread::sleep(std::time::Duration::from_millis(200)); | 40 | // std::thread::sleep(std::time::Duration::from_millis(200)); |
@@ -103,7 +106,7 @@ async fn download_file(url: &str, path: &str, name: &str, progress: &ProgressBar | |||
103 | 106 | ||
104 | let size = res.content_length().expect("Couldn't get content length"); | 107 | let size = res.content_length().expect("Couldn't get content length"); |
105 | 108 | ||
106 | let style_bar_byte = ProgressStyle::with_template("{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]") | 109 | let style_bar_byte = ProgressStyle::with_template(STYLE_BAR_BYTE) |
107 | .unwrap() | 110 | .unwrap() |
108 | .progress_chars(PROGRESS_CHARS); | 111 | .progress_chars(PROGRESS_CHARS); |
109 | 112 | ||
@@ -203,7 +206,6 @@ pub fn get_downloaded_versions(list: List) -> MLE<HashMap<String, String>> { | |||
203 | 206 | ||
204 | pub fn clean_list_dir(list: &List) -> MLE<()> { | 207 | pub fn clean_list_dir(list: &List) -> MLE<()> { |
205 | let dl_path = &list.download_folder; | 208 | let dl_path = &list.download_folder; |
206 | println!(" â””Clean directory for: {}", list.id); | ||
207 | for entry in std::fs::read_dir(dl_path)? { | 209 | for entry in std::fs::read_dir(dl_path)? { |
208 | let entry = entry?; | 210 | let entry = entry?; |
209 | std::fs::remove_file(entry.path())?; | 211 | std::fs::remove_file(entry.path())?; |