diff options
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 55 |
1 files changed, 43 insertions, 12 deletions
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 | } |