From 7f1a262999d7a8b7f12a97daf4b6722638dc62a1 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 25 May 2023 21:06:40 +0200 Subject: more progress instead of print, more references --- src/files.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/files.rs') 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::{ db::{mods_get_info, userlist_add_disabled_versions}, error::{ErrorType, MLError, MLE}, modrinth::Version, - List, PROGRESS_CHARS, + List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, STYLE_BAR_BYTE, }; -pub async fn download_versions(list: List, config: Cfg, versions: Vec) -> MLE<()> { +pub async fn download_versions(list: List, config: Cfg, versions: Vec, progress: &MultiProgress, progress_before: Option<&ProgressBar>) -> MLE<()> { let cached = get_cached_versions(&config.cache); - let mp = MultiProgress::new(); - let mut js = JoinSet::new(); - let style_spinner = ProgressStyle::with_template("{spinner:.green}{wide_msg}").unwrap(); + let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); + + let all = match progress_before { + Some(p) => progress.insert_before(p, ProgressBar::new(versions.len().try_into().unwrap())), + None => progress.add(ProgressBar::new(versions.len().try_into().unwrap())), - let all = mp.add(ProgressBar::new(versions.len().try_into().unwrap())); - all.set_style(ProgressStyle::with_template("{wide_msg}{pos}/{len} [{bar:.green/lime}]").unwrap().progress_chars(PROGRESS_CHARS)); + + }; + all.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); all.set_message("Downloading"); for ver in versions { - let p = mp.insert_before(&all, ProgressBar::new(1)); + let p = progress.insert_before(&all, ProgressBar::new(1)); p.set_style(style_spinner.clone()); js.spawn(download_version(config.clone(), list.clone(), ver, cached.clone(), p)); // 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 let size = res.content_length().expect("Couldn't get content length"); - let style_bar_byte = ProgressStyle::with_template("{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]") + let style_bar_byte = ProgressStyle::with_template(STYLE_BAR_BYTE) .unwrap() .progress_chars(PROGRESS_CHARS); @@ -203,7 +206,6 @@ pub fn get_downloaded_versions(list: List) -> MLE> { pub fn clean_list_dir(list: &List) -> MLE<()> { let dl_path = &list.download_folder; - println!(" â””Clean directory for: {}", list.id); for entry in std::fs::read_dir(dl_path)? { let entry = entry?; std::fs::remove_file(entry.path())?; -- cgit v1.2.3