From d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Fri, 25 Nov 2022 15:52:20 +0100 Subject: added direct download --- src/commands/download.rs | 8 +++-- src/commands/update.rs | 88 +++++++++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 41 deletions(-) (limited to 'src/commands') 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(()) } -- cgit v1.2.3