From 9063a041f6b2e72f6e4a861c77ac16065dd5378b Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 9 May 2023 20:34:09 +0200 Subject: add list toggles to update and download; add mod remove output and fix errors --- src/commands/modification.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/commands/modification.rs') 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 @@ +use std::io::Write; + use crate::{ config::Cfg, db::{ lists_get_all_ids, mods_get_id, mods_insert, mods_remove, userlist_get_all_ids, - userlist_get_current_version, userlist_insert, userlist_remove, + userlist_get_current_version, userlist_insert, userlist_remove, mods_get_info, }, error::{ErrorType, MLError, MLE}, files::{delete_version, download_versions}, @@ -248,17 +250,47 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec) -> MLE pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { let mod_id = mods_get_id(&config.data, id)?; + println!("Remove mod {} from {}", mods_get_info(config.clone(), &mod_id)?.title, list.id); let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; + print!(" └Remove from list"); + //Force flush of stdout, else print! doesn't print instantly + std::io::stdout().flush()?; userlist_remove(config.clone(), &list.id, &mod_id)?; - delete_version(list, version)?; + println!(" ✓"); + + print!(" └Delete file"); + //Force flush of stdout, else print! doesn't print instantly + std::io::stdout().flush()?; + match delete_version(list, version) { + Ok(_) => (), + Err(err) => { + if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" { + return Err(err); + }; + () + }, + }; + println!(" ✓"); + print!(" └Clean main db table"); + //Force flush of stdout, else print! doesn't print instantly + std::io::stdout().flush()?; let list_ids = lists_get_all_ids(config.clone())?; // Remove mod from main list if not used elsewhere let mut mod_used = false; for id in list_ids { - let mods = userlist_get_all_ids(config.clone(), id)?; + let mods = match userlist_get_all_ids(config.clone(), id) { + Ok(m) => m, + Err(err) => { + if err.to_string() == "Database: NO_MODS_USERLIST" { + println!(" ✓"); + return Ok(()); + }; + return Err(err) + } + }; if mods.contains(&mod_id) { mod_used = true; break; @@ -268,6 +300,7 @@ pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { if !mod_used { mods_remove(config, mod_id)?; }; + println!(" ✓"); Ok(()) } -- cgit v1.2.3