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/commands/download.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/commands/download.rs') diff --git a/src/commands/download.rs b/src/commands/download.rs index e9a96b5..7aa0156 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,6 +1,7 @@ -use indicatif::MultiProgress; +use indicatif::{MultiProgress, ProgressStyle, ProgressBar}; +use crate::{STYLE_BAR_POS, PROGRESS_CHARS}; use crate::{config::Cfg, List}; use crate::{ db::userlist_get_all_current_versions_with_mods, @@ -14,9 +15,12 @@ use crate::{ pub async fn download(config: &Cfg, liststack: Vec, clean: bool, delete_old: bool) -> MLE<()> { let mp = MultiProgress::new(); + let download_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); + download_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); for current_list in liststack { - println!("Downloading current versions of mods in {}", current_list.id); + download_p.set_message(format!("Download in {}", current_list.id)); + let downloaded_versions = get_downloaded_versions(current_list.clone())?; let current_version_ids = match userlist_get_all_current_versions_with_mods( config, @@ -59,24 +63,41 @@ pub async fn download(config: &Cfg, liststack: Vec, clean: bool, delete_ol config.clone(), get_raw_versions(&config.apis.modrinth, to_download).await, &mp, - None + &download_p, ) .await?; } else { - println!("There are no new versions to download"); + download_p.println(format!("There are no new versions to download for {}", current_list.id)); } if !to_disable.is_empty() { + let d_p = mp.insert_before(&download_p, ProgressBar::new(to_disable.len().try_into().unwrap())); + d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); for ver in to_disable { if delete_old { - // println!("Deleting version {} for mod {}", ver.1, ver.0); + d_p.set_message(format!("Delete version {}", ver.1)); + d_p.inc(1); delete_version(current_list.clone(), ver.1)?; } else { + d_p.set_message(format!("Disable version {}", ver.1)); + d_p.inc(1); disable_version(config, current_list.clone(), ver.1, ver.0)?; }; } + + let del_msg = if delete_old { + "Deleted all old versions" + } else { + "Disabled all old versions" + }; + + d_p.finish_with_message(del_msg); } + + download_p.inc(1); } + download_p.finish_with_message("Downloaded all lists"); + Ok(()) } -- cgit v1.2.3