From d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Fri, 25 Nov 2022 15:52:20 +0100 Subject: added direct download --- data.db | Bin 24576 -> 16384 bytes src/commands/download.rs | 8 +++-- src/commands/update.rs | 88 ++++++++++++++++++++++++++--------------------- src/input.rs | 15 ++++---- 4 files changed, 61 insertions(+), 50 deletions(-) diff --git a/data.db b/data.db index a54cd80..7f62a4e 100644 Binary files a/data.db and b/data.db differ diff --git a/src/commands/download.rs b/src/commands/download.rs index 82d6b02..13ba0e1 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,15 +1,19 @@ +#[allow(unused_imports)] use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; -pub async fn download(config: Cfg, input: Input) -> Result<(), Box> { +pub async fn download(_config: Cfg, _input: Input) -> Result<(), Box> { + println!("NO IMPLEMENTATION FOR DOWNLOAD YET"); + /* let list = get_current_list(config.clone())?; let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; download_links(config, input, list, links).await?; - + */ Ok(()) } +#[allow(dead_code)] async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec) -> Result> { println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET"); //TODO copy dl from update if possible diff --git a/src/commands/update.rs b/src/commands/update.rs index eba5e91..42d19aa 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,50 +1,60 @@ use std::io::{Error, ErrorKind}; -use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions}, List, input::Input, download_file}; +use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get}, List, input::Input, download_file}; pub async fn update(config: Cfg, input: Input) -> Result<(), Box> { - - let current_list = get_current_list(config.clone())?; - - let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; - - let mut versions = mods_get_versions(config.clone(), mods.clone())?; - versions.sort_by_key(|ver| ver.mod_id.clone()); - - let mut projects = projects(String::from(&config.apis.modrinth), mods).await; - projects.sort_by_key(|pro| pro.id.clone()); - let mut updatestack: Vec = vec![]; - for (index, project) in projects.into_iter().enumerate() { - //Get versions for project and check if they match up - let current_version = &versions[index]; - let p_id = String::from(&project.id); - let v_id = ¤t_version.mod_id; - if &p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "SORTING_ERROR"))) }; - - - //Adding to stack if not the same versions in the list OR if clean == true - if input.clone().clean || (project.versions.join("|") != current_version.versions) { - updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { - Ok(ver) => ver, - //TODO handle errors (only continue on "NO_UPDATE_AVAILABLE") - Err(_) => { println!("({}) No new version found for the specified minecraft version", project.title); continue; }, - }); - } else { - println!("({}) No new version found", project.title); + let mut liststack: Vec = vec![]; + if input.all_lists { + let list_ids = lists_get_all_ids(config.clone())?; + for id in list_ids { + liststack.push(lists_get(config.clone(), id)?); + } + } else { + liststack.push(get_current_list(config.clone())?) + } + + for current_list in liststack { + let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; + + let mut versions = mods_get_versions(config.clone(), mods.clone())?; + versions.sort_by_key(|ver| ver.mod_id.clone()); + + let mut projects = projects(String::from(&config.apis.modrinth), mods).await; + projects.sort_by_key(|pro| pro.id.clone()); + + let mut updatestack: Vec = vec![]; + for (index, project) in projects.into_iter().enumerate() { + //Get versions for project and check if they match up + let current_version = &versions[index]; + let p_id = String::from(&project.id); + let v_id = ¤t_version.mod_id; + if &p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "SORTING_ERROR"))) }; + + + //Adding to stack if not the same versions in the list OR if clean == true + if input.clone().clean || (project.versions.join("|") != current_version.versions) { + updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { + Ok(ver) => ver, + //TODO handle errors (only continue on "NO_UPDATE_AVAILABLE") + Err(_) => { println!("({}) No new version found for the specified minecraft version", project.title); continue; }, + }); + } else { + println!("({}) No new version found", project.title); + }; }; - }; - - if input.clean { - let dl_path = ¤t_list.download_folder; - println!("Cleaning {}", dl_path); - for entry in std::fs::read_dir(dl_path)? { - let entry = entry?; - std::fs::remove_file(entry.path())?; + + if input.clean { + let dl_path = ¤t_list.download_folder; + println!("Cleaning {}", dl_path); + for entry in std::fs::read_dir(dl_path)? { + let entry = entry?; + std::fs::remove_file(entry.path())?; + } } + + if input.direct_download { download_updates(current_list, updatestack).await?; }; } - - if input.direct_download { download_updates(current_list, updatestack).await?; }; Ok(()) } diff --git a/src/input.rs b/src/input.rs index 0b616d4..0946971 100644 --- a/src/input.rs +++ b/src/input.rs @@ -7,18 +7,16 @@ pub struct Input { pub subcommand: Option, pub args: Option>, pub direct_download: bool, - pub force_download: bool, pub all_lists: bool, pub delete_old: bool, pub clean: bool, } impl Input { - pub fn from(string: &str) -> MLE { + fn from(string: &str) -> MLE { let mut split: Vec<&str> = string.split(' ').collect(); let mut direct_download = false; - let mut force_download = false; let mut all_lists = false; let mut delete_old = false; let mut clean = false; @@ -27,9 +25,8 @@ impl Input { if input.starts_with("--") { match input { "--direct-download" => direct_download = true, - "--force-download" => force_download = true, - "--all_lists" => all_lists = true, - "--delete_old" => delete_old = true, + "--all-lists" => all_lists = true, + "--delete-old" => delete_old = true, "--clean" => clean = true, _ => continue, } @@ -54,7 +51,7 @@ impl Input { } }; - Ok(Self { command, subcommand, args, direct_download, force_download, all_lists, delete_old, clean }) + Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean }) } } @@ -68,7 +65,7 @@ pub enum Cmd { } impl Cmd { - pub fn from(string: &str) -> MLE { + fn from(string: &str) -> MLE { let cmd = match string { "mod" => Self::Mod, "list" => Self::List, @@ -130,6 +127,6 @@ pub async fn get_input(config: Cfg) -> Result<(), Box> { #[test] fn input_from() { let string = "list add test 1.19.2 fabric"; - let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), force_download: false, direct_download: false, all_lists: false, clean: false, delete_old: false }; + let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false }; assert_eq!(Input::from(string).unwrap(), input); } -- cgit v1.2.3