summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-29 18:01:12 +0200
committerfxqnlr <[email protected]>2023-05-29 18:01:12 +0200
commitc7ecf3019a75dc0ab1a0aefeb9b880899fc8a231 (patch)
tree116075aaa57c35afca2749719d450c3cb473ab3e /src/commands/update.rs
parent7755c9acf6b8a1d81c03ef1138e80a162f36e743 (diff)
downloadmodlist-c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231.tar
modlist-c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231.tar.gz
modlist-c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231.zip
cargo fmt and add fmt file
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 3aae002..c19c02c 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -4,10 +4,13 @@ use crate::{
4 config::Cfg, 4 config::Cfg,
5 db::{ 5 db::{
6 mods_get_info, userlist_change_versions, userlist_get_all_ids, 6 mods_get_info, userlist_change_versions, userlist_get_all_ids,
7 userlist_get_applicable_versions, userlist_get_current_version, userlist_get_set_version, 7 userlist_get_applicable_versions, userlist_get_current_version,
8 userlist_get_set_version,
8 }, 9 },
9 error::{ErrorType, MLError, MLE}, 10 error::{ErrorType, MLError, MLE},
10 files::{clean_list_dir, delete_version, disable_version, download_versions}, 11 files::{
12 clean_list_dir, delete_version, disable_version, download_versions,
13 },
11 modrinth::{extract_current_version, versions, Version}, 14 modrinth::{extract_current_version, versions, Version},
12 List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, 15 List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION,
13}; 16};
@@ -21,7 +24,8 @@ pub async fn update(
21) -> MLE<()> { 24) -> MLE<()> {
22 let mp = MultiProgress::new(); 25 let mp = MultiProgress::new();
23 26
24 let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); 27 let update_p =
28 mp.add(ProgressBar::new(liststack.len().try_into().unwrap()));
25 update_p.set_style( 29 update_p.set_style(
26 ProgressStyle::with_template(STYLE_BAR_POS) 30 ProgressStyle::with_template(STYLE_BAR_POS)
27 .unwrap() 31 .unwrap()
@@ -32,12 +36,16 @@ pub async fn update(
32 update_p.set_message(format!("Update {}", current_list.id)); 36 update_p.set_message(format!("Update {}", current_list.id));
33 37
34 let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); 38 let list_p = mp.insert_before(&update_p, ProgressBar::new(2));
35 list_p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); 39 list_p
40 .set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap());
36 list_p.set_message("Update mods"); 41 list_p.set_message("Update mods");
37 42
38 let mods = userlist_get_all_ids(config, &current_list.id)?; 43 let mods = userlist_get_all_ids(config, &current_list.id)?;
39 44
40 let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); 45 let list_u_p = mp.insert_before(
46 &list_p,
47 ProgressBar::new(mods.len().try_into().unwrap()),
48 );
41 list_u_p.set_style( 49 list_u_p.set_style(
42 ProgressStyle::with_template(STYLE_BAR_POS) 50 ProgressStyle::with_template(STYLE_BAR_POS)
43 .unwrap() 51 .unwrap()
@@ -58,10 +66,19 @@ pub async fn update(
58 } 66 }
59 67
60 //Getting current installed version for disable or delete 68 //Getting current installed version for disable or delete
61 let disable_version = userlist_get_current_version(config, &current_list.id, &id)?; 69 let disable_version =
70 userlist_get_current_version(config, &current_list.id, &id)?;
62 71
63 updatestack.push( 72 updatestack.push(
64 match specific_update(config, clean, current_list.clone(), &id, &list_u_p).await { 73 match specific_update(
74 config,
75 clean,
76 current_list.clone(),
77 &id,
78 &list_u_p,
79 )
80 .await
81 {
65 Ok(ver) => { 82 Ok(ver) => {
66 current_versions.push((disable_version, id)); 83 current_versions.push((disable_version, id));
67 ver 84 ver
@@ -79,7 +96,10 @@ pub async fn update(
79 list_u_p.inc(1); 96 list_u_p.inc(1);
80 } 97 }
81 98
82 list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id)); 99 list_u_p.finish_with_message(format!(
100 "Updated mods in {}",
101 current_list.id
102 ));
83 103
84 if clean { 104 if clean {
85 list_p.set_message("Cleaning"); 105 list_p.set_message("Cleaning");
@@ -100,7 +120,9 @@ pub async fn update(
100 if !clean { 120 if !clean {
101 let d_p = mp.insert_before( 121 let d_p = mp.insert_before(
102 &list_p, 122 &list_p,
103 ProgressBar::new(current_versions.len().try_into().unwrap()), 123 ProgressBar::new(
124 current_versions.len().try_into().unwrap(),
125 ),
104 ); 126 );
105 d_p.set_style( 127 d_p.set_style(
106 ProgressStyle::with_template(STYLE_BAR_POS) 128 ProgressStyle::with_template(STYLE_BAR_POS)
@@ -115,7 +137,12 @@ pub async fn update(
115 } else if ver.0 != "NONE" { 137 } else if ver.0 != "NONE" {
116 d_p.set_message(format!("Disable version {}", ver.0)); 138 d_p.set_message(format!("Disable version {}", ver.0));
117 d_p.inc(1); 139 d_p.inc(1);
118 disable_version(config, current_list.clone(), ver.0, ver.1)?; 140 disable_version(
141 config,
142 current_list.clone(),
143 ver.0,
144 ver.1,
145 )?;
119 }; 146 };
120 } 147 }
121 148
@@ -144,7 +171,8 @@ async fn specific_update(
144 id: &str, 171 id: &str,
145 progress: &ProgressBar, 172 progress: &ProgressBar,
146) -> MLE<Version> { 173) -> MLE<Version> {
147 let applicable_versions = versions(&config.apis.modrinth, String::from(id), list.clone()).await; 174 let applicable_versions =
175 versions(&config.apis.modrinth, String::from(id), list.clone()).await;
148 176
149 let mut versions: Vec<String> = vec![]; 177 let mut versions: Vec<String> = vec![];
150 178
@@ -159,7 +187,11 @@ async fn specific_update(
159 let mut current: Vec<Version> = vec![]; 187 let mut current: Vec<Version> = vec![];
160 if clean 188 if clean
161 || (versions.join("|") 189 || (versions.join("|")
162 != userlist_get_applicable_versions(config, String::from(&list.id), String::from(id))?) 190 != userlist_get_applicable_versions(
191 config,
192 String::from(&list.id),
193 String::from(id),
194 )?)
163 { 195 {
164 let current_str = extract_current_version(applicable_versions.clone())?; 196 let current_str = extract_current_version(applicable_versions.clone())?;
165 197