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/modification.rs | |
parent | 7f1a262999d7a8b7f12a97daf4b6722638dc62a1 (diff) | |
download | modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar.gz modlist-d8554e30029bf43dccce72e982784cd01857b0c4.zip |
added mod add progress
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 62 |
1 files changed, 29 insertions, 33 deletions
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::{ | |||
11 | error::{ErrorType, MLError, MLE}, | 11 | error::{ErrorType, MLError, MLE}, |
12 | files::{delete_version, download_versions}, | 12 | files::{delete_version, download_versions}, |
13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, | 13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, |
14 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, | 14 | List, PROGRESS_CHARS, STYLE_BAR_POS, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | #[derive(Debug)] | 17 | #[derive(Debug)] |
@@ -43,57 +43,49 @@ pub async fn mod_add( | |||
43 | list: List, | 43 | list: List, |
44 | direct_download: bool, | 44 | direct_download: bool, |
45 | ) -> MLE<()> { | 45 | ) -> MLE<()> { |
46 | let mp = MultiProgress::new(); | ||
46 | 47 | ||
47 | //TODO MultiProgress | ||
48 | |||
49 | let spinner_style = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); | ||
50 | let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS); | ||
51 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); | 48 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); |
52 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); | 49 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); |
53 | 50 | ||
54 | let p = ProgressBar::new(mods.len().try_into().unwrap()); | 51 | let add_p = mp.add(ProgressBar::new(mods.len().try_into().unwrap())); |
55 | p.set_style(spinner_style.clone()); | 52 | add_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
56 | p.set_message("Sort ids"); | 53 | add_p.set_message("Sort ids"); |
57 | 54 | ||
58 | //"Sort" project ids from version ids to be able to handle them differently but in a batch | 55 | //"Sort" project ids from version ids to be able to handle them differently but in a batch |
59 | for m in mods { | 56 | for m in mods { |
60 | p.inc(1); | 57 | add_p.inc(1); |
61 | match m.id { | 58 | match m.id { |
62 | IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), | 59 | IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), |
63 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), | 60 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), |
64 | } | 61 | } |
65 | } | 62 | } |
63 | |||
64 | add_p.set_message("Get infos"); | ||
66 | 65 | ||
67 | p.finish_with_message("Sort ids done"); | ||
68 | |||
69 | let info_p = ProgressBar::new(2); | ||
70 | info_p.set_message("Get infos"); | ||
71 | info_p.set_style(bar_style.clone()); | ||
72 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); | 66 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); |
73 | if !mod_ids.is_empty() { | 67 | if !mod_ids.is_empty() { |
74 | projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); | 68 | projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); |
75 | info_p.inc(1); | ||
76 | }; | 69 | }; |
77 | if !ver_ids.is_empty() { | 70 | if !ver_ids.is_empty() { |
78 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); | 71 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); |
79 | info_p.inc(1); | ||
80 | }; | 72 | }; |
81 | 73 | ||
82 | info_p.finish_with_message("Get infos done"); | ||
83 | |||
84 | if projectinfo.is_empty() { | 74 | if projectinfo.is_empty() { |
85 | return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); | 75 | return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); |
86 | }; | 76 | }; |
87 | 77 | ||
78 | add_p.set_message("Add mods to database"); | ||
79 | |||
88 | let mut downloadstack: Vec<Version> = Vec::new(); | 80 | let mut downloadstack: Vec<Version> = Vec::new(); |
89 | 81 | ||
90 | //Adding each mod to the lists and downloadstack | 82 | //Adding each mod to the lists and downloadstack |
91 | let add_p = ProgressBar::new(projectinfo.len().try_into().unwrap()); | 83 | let project_p = mp.insert_before(&add_p, ProgressBar::new(projectinfo.len().try_into().unwrap())); |
92 | add_p.set_style(bar_style); | 84 | project_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
93 | 85 | ||
94 | for project in projectinfo { | 86 | for project in projectinfo { |
95 | 87 | ||
96 | add_p.set_message(format!("Add {}", project.title)); | 88 | project_p.set_message(format!("Add {}", project.title)); |
97 | 89 | ||
98 | let current_version_id = if project.current_version.is_none() { | 90 | let current_version_id = if project.current_version.is_none() { |
99 | String::from("NONE") | 91 | String::from("NONE") |
@@ -144,18 +136,19 @@ pub async fn mod_add( | |||
144 | downloadstack.push(project.current_version.unwrap()) | 136 | downloadstack.push(project.current_version.unwrap()) |
145 | }; | 137 | }; |
146 | 138 | ||
147 | // add_p.println(format!("Added {}", project.title)); | 139 | project_p.inc(1); |
148 | add_p.inc(1); | ||
149 | } | 140 | } |
150 | 141 | ||
151 | add_p.finish_with_message("Added all mods"); | 142 | project_p.finish_with_message("Added all mods to the database"); |
152 | 143 | ||
153 | //Download all the added mods | 144 | //Download all the added mods |
154 | if direct_download { | 145 | if direct_download { |
155 | let mp = MultiProgress::new(); | 146 | add_p.set_message("Download mods"); |
156 | download_versions(list.clone(), config.clone(), downloadstack, &mp, None).await?; | 147 | download_versions(list.clone(), config.clone(), downloadstack, &mp, &add_p).await?; |
157 | }; | 148 | }; |
158 | 149 | ||
150 | add_p.finish_with_message("Added all mods"); | ||
151 | |||
159 | Ok(()) | 152 | Ok(()) |
160 | } | 153 | } |
161 | 154 | ||
@@ -277,14 +270,17 @@ async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE<Vec<Pro | |||
277 | 270 | ||
278 | for (i, project) in v_projects.into_iter().enumerate() { | 271 | for (i, project) in v_projects.into_iter().enumerate() { |
279 | let version = &v_versions[i]; | 272 | let version = &v_versions[i]; |
280 | // println!("\tâ””{}({})", project.title, version.id); | 273 | |
281 | let file = version | 274 | let files = version |
282 | .clone() | 275 | .clone() |
283 | .files | 276 | .files; |
284 | .into_iter() | 277 | |
285 | .find(|f| f.primary) | 278 | let file = match files.clone().into_iter().find(|f| f.primary) { |
286 | .unwrap() | 279 | Some(f) => f, |
280 | None => { files[0].clone() } | ||
281 | } | ||
287 | .url; | 282 | .url; |
283 | |||
288 | projectinfo.push(ProjectInfo { | 284 | projectinfo.push(ProjectInfo { |
289 | mod_id: String::from(&project.id), | 285 | mod_id: String::from(&project.id), |
290 | slug: project.slug, | 286 | slug: project.slug, |