From d8554e30029bf43dccce72e982784cd01857b0c4 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 25 May 2023 22:48:54 +0200 Subject: added mod add progress --- src/files.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 2830a5f..814f06d 100644 --- a/src/files.rs +++ b/src/files.rs @@ -14,37 +14,29 @@ use crate::{ db::{mods_get_info, userlist_add_disabled_versions}, error::{ErrorType, MLError, MLE}, modrinth::Version, - List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, STYLE_BAR_BYTE, + List, PROGRESS_CHARS, STYLE_SPINNER, STYLE_BAR_BYTE, STYLE_BAR_POS, }; -pub async fn download_versions(list: List, config: Cfg, versions: Vec, progress: &MultiProgress, progress_before: Option<&ProgressBar>) -> MLE<()> { +pub async fn download_versions(list: List, config: Cfg, versions: Vec, progress: &MultiProgress, progress_before: &ProgressBar) -> MLE<()> { let cached = get_cached_versions(&config.cache); let mut js = JoinSet::new(); 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 = progress.insert_before(progress_before, ProgressBar::new(versions.len().try_into().unwrap())); all.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); - all.set_message("Downloading"); + all.set_message(format!("✓Downloading {}", list.id)); for ver in versions { 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)); } while js.join_next().await.is_some() { all.inc(1) } - all.finish(); - - // mp.clear().unwrap(); + all.finish_with_message(format!("✓Downloading {}", list.id)); Ok(()) } @@ -56,10 +48,12 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: progress.set_message(format!("{} - {}", project_info.title, version.id)); + let mut cache_msg = ""; //Check cache if already downloaded let c = cached.remove(&version.id); if c.is_some() { progress.set_message(format!("Get {} from cache", version.id)); + cache_msg = " (cached)"; copy_cached_version(&c.unwrap(), &dl_path); } else { let files = version.files; @@ -95,7 +89,7 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: copy(dl_path_file, cache_path)?; } - progress.finish_with_message(format!("✓{} - {}", project_info.title, version.id)); + progress.finish_with_message(format!("✓{} - {}{}", project_info.title, version.id, cache_msg)); Ok(()) } -- cgit v1.2.3