diff options
author | fxqnlr <[email protected]> | 2023-05-09 20:34:09 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-09 20:34:09 +0200 |
commit | 9063a041f6b2e72f6e4a861c77ac16065dd5378b (patch) | |
tree | 03d34dfe9ff05de2dd74d3afe1cde87712f1b59a /src/commands/modification.rs | |
parent | 0c7ba29d3e17c47e5fc9cffe78c28a0019d453b7 (diff) | |
download | modlist-9063a041f6b2e72f6e4a861c77ac16065dd5378b.tar modlist-9063a041f6b2e72f6e4a861c77ac16065dd5378b.tar.gz modlist-9063a041f6b2e72f6e4a861c77ac16065dd5378b.zip |
add list toggles to update and download;
add mod remove output and fix errors
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 67cde0b..216a06e 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,8 +1,10 @@ | |||
1 | use std::io::Write; | ||
2 | |||
1 | use crate::{ | 3 | use crate::{ |
2 | config::Cfg, | 4 | config::Cfg, |
3 | db::{ | 5 | db::{ |
4 | lists_get_all_ids, mods_get_id, mods_insert, mods_remove, userlist_get_all_ids, | 6 | lists_get_all_ids, mods_get_id, mods_insert, mods_remove, userlist_get_all_ids, |
5 | userlist_get_current_version, userlist_insert, userlist_remove, | 7 | userlist_get_current_version, userlist_insert, userlist_remove, mods_get_info, |
6 | }, | 8 | }, |
7 | error::{ErrorType, MLError, MLE}, | 9 | error::{ErrorType, MLError, MLE}, |
8 | files::{delete_version, download_versions}, | 10 | files::{delete_version, download_versions}, |
@@ -248,17 +250,47 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<String>) -> MLE<Vec<ProjectInfo> | |||
248 | pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { | 250 | pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { |
249 | let mod_id = mods_get_id(&config.data, id)?; | 251 | let mod_id = mods_get_id(&config.data, id)?; |
250 | 252 | ||
253 | println!("Remove mod {} from {}", mods_get_info(config.clone(), &mod_id)?.title, list.id); | ||
251 | let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; | 254 | let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; |
252 | 255 | ||
256 | print!(" └Remove from list"); | ||
257 | //Force flush of stdout, else print! doesn't print instantly | ||
258 | std::io::stdout().flush()?; | ||
253 | userlist_remove(config.clone(), &list.id, &mod_id)?; | 259 | userlist_remove(config.clone(), &list.id, &mod_id)?; |
254 | delete_version(list, version)?; | 260 | println!(" ✓"); |
261 | |||
262 | print!(" └Delete file"); | ||
263 | //Force flush of stdout, else print! doesn't print instantly | ||
264 | std::io::stdout().flush()?; | ||
265 | match delete_version(list, version) { | ||
266 | Ok(_) => (), | ||
267 | Err(err) => { | ||
268 | if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" { | ||
269 | return Err(err); | ||
270 | }; | ||
271 | () | ||
272 | }, | ||
273 | }; | ||
274 | println!(" ✓"); | ||
255 | 275 | ||
276 | print!(" └Clean main db table"); | ||
277 | //Force flush of stdout, else print! doesn't print instantly | ||
278 | std::io::stdout().flush()?; | ||
256 | let list_ids = lists_get_all_ids(config.clone())?; | 279 | let list_ids = lists_get_all_ids(config.clone())?; |
257 | 280 | ||
258 | // Remove mod from main list if not used elsewhere | 281 | // Remove mod from main list if not used elsewhere |
259 | let mut mod_used = false; | 282 | let mut mod_used = false; |
260 | for id in list_ids { | 283 | for id in list_ids { |
261 | let mods = userlist_get_all_ids(config.clone(), id)?; | 284 | let mods = match userlist_get_all_ids(config.clone(), id) { |
285 | Ok(m) => m, | ||
286 | Err(err) => { | ||
287 | if err.to_string() == "Database: NO_MODS_USERLIST" { | ||
288 | println!(" ✓"); | ||
289 | return Ok(()); | ||
290 | }; | ||
291 | return Err(err) | ||
292 | } | ||
293 | }; | ||
262 | if mods.contains(&mod_id) { | 294 | if mods.contains(&mod_id) { |
263 | mod_used = true; | 295 | mod_used = true; |
264 | break; | 296 | break; |
@@ -268,6 +300,7 @@ pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { | |||
268 | if !mod_used { | 300 | if !mod_used { |
269 | mods_remove(config, mod_id)?; | 301 | mods_remove(config, mod_id)?; |
270 | }; | 302 | }; |
303 | println!(" ✓"); | ||
271 | 304 | ||
272 | Ok(()) | 305 | Ok(()) |
273 | } | 306 | } |