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/cache.rs | 2 +- src/commands/modification.rs | 16 ++++++++++------ src/files.rs | 12 ++++++++---- src/main.rs | 1 - 4 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/cache.rs b/src/cache.rs index 11645d1..c928670 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -31,7 +31,7 @@ pub fn get_cached_versions(path: &str) -> HashMap { /// Panics if . pub fn copy_cached_version(version_path: &str, download_path: &str) { let versplit: Vec<&str> = version_path.split('/').collect(); - let download = format!("{}{}", download_path, versplit[versplit.len() - 1]); + let download = format!("{}/{}", download_path, versplit[versplit.len() - 1]); // println!("{:#?}", download); copy(version_path, download).unwrap(); } diff --git a/src/commands/modification.rs b/src/commands/modification.rs index ffc4e10..67cde0b 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -159,16 +159,20 @@ async fn get_mod_infos(config: Cfg, mod_ids: Vec, list: List) -> MLE f, + None => { files[0].clone() } + } .url; + for ver in available_versions { available_versions_vec.push(ver.id); } 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(), ) diff --git a/src/main.rs b/src/main.rs index 0ecb850..53cbe71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,7 +148,6 @@ async fn main() { let cli = Cli::parse(); let config = Cfg::init(cli.config).unwrap(); - println!("{:?}", config); match cli.command { Commands::Mod { command } => { -- cgit v1.2.3