From 416f4dc383ff5a1194da3a5532a8e159a4a1dac0 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 23 Apr 2023 18:24:32 +0200 Subject: added caching, better data location --- src/cache.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/cache.rs (limited to 'src/cache.rs') diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 0000000..30c9f09 --- /dev/null +++ b/src/cache.rs @@ -0,0 +1,36 @@ +use std::{collections::HashMap, fs::{read_dir, copy}}; + +use crate::devdir; + +/// . +/// +/// # Panics +/// +/// Panics if . +pub fn get_cached_versions(path: &str) -> HashMap { + let mut versions: HashMap = HashMap::new(); + for file in read_dir(devdir(path)).unwrap() { + let path = file.unwrap().path(); + 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() - 2]), + String::from(pathstr), + ); + } + } + versions +} + +/// . +/// +/// # Panics +/// +/// 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]); + // println!("{:#?}", download); + copy(version_path, download).unwrap(); +} -- cgit v1.2.3