From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/files.rs | 59 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 17 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 6519c6a..6160cb4 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,11 +1,20 @@ -use std::{fs::{File, read_dir, remove_file, rename}, io::Write, collections::HashMap}; use futures_util::StreamExt; use reqwest::Client; - -use crate::{List, modrinth::Version, db::{userlist_add_disabled_versions, mods_get_info}, config::Cfg, error::{MLE, MLError, ErrorType}}; +use std::{ + collections::HashMap, + fs::{read_dir, remove_file, rename, File}, + io::Write, +}; + +use crate::{ + config::Cfg, + db::{mods_get_info, userlist_add_disabled_versions}, + error::{ErrorType, MLError, MLE}, + modrinth::Version, + List, +}; pub async fn download_versions(list: List, config: Cfg, versions: Vec) -> MLE { - let dl_path = String::from(&list.download_folder); println!(" └Download mods to {}", dl_path); @@ -21,7 +30,13 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) Ok(e) => e, Err(..) => return Err(MLError::new(ErrorType::Other, "NO_FILE_EXTENSION")), }; - let filename = format!("{}.mr.{}.{}.{}", splitname.join("."), ver.project_id, ver.id, extension); + let filename = format!( + "{}.mr.{}.{}.{}", + splitname.join("."), + ver.project_id, + ver.id, + extension + ); download_file(primary_file.url, list.clone().download_folder, filename).await?; //tokio::time::sleep(std::time::Duration::new(3, 0)).await; println!(" ✓"); @@ -32,10 +47,7 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) async fn download_file(url: String, path: String, name: String) -> MLE<()> { let dl_path_file = format!("{}/{}", path, name); - let res = Client::new() - .get(String::from(&url)) - .send() - .await?; + let res = Client::new().get(String::from(&url)).send().await?; // download chunks let mut file = File::create(&dl_path_file)?; @@ -49,7 +61,12 @@ async fn download_file(url: String, path: String, name: String) -> MLE<()> { Ok(()) } -pub fn disable_version(config: Cfg, current_list: List, versionid: String, mod_id: String) -> MLE<()> { +pub fn disable_version( + config: Cfg, + current_list: List, + versionid: String, + mod_id: String, +) -> MLE<()> { //println!("Disabling version {} for mod {}", versionid, mod_id); let file = get_file_path(current_list.clone(), String::from(&versionid))?; let disabled = format!("{}.disabled", file); @@ -63,7 +80,7 @@ pub fn disable_version(config: Cfg, current_list: List, versionid: String, mod_i pub fn delete_version(list: List, version: String) -> MLE<()> { let file = get_file_path(list, version)?; - + remove_file(file)?; Ok(()) @@ -76,19 +93,24 @@ pub fn get_file_path(list: List, versionid: String) -> MLE { if path.is_file() { let pathstr = match path.to_str().ok_or("") { Ok(s) => s, - Err(..) => return Err(MLError::new(ErrorType::Other, "INVALID_PATH")) + Err(..) => return Err(MLError::new(ErrorType::Other, "INVALID_PATH")), }; let namesplit: Vec<&str> = pathstr.split('.').collect(); let ver_id = namesplit[namesplit.len() - 2]; names.insert(String::from(ver_id), String::from(pathstr)); } - }; + } let filename = match names.get(&versionid).ok_or("") { Ok(n) => n, - Err(..) => return Err(MLError::new(ErrorType::ArgumentError, "VERSION_NOT_FOUND_IN_FILES")) + Err(..) => { + return Err(MLError::new( + ErrorType::ArgumentError, + "VERSION_NOT_FOUND_IN_FILES", + )) + } }; - + Ok(filename.to_owned()) } @@ -99,7 +121,10 @@ pub fn get_downloaded_versions(list: List) -> MLE> { if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { let pathstr = path.to_str().ok_or("BAH").unwrap(); let namesplit: Vec<&str> = pathstr.split('.').collect(); - versions.insert(String::from(namesplit[namesplit.len() - 3]), String::from(namesplit[namesplit.len() - 2])); + versions.insert( + String::from(namesplit[namesplit.len() - 3]), + String::from(namesplit[namesplit.len() - 2]), + ); } } Ok(versions) @@ -111,6 +136,6 @@ pub fn clean_list_dir(list: &List) -> MLE<()> { for entry in std::fs::read_dir(dl_path)? { let entry = entry?; std::fs::remove_file(entry.path())?; - }; + } Ok(()) } -- cgit v1.2.3