From d6415cf0e03dbb42c573a597d07ea1be5cd1fc44 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 9 May 2023 20:53:34 +0200 Subject: added list check on default change --- src/commands/list.rs | 8 +++++--- src/commands/update.rs | 2 -- src/main.rs | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/commands/list.rs b/src/commands/list.rs index 13176f4..8ec662d 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -2,9 +2,9 @@ use crate::{ config::Cfg, db::{ config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove, - lists_version, + lists_version, lists_get_all_ids, }, - error::MLE, + error::{MLE, MLError, ErrorType}, update, Modloader, }; @@ -32,7 +32,9 @@ pub fn list_add( } pub fn list_change(config: Cfg, id: String) -> MLE<()> { - //TODO check if list exists + if lists_get_all_ids(config.clone())?.into_iter().find(|l| l == &id).is_none() { + return Err(MLError::new(ErrorType::ArgumentError, "List not found")); + }; println!("Change default list to: {}", id); config_change_current_list(config, id) } diff --git a/src/commands/update.rs b/src/commands/update.rs index d76ba4b..1fe664e 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -105,7 +105,6 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML } let mut current: Vec = vec![]; - //TODO Split clean and no match if clean || (versions.join("|") != userlist_get_applicable_versions( @@ -134,7 +133,6 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML }?; current.push(current_ver.clone()); - //TODO implement version selection if no primary let link = match current_ver .files .into_iter() diff --git a/src/main.rs b/src/main.rs index 2db304b..4239dc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ use modlist::{ mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, }; -//TODO make default list optional #[derive(Parser)] #[command(author, version, about)] struct Cli { -- cgit v1.2.3 From bfc5c2c68007785b3d58724c0dae355162341866 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 9 May 2023 21:02:23 +0200 Subject: added list for lists --- src/commands/list.rs | 9 +++++++++ src/main.rs | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/commands/list.rs b/src/commands/list.rs index 8ec662d..4aa4306 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -70,3 +70,12 @@ pub async fn list_version( let list = lists_get(config.clone(), id)?; update(config, vec![list], true, download, delete).await } + +pub fn list_list(config: Cfg) -> MLE<()> { + let lists = lists_get_all_ids(config.clone())?; + for list in lists { + let l = lists_get(config.clone(), list)?; + println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) + } + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 4239dc1..4979386 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use modlist::{ config::Cfg, db::{config_get_current_list, lists_get, lists_get_all_ids}, download, export, get_current_list, import, list_add, list_change, list_remove, list_version, - mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, + mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, }; #[derive(Parser)] @@ -222,7 +222,7 @@ async fn main() { } ListCommands::Remove { id } => list_remove(config, id), ListCommands::List => { - todo!() + list_list(config) } ListCommands::Change { id } => list_change(config, id), ListCommands::Version { -- cgit v1.2.3 From bf8fa23bf00584e4efa3060cf8ca4932173061c9 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 10 May 2023 08:15:22 +0200 Subject: fix quilt implementation --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index f18bdfb..1c40ceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ impl Modloader { match string { "forge" => Ok(Modloader::Forge), "fabric" => Ok(Modloader::Fabric), + "quilt" => Ok(Modloader::Quilt), _ => Err(MLError::new(ErrorType::ArgumentError, "UNKNOWN_MODLOADER")), } } -- cgit v1.2.3 From 8398b4003b72b3eefea11d8f71897ddb48f4b0ad Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sat, 13 May 2023 12:37:07 +0200 Subject: impl of set_version import --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/io.rs | 39 ++++++++++++++++++------- src/commands/modification.rs | 69 +++++++++++++++++++++++++++++++------------- src/commands/update.rs | 2 +- src/db.rs | 10 +++---- src/main.rs | 6 ++-- 7 files changed, 90 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7422038..c842b90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ dependencies = [ [[package]] name = "modlist" -version = "0.14.1" +version = "0.14.2" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index bd41811..345f60d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "modlist" -version = "0.14.1" +version = "0.14.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/commands/io.rs b/src/commands/io.rs index e072f00..2bab132 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -4,9 +4,9 @@ use std::io::prelude::*; use crate::{ config::Cfg, - db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids}, + db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_set_version, userlist_get_all_ids, userlist_get_current_version}, error::MLE, - mod_add, IDSelector, List, Modloader, + mod_add, IDSelector, List, Modloader, AddMod, }; #[derive(Debug, Serialize, Deserialize)] @@ -14,10 +14,25 @@ struct Export { lists: Vec, } +#[derive(Debug, Serialize, Deserialize)] +struct ExportVersion { + version: String, + set: bool +} + +impl ExportVersion { + fn from(config: Cfg, list_id: &str, mod_id: &str) -> MLE { + Ok(Self { + version: userlist_get_current_version(config.clone(), list_id, mod_id)?, + set: userlist_get_set_version(config.clone(), list_id, mod_id)? + }) + } +} + #[derive(Debug, Serialize, Deserialize)] struct ExportList { id: String, - mods: String, + versions: Vec, launcher: String, mc_version: String, download_folder: Option, @@ -32,11 +47,15 @@ impl ExportList { dl_folder = Some(list.download_folder) }; - let mods = userlist_get_all_ids(config, list_id)?.join("|"); + let mods = userlist_get_all_ids(config.clone(), &list_id)?; + let mut versions = vec![]; + for m in mods { + versions.push(ExportVersion::from(config.clone(), &list_id, &m)?) + } Ok(Self { id: list.id, - mods, + versions, launcher: list.modloader.to_string(), mc_version: list.mc_version, download_folder: dl_folder, @@ -86,14 +105,14 @@ pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE list.modloader.clone(), String::from(&list.download_folder), )?; - let mods: Vec<&str> = exportlist.mods.split('|').collect(); - let mut mod_ids = vec![]; - for mod_id in mods { - mod_ids.push(IDSelector::ModificationID(String::from(mod_id))); + + let mut ver_ids = vec![]; + for id in exportlist.versions { + ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} ); } //TODO impl set_version and good direct download //TODO impl all at once, dafuck ?done? - mod_add(config.clone(), mod_ids, list, direct_download, false).await?; + mod_add(config.clone(), ver_ids, list, direct_download).await?; } Ok(()) } diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 216a06e..ab42468 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,4 +1,4 @@ -use std::io::Write; +use std::{io::Write, collections::HashMap}; use crate::{ config::Cfg, @@ -12,6 +12,12 @@ use crate::{ List, }; +#[derive(Debug, Clone)] +pub struct AddMod { + pub id: IDSelector, + pub set_version: bool +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum IDSelector { ModificationID(String), @@ -26,26 +32,27 @@ pub struct ProjectInfo { pub current_version: Option, pub applicable_versions: Vec, pub download_link: String, + pub set_version: bool, } +//TODO fix setversion to per mod pub async fn mod_add( config: Cfg, - ids: Vec, + mods: Vec, list: List, direct_download: bool, - set_version: bool, ) -> MLE<()> { println!("Add mods to {}", list.id); println!(" └Add mods:"); - let mut mod_ids: Vec = Vec::new(); - let mut ver_ids: Vec = Vec::new(); + let mut mod_ids: Vec<(String, bool)> = Vec::new(); + let mut ver_ids: Vec<(String, bool)> = Vec::new(); //"Sort" project ids from version ids to be able to handle them differently but in a batch - for id in ids { - match id { - IDSelector::ModificationID(pid) => mod_ids.push(pid), - IDSelector::VersionID(vid) => ver_ids.push(vid), + for m in mods { + match m.id { + IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), + IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), } } @@ -83,7 +90,7 @@ pub async fn mod_add( ¤t_version_id, project.clone().applicable_versions, &project.download_link, - set_version, + project.set_version, ) { Err(e) => { let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); @@ -128,13 +135,23 @@ pub async fn mod_add( Ok(()) } -async fn get_mod_infos(config: Cfg, mod_ids: Vec, list: List) -> MLE> { +async fn get_mod_infos(config: Cfg, mod_ids: Vec<(String, bool)>, list: List) -> MLE> { + + let mut setmap: HashMap = HashMap::new(); + + let mut ids = vec![]; + + for id in mod_ids { + setmap.insert(id.0.to_string(), id.1); + ids.push(id.0); + } + let mut projectinfo: Vec = Vec::new(); //Get required information from mod_ids - let m_projects = match mod_ids.len() { - 1 => vec![project(&config.apis.modrinth, &mod_ids[0]).await], - 2.. => projects(&config.apis.modrinth, mod_ids).await, + let m_projects = match ids.len() { + 1 => vec![project(&config.apis.modrinth, &ids[0]).await], + 2.. => projects(&config.apis.modrinth, ids).await, _ => panic!("PANIC"), }; for project in m_projects { @@ -180,12 +197,13 @@ async fn get_mod_infos(config: Cfg, mod_ids: Vec, list: List) -> MLE, list: List) -> MLE, list: List) -> MLE) -> MLE> { +async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE> { + + let mut setmap: HashMap = HashMap::new(); + + let mut ids = vec![]; + + for id in ver_ids { + setmap.insert(id.0.to_string(), id.1); + ids.push(id.0); + } let mut projectinfo: Vec = Vec::new(); //Get required information from ver_ids - let mut v_versions = get_raw_versions(&config.apis.modrinth, ver_ids).await; + let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await; let mut v_mod_ids: Vec = Vec::new(); for ver in v_versions.clone() { v_mod_ids.push(ver.project_id); @@ -230,12 +258,13 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec) -> MLE .unwrap() .url; projectinfo.push(ProjectInfo { - mod_id: project.id, + mod_id: String::from(&project.id), slug: project.slug, title: project.title, current_version: Some(version.clone()), applicable_versions: vec![String::from(&version.id)], download_link: file, + set_version: setmap.get(&project.id).unwrap().clone(), }) } Ok(projectinfo) @@ -281,7 +310,7 @@ pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { // Remove mod from main list if not used elsewhere let mut mod_used = false; for id in list_ids { - let mods = match 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" { diff --git a/src/commands/update.rs b/src/commands/update.rs index 1fe664e..2128090 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -19,7 +19,7 @@ pub async fn update( ) -> 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 mods = userlist_get_all_ids(config.clone(), ¤t_list.id)?; let mut current_versions: Vec<(String, String)> = vec![]; diff --git a/src/db.rs b/src/db.rs index 9ffbfe5..8fd21b1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -220,7 +220,7 @@ pub fn userlist_insert( Ok(()) } -pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { +pub fn userlist_get_all_ids(config: Cfg, list_id: &str) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -329,7 +329,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> pub fn userlist_get_all_current_version_ids( config: Cfg, list_id: String, -) -> Result, Box> { +) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -343,10 +343,10 @@ pub fn userlist_get_all_current_version_ids( } if versions.is_empty() { - return Err(Box::new(std::io::Error::new( - ErrorKind::Other, + return Err(MLError::new( + ErrorType::DBError, "NO_MODS_ON_LIST", - ))); + )); }; Ok(versions) diff --git a/src/main.rs b/src/main.rs index 4979386..31a320b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use modlist::{ config::Cfg, db::{config_get_current_list, lists_get, lists_get_all_ids}, download, export, get_current_list, import, list_add, list_change, list_remove, list_version, - mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, + mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, AddMod, }; #[derive(Parser)] @@ -184,7 +184,9 @@ async fn main() { false => IDSelector::ModificationID(id), }; - mod_add(config, vec![marked_id], listf, download, lock).await + let add_id = AddMod { id: marked_id, set_version: lock }; + + mod_add(config, vec![add_id], listf, download).await } ModCommands::Remove { id, list } => { let listf = match list { -- cgit v1.2.3 From 3181da20e001146653a09f0734e0340b043d9b4b Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 13 May 2023 12:59:38 +0200 Subject: removed todos, fixed get version set --- src/commands/io.rs | 2 -- src/commands/modification.rs | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/commands/io.rs b/src/commands/io.rs index 2bab132..dd294bc 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -110,8 +110,6 @@ pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE for id in exportlist.versions { ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} ); } - //TODO impl set_version and good direct download - //TODO impl all at once, dafuck ?done? mod_add(config.clone(), ver_ids, list, direct_download).await?; } Ok(()) diff --git a/src/commands/modification.rs b/src/commands/modification.rs index ab42468..9a1a651 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -35,7 +35,6 @@ pub struct ProjectInfo { pub set_version: bool, } -//TODO fix setversion to per mod pub async fn mod_add( config: Cfg, mods: Vec, @@ -264,7 +263,7 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE Date: Sat, 13 May 2023 17:12:07 +0200 Subject: minimally better logging --- src/commands/update.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/update.rs b/src/commands/update.rs index 2128090..d3a282b 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -27,10 +27,10 @@ pub async fn update( for id in mods { let info = mods_get_info(config.clone(), &id)?; - println!(" └{}", info.title); + println!(" ├{}", info.title); if userlist_get_set_version(config.clone(), ¤t_list.id, &id)? { - println!(" └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!( - " └No new version found for the specified minecraft version" + " │ └No new version found for the specified minecraft version" ); } else { return Err(e); -- cgit v1.2.3