diff options
author | fxqnlr <[email protected]> | 2023-05-29 18:01:12 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-29 18:01:12 +0200 |
commit | c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231 (patch) | |
tree | 116075aaa57c35afca2749719d450c3cb473ab3e /src/commands | |
parent | 7755c9acf6b8a1d81c03ef1138e80a162f36e743 (diff) | |
download | modlist-c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231.tar modlist-c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231.tar.gz modlist-c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231.zip |
cargo fmt and add fmt file
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/download.rs | 39 | ||||
-rw-r--r-- | src/commands/io.rs | 6 | ||||
-rw-r--r-- | src/commands/list.rs | 4 | ||||
-rw-r--r-- | src/commands/modification.rs | 55 | ||||
-rw-r--r-- | src/commands/update.rs | 56 |
5 files changed, 121 insertions, 39 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index dd00ffb..a7cf744 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -5,7 +5,8 @@ use crate::{ | |||
5 | db::userlist_get_all_current_versions_with_mods, | 5 | db::userlist_get_all_current_versions_with_mods, |
6 | error::{ErrorType, MLError, MLE}, | 6 | error::{ErrorType, MLError, MLE}, |
7 | files::{ | 7 | files::{ |
8 | clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, | 8 | clean_list_dir, delete_version, disable_version, download_versions, |
9 | get_downloaded_versions, | ||
9 | }, | 10 | }, |
10 | modrinth::get_raw_versions, | 11 | modrinth::get_raw_versions, |
11 | }; | 12 | }; |
@@ -18,7 +19,8 @@ pub async fn download( | |||
18 | delete_old: bool, | 19 | delete_old: bool, |
19 | ) -> MLE<()> { | 20 | ) -> MLE<()> { |
20 | let mp = MultiProgress::new(); | 21 | let mp = MultiProgress::new(); |
21 | let download_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | 22 | let download_p = |
23 | mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | ||
22 | download_p.set_style( | 24 | download_p.set_style( |
23 | ProgressStyle::with_template(STYLE_BAR_POS) | 25 | ProgressStyle::with_template(STYLE_BAR_POS) |
24 | .unwrap() | 26 | .unwrap() |
@@ -28,14 +30,19 @@ pub async fn download( | |||
28 | for current_list in liststack { | 30 | for current_list in liststack { |
29 | download_p.set_message(format!("Download in {}", current_list.id)); | 31 | download_p.set_message(format!("Download in {}", current_list.id)); |
30 | 32 | ||
31 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 33 | let downloaded_versions = |
32 | let current_version_ids = match userlist_get_all_current_versions_with_mods( | 34 | get_downloaded_versions(current_list.clone())?; |
33 | config, | 35 | let current_version_ids = |
34 | String::from(¤t_list.id), | 36 | match userlist_get_all_current_versions_with_mods( |
35 | ) { | 37 | config, |
36 | Ok(i) => Ok(i), | 38 | String::from(¤t_list.id), |
37 | Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), | 39 | ) { |
38 | }?; | 40 | Ok(i) => Ok(i), |
41 | Err(e) => Err(MLError::new( | ||
42 | ErrorType::DBError, | ||
43 | e.to_string().as_str(), | ||
44 | )), | ||
45 | }?; | ||
39 | 46 | ||
40 | let mut to_download: Vec<String> = vec![]; | 47 | let mut to_download: Vec<String> = vec![]; |
41 | //(mod_id, version_id) | 48 | //(mod_id, version_id) |
@@ -54,7 +61,10 @@ pub async fn download( | |||
54 | .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") | 61 | .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") |
55 | .unwrap(); | 62 | .unwrap(); |
56 | if ¤t_version != downloaded_version { | 63 | if ¤t_version != downloaded_version { |
57 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); | 64 | to_disable.push(( |
65 | mod_id.clone(), | ||
66 | String::from(downloaded_version), | ||
67 | )); | ||
58 | to_download.push(current_version); | 68 | to_download.push(current_version); |
59 | } | 69 | } |
60 | } | 70 | } |
@@ -98,7 +108,12 @@ pub async fn download( | |||
98 | } else { | 108 | } else { |
99 | d_p.set_message(format!("Disable version {}", ver.1)); | 109 | d_p.set_message(format!("Disable version {}", ver.1)); |
100 | d_p.inc(1); | 110 | d_p.inc(1); |
101 | disable_version(config, current_list.clone(), ver.1, ver.0)?; | 111 | disable_version( |
112 | config, | ||
113 | current_list.clone(), | ||
114 | ver.1, | ||
115 | ver.0, | ||
116 | )?; | ||
102 | }; | 117 | }; |
103 | } | 118 | } |
104 | 119 | ||
diff --git a/src/commands/io.rs b/src/commands/io.rs index 2501583..8e44b2b 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -102,7 +102,11 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
102 | Ok(()) | 102 | Ok(()) |
103 | } | 103 | } |
104 | 104 | ||
105 | pub async fn import(config: &Cfg, file_str: &str, direct_download: bool) -> MLE<()> { | 105 | pub async fn import( |
106 | config: &Cfg, | ||
107 | file_str: &str, | ||
108 | direct_download: bool, | ||
109 | ) -> MLE<()> { | ||
106 | let mut file = File::open(file_str)?; | 110 | let mut file = File::open(file_str)?; |
107 | let mut content = String::new(); | 111 | let mut content = String::new(); |
108 | file.read_to_string(&mut content)?; | 112 | file.read_to_string(&mut content)?; |
diff --git a/src/commands/list.rs b/src/commands/list.rs index b0a082d..3665446 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -3,8 +3,8 @@ use indicatif::{ProgressBar, ProgressStyle}; | |||
3 | use crate::{ | 3 | use crate::{ |
4 | config::Cfg, | 4 | config::Cfg, |
5 | db::{ | 5 | db::{ |
6 | config_change_current_list, config_get_current_list, lists_get, lists_get_all_ids, | 6 | config_change_current_list, config_get_current_list, lists_get, |
7 | lists_insert, lists_remove, lists_version, | 7 | lists_get_all_ids, lists_insert, lists_remove, lists_version, |
8 | }, | 8 | }, |
9 | error::{ErrorType, MLError, MLE}, | 9 | error::{ErrorType, MLError, MLE}, |
10 | update, Modloader, STYLE_OPERATION, | 10 | update, Modloader, STYLE_OPERATION, |
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 577bbd1..4488b70 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -5,12 +5,16 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | |||
5 | use crate::{ | 5 | use crate::{ |
6 | config::Cfg, | 6 | config::Cfg, |
7 | db::{ | 7 | db::{ |
8 | lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, mods_remove, | 8 | lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, |
9 | userlist_get_all_ids, userlist_get_current_version, userlist_insert, userlist_remove, | 9 | mods_remove, userlist_get_all_ids, userlist_get_current_version, |
10 | userlist_insert, userlist_remove, | ||
10 | }, | 11 | }, |
11 | error::{ErrorType, MLError, MLE}, | 12 | error::{ErrorType, MLError, MLE}, |
12 | files::{delete_version, download_versions}, | 13 | files::{delete_version, download_versions}, |
13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, | 14 | modrinth::{ |
15 | extract_current_version, get_raw_versions, project, projects, versions, | ||
16 | Version, | ||
17 | }, | ||
14 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, | 18 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, |
15 | }; | 19 | }; |
16 | 20 | ||
@@ -60,7 +64,9 @@ pub async fn mod_add( | |||
60 | for m in mods { | 64 | for m in mods { |
61 | add_p.inc(1); | 65 | add_p.inc(1); |
62 | match m.id { | 66 | match m.id { |
63 | IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), | 67 | IDSelector::ModificationID(pid) => { |
68 | mod_ids.push((pid, m.set_version)) | ||
69 | } | ||
64 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), | 70 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), |
65 | } | 71 | } |
66 | } | 72 | } |
@@ -69,7 +75,8 @@ pub async fn mod_add( | |||
69 | 75 | ||
70 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); | 76 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); |
71 | if !mod_ids.is_empty() { | 77 | if !mod_ids.is_empty() { |
72 | projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); | 78 | projectinfo |
79 | .append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); | ||
73 | }; | 80 | }; |
74 | if !ver_ids.is_empty() { | 81 | if !ver_ids.is_empty() { |
75 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); | 82 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); |
@@ -113,7 +120,10 @@ pub async fn mod_add( | |||
113 | project.set_version, | 120 | project.set_version, |
114 | ) { | 121 | ) { |
115 | Err(e) => { | 122 | Err(e) => { |
116 | let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); | 123 | let expected_err = format!( |
124 | "SQL: UNIQUE constraint failed: {}.mod_id", | ||
125 | list.id | ||
126 | ); | ||
117 | if e.to_string() == expected_err { | 127 | if e.to_string() == expected_err { |
118 | Err(MLError::new( | 128 | Err(MLError::new( |
119 | ErrorType::ModError, | 129 | ErrorType::ModError, |
@@ -126,7 +136,12 @@ pub async fn mod_add( | |||
126 | Ok(..) => Ok(..), | 136 | Ok(..) => Ok(..), |
127 | }?; | 137 | }?; |
128 | 138 | ||
129 | match mods_insert(config, &project.mod_id, &project.slug, &project.title) { | 139 | match mods_insert( |
140 | config, | ||
141 | &project.mod_id, | ||
142 | &project.slug, | ||
143 | &project.title, | ||
144 | ) { | ||
130 | Err(e) => { | 145 | Err(e) => { |
131 | if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { | 146 | if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { |
132 | Ok(..) | 147 | Ok(..) |
@@ -149,7 +164,14 @@ pub async fn mod_add( | |||
149 | //Download all the added mods | 164 | //Download all the added mods |
150 | if direct_download { | 165 | if direct_download { |
151 | add_p.set_message("Download mods"); | 166 | add_p.set_message("Download mods"); |
152 | download_versions(list.clone(), config.clone(), downloadstack, &mp, &add_p).await?; | 167 | download_versions( |
168 | list.clone(), | ||
169 | config.clone(), | ||
170 | downloadstack, | ||
171 | &mp, | ||
172 | &add_p, | ||
173 | ) | ||
174 | .await?; | ||
153 | }; | 175 | }; |
154 | 176 | ||
155 | add_p.finish_with_message("Added all mods"); | 177 | add_p.finish_with_message("Added all mods"); |
@@ -191,7 +213,8 @@ async fn get_mod_infos( | |||
191 | let current_version: Option<Version>; | 213 | let current_version: Option<Version>; |
192 | let file: String; | 214 | let file: String; |
193 | if !available_versions.is_empty() { | 215 | if !available_versions.is_empty() { |
194 | let current_id = extract_current_version(available_versions.clone())?; | 216 | let current_id = |
217 | extract_current_version(available_versions.clone())?; | ||
195 | 218 | ||
196 | current_version = Some( | 219 | current_version = Some( |
197 | available_versions | 220 | available_versions |
@@ -242,7 +265,10 @@ async fn get_mod_infos( | |||
242 | Ok(projectinfo) | 265 | Ok(projectinfo) |
243 | } | 266 | } |
244 | 267 | ||
245 | async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE<Vec<ProjectInfo>> { | 268 | async fn get_ver_info( |
269 | config: &Cfg, | ||
270 | ver_ids: Vec<(String, bool)>, | ||
271 | ) -> MLE<Vec<ProjectInfo>> { | ||
246 | let mut setmap: HashMap<String, bool> = HashMap::new(); | 272 | let mut setmap: HashMap<String, bool> = HashMap::new(); |
247 | 273 | ||
248 | let mut ids = vec![]; | 274 | let mut ids = vec![]; |
@@ -311,7 +337,9 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { | |||
311 | match delete_version(list, version) { | 337 | match delete_version(list, version) { |
312 | Ok(_) => (), | 338 | Ok(_) => (), |
313 | Err(err) => { | 339 | Err(err) => { |
314 | if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" { | 340 | if err.to_string() |
341 | != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" | ||
342 | { | ||
315 | return Err(err); | 343 | return Err(err); |
316 | }; | 344 | }; |
317 | } | 345 | } |
@@ -343,7 +371,10 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { | |||
343 | mods_remove(config, &mod_id)?; | 371 | mods_remove(config, &mod_id)?; |
344 | }; | 372 | }; |
345 | 373 | ||
346 | progress.finish_with_message(format!("Removed {} from {}", info.title, list.id)); | 374 | progress.finish_with_message(format!( |
375 | "Removed {} from {}", | ||
376 | info.title, list.id | ||
377 | )); | ||
347 | 378 | ||
348 | Ok(()) | 379 | Ok(()) |
349 | } | 380 | } |
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, ¤t_list.id)?; | 43 | let mods = userlist_get_all_ids(config, ¤t_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, ¤t_list.id, &id)?; | 69 | let disable_version = |
70 | userlist_get_current_version(config, ¤t_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 | ||