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/download.rs | 18 ++++-------------- src/commands/modification.rs | 39 ++++++++++++++++++++++++++++++++++++--- src/commands/update.rs | 12 ++++++------ 3 files changed, 46 insertions(+), 23 deletions(-) (limited to 'src/commands') diff --git a/src/commands/download.rs b/src/commands/download.rs index 1a8eb8f..ebfb4eb 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,6 +1,6 @@ -use crate::{config::Cfg, get_current_list, List}; +use crate::{config::Cfg, List}; use crate::{ - db::{lists_get, lists_get_all_ids, userlist_get_all_current_versions_with_mods}, + db::userlist_get_all_current_versions_with_mods, error::{ErrorType, MLError, MLE}, files::{ clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, @@ -8,20 +8,10 @@ use crate::{ modrinth::get_raw_versions, }; -pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> { - let mut liststack: Vec = vec![]; - if all_lists { - let list_ids = lists_get_all_ids(config.clone())?; - for id in list_ids { - liststack.push(lists_get(config.clone(), id)?); - } - } else { - let current = get_current_list(config.clone())?; - println!("Downloading current versions of mods in {}", current.id); - liststack.push(current) - } +pub async fn download(config: Cfg, liststack: Vec, clean: bool, delete_old: bool) -> MLE<()> { for current_list in liststack { + println!("Downloading current versions of mods in {}", current_list.id); let downloaded_versions = get_downloaded_versions(current_list.clone())?; // println!("To download: {:#?}", downloaded_versions); let current_version_ids = match userlist_get_all_current_versions_with_mods( 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(()) } diff --git a/src/commands/update.rs b/src/commands/update.rs index 4bc3ac0..d76ba4b 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -18,19 +18,19 @@ pub async fn update( delete_old: bool, ) -> MLE<()> { for current_list in liststack { + println!("Update mods in {}", current_list.id); let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; let mut current_versions: Vec<(String, String)> = vec![]; - println!(" └Update mods:"); let mut updatestack: Vec = vec![]; for id in mods { let info = mods_get_info(config.clone(), &id)?; - println!("\t└{}", info.title); + println!(" └{}", info.title); if userlist_get_set_version(config.clone(), ¤t_list.id, &id)? { - println!("\t └Set version, skipping update"); + println!(" └Set version, skipping update"); continue; } @@ -54,7 +54,7 @@ pub async fn update( Err(e) => { if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" { println!( - "\t └No new version found for the specified minecraft version" + " └No new version found for the specified minecraft version" ); } else { return Err(e); @@ -76,10 +76,10 @@ pub async fn update( if !clean { for ver in current_versions { if delete_old { - println!("\t └Delete version {}", ver.0); + println!(" └Delete version {}", ver.0); delete_version(current_list.clone(), ver.0)?; } else if ver.0 != "NONE" { - println!("\t └Disable version {}", ver.0); + println!(" └Disable version {}", ver.0); disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?; }; } -- cgit v1.2.3