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/modification.rs | 62 +++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index d369c4b..8abf913 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -11,7 +11,7 @@ use crate::{ error::{ErrorType, MLError, MLE}, files::{delete_version, download_versions}, modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, - List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, + List, PROGRESS_CHARS, STYLE_BAR_POS, }; #[derive(Debug)] @@ -43,57 +43,49 @@ pub async fn mod_add( list: List, direct_download: bool, ) -> MLE<()> { + let mp = MultiProgress::new(); - //TODO MultiProgress - - let spinner_style = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); - let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS); let mut mod_ids: Vec<(String, bool)> = Vec::new(); let mut ver_ids: Vec<(String, bool)> = Vec::new(); - - let p = ProgressBar::new(mods.len().try_into().unwrap()); - p.set_style(spinner_style.clone()); - p.set_message("Sort ids"); + + let add_p = mp.add(ProgressBar::new(mods.len().try_into().unwrap())); + add_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + add_p.set_message("Sort ids"); //"Sort" project ids from version ids to be able to handle them differently but in a batch for m in mods { - p.inc(1); + add_p.inc(1); match m.id { IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), } } + + add_p.set_message("Get infos"); - p.finish_with_message("Sort ids done"); - - let info_p = ProgressBar::new(2); - info_p.set_message("Get infos"); - info_p.set_style(bar_style.clone()); let mut projectinfo: Vec = Vec::new(); if !mod_ids.is_empty() { projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); - info_p.inc(1); }; if !ver_ids.is_empty() { projectinfo.append(&mut get_ver_info(config, ver_ids).await?); - info_p.inc(1); }; - info_p.finish_with_message("Get infos done"); - if projectinfo.is_empty() { return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); }; + add_p.set_message("Add mods to database"); + let mut downloadstack: Vec = Vec::new(); //Adding each mod to the lists and downloadstack - let add_p = ProgressBar::new(projectinfo.len().try_into().unwrap()); - add_p.set_style(bar_style); + let project_p = mp.insert_before(&add_p, ProgressBar::new(projectinfo.len().try_into().unwrap())); + project_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); for project in projectinfo { - add_p.set_message(format!("Add {}", project.title)); + project_p.set_message(format!("Add {}", project.title)); let current_version_id = if project.current_version.is_none() { String::from("NONE") @@ -144,18 +136,19 @@ pub async fn mod_add( downloadstack.push(project.current_version.unwrap()) }; - // add_p.println(format!("Added {}", project.title)); - add_p.inc(1); + project_p.inc(1); } - add_p.finish_with_message("Added all mods"); + project_p.finish_with_message("Added all mods to the database"); //Download all the added mods if direct_download { - let mp = MultiProgress::new(); - download_versions(list.clone(), config.clone(), downloadstack, &mp, None).await?; + add_p.set_message("Download mods"); + download_versions(list.clone(), config.clone(), downloadstack, &mp, &add_p).await?; }; + add_p.finish_with_message("Added all mods"); + Ok(()) } @@ -277,14 +270,17 @@ async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE f, + None => { files[0].clone() } + } .url; + projectinfo.push(ProjectInfo { mod_id: String::from(&project.id), slug: project.slug, -- cgit v1.2.3