summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-25 21:06:40 +0200
committerfxqnlr <[email protected]>2023-05-25 21:06:40 +0200
commit7f1a262999d7a8b7f12a97daf4b6722638dc62a1 (patch)
treec030a952891fba2f64427adad1113efc567ae54d /src/commands/update.rs
parent48393b209396db9ddd44251b2bb445d3ad7533fb (diff)
downloadmodlist-7f1a262999d7a8b7f12a97daf4b6722638dc62a1.tar
modlist-7f1a262999d7a8b7f12a97daf4b6722638dc62a1.tar.gz
modlist-7f1a262999d7a8b7f12a97daf4b6722638dc62a1.zip
more progress instead of print, more references
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs123
1 files changed, 36 insertions, 87 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 7482e43..bde6896 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, 12 List, PROGRESS_CHARS, STYLE_BAR_POS,
13}; 13};
14 14
15pub async fn update( 15pub async fn update(
@@ -23,35 +23,32 @@ 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("{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]").unwrap().progress_chars(PROGRESS_CHARS); 26 let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS);
27 let spinner_style = ProgressStyle::with_template("{spinner:.green}{msg}").unwrap();
28 update_p.set_style(bar_style.clone()); 27 update_p.set_style(bar_style.clone());
29 update_p.set_message("Update"); 28 update_p.set_message("Update");
30 29
31 for current_list in liststack { 30 for current_list in liststack {
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));
33 list_p.set_message(format!("Update {}", current_list.id));
32 34
33 // println!("Update mods in {}", current_list.id);
34 let mods = userlist_get_all_ids(config, &current_list.id)?; 35 let mods = userlist_get_all_ids(config, &current_list.id)?;
35 36
36 let list_p = mp.insert_before(&update_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()));
37 list_p.set_style(bar_style.clone()); 38 list_u_p.set_style(bar_style.clone());
38 list_p.set_message(format!("Update {}", current_list.id)); 39 list_u_p.set_message(format!("Update {}", current_list.id));
39 40
40 let mut current_versions: Vec<(String, String)> = vec![]; 41 let mut current_versions: Vec<(String, String)> = vec![];
41 42
42 let mut updatestack: Vec<Version> = vec![]; 43 let mut updatestack: Vec<Version> = vec![];
43 44
44 for id in mods { 45 for id in mods {
45 let mod_p = mp.insert_before(&list_p, ProgressBar::new(1));
46 mod_p.set_style(spinner_style.clone());
47
48 let info = mods_get_info(config, &id)?; 46 let info = mods_get_info(config, &id)?;
49 mod_p.set_message(format!("Update {}", info.title)); 47 list_u_p.set_message(format!("Update {}", info.title));
50 // println!(" ├{}", info.title); 48
51 49 //Skip check if version is set
52 if userlist_get_set_version(config, &current_list.id, &id)? { 50 if userlist_get_set_version(config, &current_list.id, &id)? {
53 // println!(" │ └Set version, skipping update"); 51 list_u_p.inc(1);
54 list_p.inc(1);
55 continue; 52 continue;
56 } 53 }
57 54
@@ -59,15 +56,13 @@ pub async fn update(
59 let disable_version = 56 let disable_version =
60 userlist_get_current_version(config, &current_list.id, &id)?; 57 userlist_get_current_version(config, &current_list.id, &id)?;
61 58
62 mod_p.inc(1);
63
64 updatestack.push( 59 updatestack.push(
65 match specific_update( 60 match specific_update(
66 config, 61 config,
67 clean, 62 clean,
68 current_list.clone(), 63 current_list.clone(),
69 &id, 64 &id,
70 &mod_p 65 &list_u_p
71 ) 66 )
72 .await 67 .await
73 { 68 {
@@ -77,44 +72,55 @@ pub async fn update(
77 } 72 }
78 Err(e) => { 73 Err(e) => {
79 if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" { 74 if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" {
80 // println!(
81 // " │ └No new version found for the specified minecraft version"
82 // );
83 } else { 75 } else {
84 return Err(e); 76 return Err(e);
85 }; 77 };
86 list_p.inc(1); 78 list_u_p.inc(1);
87 continue; 79 continue;
88 } 80 }
89 }, 81 },
90 ); 82 );
91 list_p.inc(1); 83 list_u_p.inc(1);
92 } 84 }
93 85
94 list_p.finish_with_message(format!("Updated {}", current_list.id)); 86 list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id));
87 list_p.inc(1);
95 88
96 if clean { 89 if clean {
97 update_p.set_message("Cleaning"); 90 list_p.set_message("Cleaning");
98 update_p.inc(1);
99 clean_list_dir(&current_list)?; 91 clean_list_dir(&current_list)?;
100 }; 92 };
101 93
102 if direct_download && !updatestack.is_empty() { 94 if direct_download && !updatestack.is_empty() {
103 download_versions(current_list.clone(), config.clone(), updatestack).await?; 95 download_versions(current_list.clone(), config.clone(), updatestack, &mp, Some(&list_p)).await?;
104 96
105 //Disable old versions 97 //Disable old versions
106 if !clean { 98 if !clean {
99 let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap()));
100 d_p.set_style(bar_style.clone());
107 for ver in current_versions { 101 for ver in current_versions {
108 if delete_old { 102 if delete_old {
109 println!(" └Delete version {}", ver.0); 103 d_p.set_message(format!("Delete version {}", ver.0));
104 d_p.inc(1);
110 delete_version(current_list.clone(), ver.0)?; 105 delete_version(current_list.clone(), ver.0)?;
111 } else if ver.0 != "NONE" { 106 } else if ver.0 != "NONE" {
112 println!(" └Disable version {}", ver.0); 107 d_p.set_message(format!("Disable version {}", ver.0));
108 d_p.inc(1);
113 disable_version(config, current_list.clone(), ver.0, ver.1)?; 109 disable_version(config, current_list.clone(), ver.0, ver.1)?;
114 }; 110 };
115 } 111 }
112
113 let del_msg = if delete_old {
114 "Deleted all old versions"
115 } else {
116 "Disabled all old versions"
117 };
118
119 d_p.finish_with_message(del_msg);
116 } 120 }
117 }; 121 };
122 list_p.inc(1);
123 list_p.finish_with_message(format!("Updated {}", current_list.id));
118 update_p.inc(1); 124 update_p.inc(1);
119 } 125 }
120 126
@@ -149,13 +155,7 @@ async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progre
149 { 155 {
150 let current_str = extract_current_version(applicable_versions.clone())?; 156 let current_str = extract_current_version(applicable_versions.clone())?;
151 157
152 if clean { 158 if !clean { progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title)); }
153 // println!("\t └Add version to downloadstack");
154 } else {
155 progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title));
156 // println!("\t └Get versions for specified minecraft versions");
157 // println!("\t └New current version: {}", current_str);
158 };
159 159
160 //get new versions 160 //get new versions
161 let current_ver = match applicable_versions 161 let current_ver = match applicable_versions
@@ -183,56 +183,5 @@ async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progre
183 return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")); 183 return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE"));
184 }; 184 };
185 185
186 //println!(" └✔️");
187 Ok(current[0].clone()) 186 Ok(current[0].clone())
188} 187}
189
190// #[tokio::test]
191// async fn download_updates_test() {
192// use crate::{
193// modrinth::{Hash, Version, VersionFile, VersionType},
194// List, Modloader,
195// };
196//
197// let config = Cfg::init().unwrap();
198// let current_list = List {
199// id: String::from("..."),
200// mc_version: String::from("..."),
201// modloader: Modloader::Fabric,
202// download_folder: String::from("./dev/tests/dl"),
203// };
204//
205// let versions = vec![Version {
206// id: "dEqtGnT9".to_string(),
207// project_id: "kYuIpRLv".to_string(),
208// author_id: "Qnt13hO8".to_string(),
209// featured: true,
210// name: "1.2.2-1.19 - Fabric".to_string(),
211// version_number: "1.2.2-1.19".to_string(),
212// changelog: None,
213// date_published: "2022-11-02T17:41:43.072267Z".to_string(),
214// downloads: 58,
215// version_type: VersionType::release,
216// files: vec![VersionFile {
217// hashes: Hash {
218// sha1: "fdc6dc39427fc92cc1d7ad8b275b5b83325e712b".to_string(),
219// sha512: "5b372f00d6e5d6a5ef225c3897826b9f6a2be5506905f7f71b9e939779765b41be6f2a9b029cfc752ad0751d0d2d5f8bb4544408df1363eebdde15641e99a849".to_string()
220// },
221// url: "https://cdn.modrinth.com/data/kYuIpRLv/versions/dEqtGnT9/waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(),
222// filename: "waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(),
223// primary: true,
224// size: 323176
225// }],
226// game_versions: vec![
227// "1.19".to_string(),
228// "1.19.1".to_string(),
229// "1.19.2".to_string()
230// ],
231// loaders: vec![
232// "fabric".to_string()
233// ]
234// }];
235// assert!(download_versions(current_list, config, versions)
236// .await
237// .is_ok())
238// }