diff options
author | fxqnlr <[email protected]> | 2023-04-23 18:24:32 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-04-23 18:24:32 +0200 |
commit | 416f4dc383ff5a1194da3a5532a8e159a4a1dac0 (patch) | |
tree | c3d00456cafa01bfbe620aed85b25caa60b4e29d /src/cache.rs | |
parent | 4300ad2eb05dddfa4274e04b204f2ad28c87da05 (diff) | |
download | modlist-416f4dc383ff5a1194da3a5532a8e159a4a1dac0.tar modlist-416f4dc383ff5a1194da3a5532a8e159a4a1dac0.tar.gz modlist-416f4dc383ff5a1194da3a5532a8e159a4a1dac0.zip |
added caching, better data location
Diffstat (limited to 'src/cache.rs')
-rw-r--r-- | src/cache.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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 @@ | |||
1 | use std::{collections::HashMap, fs::{read_dir, copy}}; | ||
2 | |||
3 | use crate::devdir; | ||
4 | |||
5 | /// . | ||
6 | /// | ||
7 | /// # Panics | ||
8 | /// | ||
9 | /// Panics if . | ||
10 | pub fn get_cached_versions(path: &str) -> HashMap<String, String> { | ||
11 | let mut versions: HashMap<String, String> = HashMap::new(); | ||
12 | for file in read_dir(devdir(path)).unwrap() { | ||
13 | let path = file.unwrap().path(); | ||
14 | if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { | ||
15 | let pathstr = path.to_str().ok_or("BAH").unwrap(); | ||
16 | let namesplit: Vec<&str> = pathstr.split('.').collect(); | ||
17 | versions.insert( | ||
18 | String::from(namesplit[namesplit.len() - 2]), | ||
19 | String::from(pathstr), | ||
20 | ); | ||
21 | } | ||
22 | } | ||
23 | versions | ||
24 | } | ||
25 | |||
26 | /// . | ||
27 | /// | ||
28 | /// # Panics | ||
29 | /// | ||
30 | /// Panics if . | ||
31 | pub fn copy_cached_version(version_path: &str, download_path: &str) { | ||
32 | let versplit: Vec<&str> = version_path.split('/').collect(); | ||
33 | let download = format!("{}{}", download_path, versplit[versplit.len() - 1]); | ||
34 | // println!("{:#?}", download); | ||
35 | copy(version_path, download).unwrap(); | ||
36 | } | ||