From 2b180daf1e2687436046b853c59e0abe12c50f57 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 29 Apr 2023 23:59:54 +0200 Subject: added fallback if no primaries, removed prints --- src/files.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 59fc7de..a4c128e 100644 --- a/src/files.rs +++ b/src/files.rs @@ -18,7 +18,7 @@ use crate::{ pub async fn download_versions(list: List, config: Cfg, versions: Vec) -> MLE { let mut cached = get_cached_versions(&config.cache); - println!("{:#?}", cached); + // println!("{:#?}", cached); let dl_path = String::from(&list.download_folder); @@ -42,8 +42,12 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) print!("\tâ””({})Download version {}", project_info.title, ver.id); //Force flush of stdout, else print! doesn't print instantly std::io::stdout().flush().unwrap(); - let primary_file = ver.files.into_iter().find(|file| file.primary).unwrap(); - let mut splitname: Vec<&str> = primary_file.filename.split('.').collect(); + let files = ver.files; + let file = match files.clone().into_iter().find(|f| f.primary) { + Some(f) => f, + None => files[0].clone() + }; + let mut splitname: Vec<&str> = file.filename.split('.').collect(); let extension = match splitname.pop().ok_or("") { Ok(e) => e, Err(..) => return Err(MLError::new(ErrorType::Other, "NO_FILE_EXTENSION")), @@ -56,7 +60,7 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) extension ); download_file( - primary_file.url, + file.url, list.clone().download_folder, filename.clone(), ) -- cgit v1.2.3