change: Add more then pack/ support.
parent
0c352ad4e0
commit
bf2ae78108
|
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
checksum.json
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,15 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-deque"
|
name = "crossbeam-deque"
|
||||||
version = "0.8.6"
|
version = "0.8.6"
|
||||||
|
|
@ -38,7 +47,9 @@ name = "hash-gen"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memmap2",
|
"memmap2",
|
||||||
|
"once_cell",
|
||||||
"rayon",
|
"rayon",
|
||||||
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
|
@ -72,6 +83,12 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.21.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.103"
|
version = "1.0.103"
|
||||||
|
|
@ -110,6 +127,35 @@ dependencies = [
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.12.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,5 @@ xxhash-rust = { version = "0.8.15", features = ["xxh3"] }
|
||||||
rayon = "1.10"
|
rayon = "1.10"
|
||||||
memmap2 = "0.9"
|
memmap2 = "0.9"
|
||||||
walkdir = "2.3"
|
walkdir = "2.3"
|
||||||
|
regex = "1.12.2"
|
||||||
|
once_cell = "*"
|
||||||
|
|
|
||||||
25
src/main.rs
25
src/main.rs
|
|
@ -1,23 +1,29 @@
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use regex::Regex;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
env, fs,
|
env, fs,
|
||||||
fs::File,
|
fs::File,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Mutex,
|
|
||||||
};
|
};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use xxhash_rust::xxh3::xxh3_64;
|
use xxhash_rust::xxh3::xxh3_64;
|
||||||
|
|
||||||
fn hash_file(path: &Path) -> (String, String) {
|
static RE: Lazy<Regex> = Lazy::new(|| {
|
||||||
|
Regex::new(r"(metin2\.exe|granny2\.dll|SpeedTreeRT\.dll|BGM[/\\].*|lib[/\\].*|pack[/\\].*)")
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
fn hash_file(path: &Path, base_path: &String) -> (String, String) {
|
||||||
let file = File::open(path).expect("Failed to open file");
|
let file = File::open(path).expect("Failed to open file");
|
||||||
let mmap = unsafe { Mmap::map(&file).expect("Failed to mmap file") };
|
let mmap = unsafe { Mmap::map(&file).expect("Failed to mmap file") };
|
||||||
let hash = xxh3_64(&mmap);
|
let hash = xxh3_64(&mmap);
|
||||||
let hash_str = hash.to_string();
|
let hash_str = hash.to_string();
|
||||||
|
|
||||||
let filename = path.file_name().unwrap().to_string_lossy().to_string();
|
let filename = path.to_str().unwrap().to_string().replace(base_path, "");
|
||||||
(filename, hash_str)
|
(filename, hash_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,12 +31,15 @@ fn collect_files(folder: &Path) -> Vec<PathBuf> {
|
||||||
WalkDir::new(folder)
|
WalkDir::new(folder)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.filter(|e| e.path().is_file())
|
.filter(|e| e.path().is_file() && RE.is_match(e.path().to_str().unwrap()))
|
||||||
.map(|e| e.path().to_path_buf())
|
.map(|e| e.path().to_path_buf())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
|
use std::time::Instant;
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
if args.len() != 2 {
|
if args.len() != 2 {
|
||||||
eprintln!("Usage: {} <folder>", args[0]);
|
eprintln!("Usage: {} <folder>", args[0]);
|
||||||
|
|
@ -45,11 +54,13 @@ fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
let files = collect_files(folder);
|
let files = collect_files(folder);
|
||||||
|
|
||||||
let results: BTreeMap<String, String> = files.par_iter().map(|f| hash_file(f)).collect();
|
let results: BTreeMap<String, String> =
|
||||||
|
files.par_iter().map(|f| hash_file(f, &args[1])).collect();
|
||||||
|
|
||||||
let json_output = json!({ "checksums": results });
|
let json_output = json!({ "checksums": results });
|
||||||
|
|
||||||
fs::write("checksum", serde_json::to_string_pretty(&json_output)?)?;
|
fs::write("checksum.json", serde_json::to_string_pretty(&json_output)?)?;
|
||||||
println!("Done! JSON saved to 'checksum'");
|
let elapsed = now.elapsed();
|
||||||
|
println!("Generated 'checksum', elapsed {:.2?}", elapsed);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue