diff options
author | fxqnlr <[email protected]> | 2023-05-25 22:48:54 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-25 22:48:54 +0200 |
commit | d8554e30029bf43dccce72e982784cd01857b0c4 (patch) | |
tree | 72b4ee26a4f980deb1165e615e47598be017e5fa /src/commands/update.rs | |
parent | 7f1a262999d7a8b7f12a97daf4b6722638dc62a1 (diff) | |
download | modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar.gz modlist-d8554e30029bf43dccce72e982784cd01857b0c4.zip |
added mod add progress
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r-- | src/commands/update.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs index bde6896..194bbe5 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | error::{ErrorType, MLError, MLE}, | 9 | error::{ErrorType, MLError, MLE}, |
10 | files::{clean_list_dir, delete_version, disable_version, download_versions}, | 10 | files::{clean_list_dir, delete_version, disable_version, download_versions}, |
11 | modrinth::{extract_current_version, versions, Version}, | 11 | modrinth::{extract_current_version, versions, Version}, |
12 | List, PROGRESS_CHARS, STYLE_BAR_POS, | 12 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | pub async fn update( | 15 | pub async fn update( |
@@ -23,23 +23,21 @@ pub async fn update( | |||
23 | let mp = MultiProgress::new(); | 23 | let mp = MultiProgress::new(); |
24 | 24 | ||
25 | let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | 25 | let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); |
26 | let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS); | 26 | update_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
27 | update_p.set_style(bar_style.clone()); | ||
28 | update_p.set_message("Update"); | ||
29 | 27 | ||
30 | for current_list in liststack { | 28 | for current_list in liststack { |
29 | update_p.set_message(format!("Update {}", current_list.id)); | ||
30 | |||
31 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); | 31 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); |
32 | list_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); | 32 | list_p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
33 | list_p.set_message(format!("Update {}", current_list.id)); | 33 | list_p.set_message("Update mods"); |
34 | 34 | ||
35 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; | 35 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; |
36 | 36 | ||
37 | let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); | 37 | let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); |
38 | list_u_p.set_style(bar_style.clone()); | 38 | list_u_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
39 | list_u_p.set_message(format!("Update {}", current_list.id)); | ||
40 | 39 | ||
41 | let mut current_versions: Vec<(String, String)> = vec![]; | 40 | let mut current_versions: Vec<(String, String)> = vec![]; |
42 | |||
43 | let mut updatestack: Vec<Version> = vec![]; | 41 | let mut updatestack: Vec<Version> = vec![]; |
44 | 42 | ||
45 | for id in mods { | 43 | for id in mods { |
@@ -84,7 +82,6 @@ pub async fn update( | |||
84 | } | 82 | } |
85 | 83 | ||
86 | list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id)); | 84 | list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id)); |
87 | list_p.inc(1); | ||
88 | 85 | ||
89 | if clean { | 86 | if clean { |
90 | list_p.set_message("Cleaning"); | 87 | list_p.set_message("Cleaning"); |
@@ -92,12 +89,12 @@ pub async fn update( | |||
92 | }; | 89 | }; |
93 | 90 | ||
94 | if direct_download && !updatestack.is_empty() { | 91 | if direct_download && !updatestack.is_empty() { |
95 | download_versions(current_list.clone(), config.clone(), updatestack, &mp, Some(&list_p)).await?; | 92 | download_versions(current_list.clone(), config.clone(), updatestack, &mp, &list_p).await?; |
96 | 93 | ||
97 | //Disable old versions | 94 | //Disable old versions |
98 | if !clean { | 95 | if !clean { |
99 | let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap())); | 96 | let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap())); |
100 | d_p.set_style(bar_style.clone()); | 97 | d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
101 | for ver in current_versions { | 98 | for ver in current_versions { |
102 | if delete_old { | 99 | if delete_old { |
103 | d_p.set_message(format!("Delete version {}", ver.0)); | 100 | d_p.set_message(format!("Delete version {}", ver.0)); |
@@ -119,14 +116,12 @@ pub async fn update( | |||
119 | d_p.finish_with_message(del_msg); | 116 | d_p.finish_with_message(del_msg); |
120 | } | 117 | } |
121 | }; | 118 | }; |
122 | list_p.inc(1); | ||
123 | list_p.finish_with_message(format!("Updated {}", current_list.id)); | 119 | list_p.finish_with_message(format!("Updated {}", current_list.id)); |
124 | update_p.inc(1); | 120 | update_p.inc(1); |
125 | } | 121 | } |
126 | 122 | ||
127 | update_p.finish_with_message("Updated all lists"); | 123 | update_p.finish_with_message("Updated all lists"); |
128 | 124 | ||
129 | |||
130 | Ok(()) | 125 | Ok(()) |
131 | } | 126 | } |
132 | 127 | ||