From 9f2f36eb7ff00d655ab9fb12f10434962b7de1a2 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 19 Feb 2023 12:14:37 +0100 Subject: Fixed import output && cleanup --- src/commands/modification.rs | 70 ++++---------------------------------------- src/db.rs | 4 --- 2 files changed, 6 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index c815155..31e50af 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,6 +1,5 @@ use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; -//TODO DO IT #[derive(Debug, Clone, PartialEq, Eq)] pub enum IDSelector { ModificationID(String), @@ -35,7 +34,6 @@ pub struct ProjectInfo { pub download_link: String, } -//TODO impl specific version... Rewrite yay pub async fn mods_add(config: Cfg, ids: Vec, list: List, direct_download: bool, set_version: bool) -> MLE<()> { println!("Add mods to {}", list.id); println!(" └Add mods:"); @@ -60,9 +58,14 @@ pub async fn mods_add(config: Cfg, ids: Vec, list: List, direct_down let mut downloadstack: Vec = Vec::new(); //Adding each mod to the lists and downloadstack + if projectinfo.len() == 1 { + println!(" └Insert mod in list {} and save infos", list.id); + } else { + println!(" └Insert mods in list {} and save infos", list.id); + } + for project in projectinfo { let current_version_id = if project.current_version.is_none() { String::from("NONE") } else { project.current_version.clone().unwrap().id }; - match userlist_insert(config.clone(), &list.id, &project.mod_id, ¤t_version_id, project.clone().applicable_versions, &project.download_link, set_version) { Err(e) => { let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); @@ -86,67 +89,6 @@ pub async fn mods_add(config: Cfg, ids: Vec, list: List, direct_down download_versions(list.clone(), config.clone(), downloadstack).await?; }; - - // let projects = if id.len() == 1 { - // vec![project(String::from(&config.apis.modrinth), &mod_id).await] - // } else { - // projects(String::from(&config.apis.modrinth), &mod_id).await - // }; -// -// let mut downloadstack: Vec = Vec::new(); -// -// for project in projects { -// println!("\t└{}", project.title); -// println!("\t └Get versions"); -// let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; -// -// let mut available_versions_vec: Vec = Vec::new(); -// let current_version: Option; -// let current_version_id: String; -// let file: String; -// if !available_versions.is_empty() { -// let current_id = extract_current_version(available_versions.clone())?; -// println!("\t └Current version: {}", current_id); -// -// current_version = Some(available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap()); -// -// current_version_id = current_version.clone().unwrap().id; -// -// file = current_version.clone().ok_or("").unwrap().files.into_iter().find(|f| f.primary).unwrap().url; -// for ver in available_versions { -// available_versions_vec.push(ver.id); -// }; -// } else { -// println!("\t └There's currently no mod version for your specified target"); -// current_version = None; -// current_version_id = String::from("NONE"); -// file = String::from("NONE"); -// available_versions_vec.push(String::from("NONE")); -// } -// -// match userlist_insert(config.clone(), &list.id, &project.id, ¤t_version_id, available_versions_vec, &file, set_version) { -// Err(e) => { -// let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); -// if e.to_string() == expected_err { Err(MLError::new(ErrorType::ModError, "MOD_ALREADY_ON_SELECTED_LIST")) } else { Err(e) } -// }, -// Ok(..) => { Ok(..) }, -// }?; -// -// match mods_insert(config.clone(), &project.id, &project.slug, &project.title) { -// Err(e) => { -// if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { Ok(..) } else { Err(e) } -// }, -// Ok(..) => Ok(..), -// }?; -// -// downloadstack.push(current_version.unwrap()); -// }; -// -// //Download all the added mods -// if direct_download { -// download_versions(list.clone(), config.clone(), downloadstack).await?; -// }; -// Ok(()) } diff --git a/src/db.rs b/src/db.rs index a7c149c..9428466 100644 --- a/src/db.rs +++ b/src/db.rs @@ -7,8 +7,6 @@ use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorTyp //MODS pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { - println!("\t └Save mod info"); - let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -160,8 +158,6 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE, current_link: &str, set_version: bool) -> MLE<()> { - println!("\t └Insert in list"); - let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; -- cgit v1.2.3