diff options
Diffstat (limited to 'src/cache.rs')
-rw-r--r-- | src/cache.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 0000000..11645d1 --- /dev/null +++ b/src/cache.rs | |||
@@ -0,0 +1,37 @@ | |||
1 | use std::{ | ||
2 | collections::HashMap, | ||
3 | fs::{copy, read_dir}, | ||
4 | }; | ||
5 | |||
6 | /// . | ||
7 | /// | ||
8 | /// # Panics | ||
9 | /// | ||
10 | /// Panics if . | ||
11 | pub fn get_cached_versions(path: &str) -> HashMap<String, String> { | ||
12 | let mut versions: HashMap<String, String> = HashMap::new(); | ||
13 | for file in read_dir(path).unwrap() { | ||
14 | let path = file.unwrap().path(); | ||
15 | if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { | ||
16 | let pathstr = path.to_str().ok_or("BAH").unwrap(); | ||
17 | let namesplit: Vec<&str> = pathstr.split('.').collect(); | ||
18 | versions.insert( | ||
19 | String::from(namesplit[namesplit.len() - 2]), | ||
20 | String::from(pathstr), | ||
21 | ); | ||
22 | } | ||
23 | } | ||
24 | versions | ||
25 | } | ||
26 | |||
27 | /// . | ||
28 | /// | ||
29 | /// # Panics | ||
30 | /// | ||
31 | /// Panics if . | ||
32 | pub fn copy_cached_version(version_path: &str, download_path: &str) { | ||
33 | let versplit: Vec<&str> = version_path.split('/').collect(); | ||
34 | let download = format!("{}{}", download_path, versplit[versplit.len() - 1]); | ||
35 | // println!("{:#?}", download); | ||
36 | copy(version_path, download).unwrap(); | ||
37 | } | ||