1use std::{path::PathBuf, collections::HashMap, ffi::OsString};
2use std::io::Read;
3
4use rc_zip::{prelude::ReadZip};
5
6const IGNORED_PARTS: [&'static str; 35] = [
7 "_(Model)/", "Characters/", "Arenas/", "_(AIGeometry)/", "_(BasicSkelAnim)/", "_(AnimSet)/", "_(CameraSet)/",
8 "_(Decal)/", "_(DistanceFog)/", "_(Geometry)/", "_(HeightFog)/",
9 "_(Material)/", "_(Skeleton)/", "_(SunFlares)/", "ArenaObjects/",
10 "index.bin", "bin/", "Campaigns/", "Cameras/", "Custom/",
11 "Editor/", "_(Effect)/", "Lights/", "DialogScenes/", "RMG/",
12 "Scenes/", "scripts/", "Sounds/", "Roots/", ".bin", ".dds", ".ogg", ".tga", "types.xml", ".git"
13];
14
15#[derive(Debug, Clone)]
16pub struct FileStructure {
17 pub pak: String,
19 pub modified: i64,
20 pub content: String
21}
22
23pub fn check_pak(path: PathBuf, files: &mut HashMap<String, FileStructure>) {
24 let file = std::fs::File::open(&path).unwrap();
25 let archive = file.read_zip().unwrap();
26 for entry in archive.entries() {
27 let name = entry.name().to_string();
28 if (IGNORED_PARTS.iter().any(|part| entry.name().contains(part)) == false) && (entry.name().ends_with("/") == false) {
29 if files.contains_key(entry.name().to_lowercase().as_str()) {
30 if files.get(entry.name().to_lowercase().as_str()).unwrap().modified < entry.modified().timestamp() {
31 let mut content = String::new();
32 match entry.reader().read_to_string(&mut content) {
33 Ok(x) => {
34 files.insert(name.to_lowercase(), FileStructure {
35 pak: path.to_str().unwrap().to_string(),
36 modified: entry.modified().timestamp(),
37 content: content
38 });
39 }
40 Err(x) => {}
41 }
42 }
43 }
44 else {
45 let mut content = String::new();
46 match entry.reader().read_to_string(&mut content) {
47 Ok(x) => {
48 files.insert(name.to_lowercase(), FileStructure {
49 pak: path.to_str().unwrap().to_string(),
50 modified: entry.modified().timestamp(),
51 content: content
52 });
53 }
54 Err(x) => {
55 files.insert(name.to_lowercase(), FileStructure {
57 pak: path.to_str().unwrap().to_string(),
58 modified: entry.modified().timestamp(),
59 content: content
60 });
61 }
62 }
63 }
64 }
65 }
66}