summaryrefslogtreecommitdiff
path: root/src/commands/download.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-25 22:48:54 +0200
committerfxqnlr <[email protected]>2023-05-25 22:48:54 +0200
commitd8554e30029bf43dccce72e982784cd01857b0c4 (patch)
tree72b4ee26a4f980deb1165e615e47598be017e5fa /src/commands/download.rs
parent7f1a262999d7a8b7f12a97daf4b6722638dc62a1 (diff)
downloadmodlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar
modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar.gz
modlist-d8554e30029bf43dccce72e982784cd01857b0c4.zip
added mod add progress
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r--src/commands/download.rs31
1 files changed, 26 insertions, 5 deletions
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 @@
1 1
2use indicatif::MultiProgress; 2use indicatif::{MultiProgress, ProgressStyle, ProgressBar};
3 3
4use crate::{STYLE_BAR_POS, PROGRESS_CHARS};
4use crate::{config::Cfg, List}; 5use crate::{config::Cfg, List};
5use crate::{ 6use crate::{
6 db::userlist_get_all_current_versions_with_mods, 7 db::userlist_get_all_current_versions_with_mods,
@@ -14,9 +15,12 @@ use crate::{
14pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> { 15pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> {
15 16
16 let mp = MultiProgress::new(); 17 let mp = MultiProgress::new();
18 let download_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap()));
19 download_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS));
17 20
18 for current_list in liststack { 21 for current_list in liststack {
19 println!("Downloading current versions of mods in {}", current_list.id); 22 download_p.set_message(format!("Download in {}", current_list.id));
23
20 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 24 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
21 let current_version_ids = match userlist_get_all_current_versions_with_mods( 25 let current_version_ids = match userlist_get_all_current_versions_with_mods(
22 config, 26 config,
@@ -59,24 +63,41 @@ pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_ol
59 config.clone(), 63 config.clone(),
60 get_raw_versions(&config.apis.modrinth, to_download).await, 64 get_raw_versions(&config.apis.modrinth, to_download).await,
61 &mp, 65 &mp,
62 None 66 &download_p,
63 ) 67 )
64 .await?; 68 .await?;
65 } else { 69 } else {
66 println!("There are no new versions to download"); 70 download_p.println(format!("There are no new versions to download for {}", current_list.id));
67 } 71 }
68 72
69 if !to_disable.is_empty() { 73 if !to_disable.is_empty() {
74 let d_p = mp.insert_before(&download_p, ProgressBar::new(to_disable.len().try_into().unwrap()));
75 d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS));
70 for ver in to_disable { 76 for ver in to_disable {
71 if delete_old { 77 if delete_old {
72 // println!("Deleting version {} for mod {}", ver.1, ver.0); 78 d_p.set_message(format!("Delete version {}", ver.1));
79 d_p.inc(1);
73 delete_version(current_list.clone(), ver.1)?; 80 delete_version(current_list.clone(), ver.1)?;
74 } else { 81 } else {
82 d_p.set_message(format!("Disable version {}", ver.1));
83 d_p.inc(1);
75 disable_version(config, current_list.clone(), ver.1, ver.0)?; 84 disable_version(config, current_list.clone(), ver.1, ver.0)?;
76 }; 85 };
77 } 86 }
87
88 let del_msg = if delete_old {
89 "Deleted all old versions"
90 } else {
91 "Disabled all old versions"
92 };
93
94 d_p.finish_with_message(del_msg);
78 } 95 }
96
97 download_p.inc(1);
79 } 98 }
80 99
100 download_p.finish_with_message("Downloaded all lists");
101
81 Ok(()) 102 Ok(())
82} 103}