From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/commands/download.rs | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/commands/download.rs') diff --git a/src/commands/download.rs b/src/commands/download.rs index 4baecee..9434591 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,8 +1,14 @@ -use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version, clean_list_dir}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions, error::{MLE, ErrorType, MLError}}; -use crate::{List, get_current_list, config::Cfg}; +use crate::{config::Cfg, get_current_list, List}; +use crate::{ + db::{lists_get, lists_get_all_ids, userlist_get_all_current_versions_with_mods}, + error::{ErrorType, MLError, MLE}, + files::{ + clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, + }, + 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())?; @@ -18,7 +24,10 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo for current_list in liststack { 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(config.clone(), String::from(¤t_list.id)) { + let current_version_ids = match userlist_get_all_current_versions_with_mods( + config.clone(), + String::from(¤t_list.id), + ) { Ok(i) => Ok(i), Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), }?; @@ -36,28 +45,37 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo if current_download.is_none() || clean { to_download.push(current_version); } else { - let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG").unwrap(); + let downloaded_version = current_download + .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") + .unwrap(); if ¤t_version != downloaded_version { to_disable.push((mod_id.clone(), String::from(downloaded_version))); to_download.push(current_version); } } } - - if clean { clean_list_dir(¤t_list)? }; + + if clean { + clean_list_dir(¤t_list)? + }; if !to_download.is_empty() { - download_versions(current_list.clone(), config.clone(), get_raw_versions(&config.apis.modrinth, to_download).await).await?; + download_versions( + current_list.clone(), + config.clone(), + get_raw_versions(&config.apis.modrinth, to_download).await, + ) + .await?; } else { println!("There are no new versions to download"); } - + if !to_disable.is_empty() { for ver in to_disable { if delete_old { println!("Deleting version {} for mod {}", ver.1, ver.0); delete_version(current_list.clone(), ver.1)?; - } else { + } else { disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; }; } -- cgit v1.2.3