diff --git a/crates/jmmt/src/hash/filename.rs b/crates/jmmt/src/hash/filename.rs new file mode 100644 index 0000000..749e6b0 --- /dev/null +++ b/crates/jmmt/src/hash/filename.rs @@ -0,0 +1,18 @@ +//! Utilities for making .DAT and .MET file names +//! +//! .DAT and .MET filenames are formatted like "{:X}.DAT" in fmt parlance. +//! The name component is the CRC32 of the original filename. +//! +//! The DAT/MET filename can be a max of 13 characters long. + +use super::crc32::hash_string; + +/// Make a .DAT filename from a cleartext filename. +pub fn dat_filename(filename: &str) -> String { + format!("{:X}.DAT", hash_string(String::from(filename))) +} + +/// Make a .MET filename from a cleartext filename. +pub fn met_filename(filename: &str) -> String { + format!("{:X}.MET", hash_string(String::from(filename))) +} diff --git a/crates/jmmt/src/hash/mod.rs b/crates/jmmt/src/hash/mod.rs index 9e08a55..72be017 100644 --- a/crates/jmmt/src/hash/mod.rs +++ b/crates/jmmt/src/hash/mod.rs @@ -1,4 +1,5 @@ //! Hash Algorithms pub mod crc32; +pub mod filename; pub use crc32::*; diff --git a/crates/jmrenamer/src/main.rs b/crates/jmrenamer/src/main.rs index 861361a..391e9ff 100644 --- a/crates/jmrenamer/src/main.rs +++ b/crates/jmrenamer/src/main.rs @@ -3,7 +3,7 @@ //! of an extracted (from image) copy of the game. use std::{fs, io, path::Path}; -use jmmt::hash::hash_string; +use jmmt::hash::filename::*; const FILENAME_TABLE : [&str; 20] = [ // First loaded by the game @@ -38,16 +38,6 @@ const FILENAME_TABLE : [&str; 20] = [ "TR_training.pak" ]; -/// Make a .DAT filename from a cleartext filename. -/// -/// .DAT and .MET filenames are formatted like "[hex char * 8].DAT" -/// The name component is the CRC32 of the original filename. -/// -/// The DAT/MET filename can be a max of 13 characters long. -fn hashed_dat_filename(filename: &str) -> String { - format!("{:X}.DAT", hash_string(String::from(filename))) -} - fn main() -> io::Result<()> { // A relatively simple idiot-check. Later on utilities might have a shared library @@ -59,7 +49,7 @@ fn main() -> io::Result<()> { // Go through the clearname table and rename files in the DATA directory for clearname in FILENAME_TABLE.iter() { - let dat_filename = hashed_dat_filename(clearname); + let dat_filename = dat_filename(clearname); let dat_src = format!("DATA/{}", dat_filename); let dat_clearname = format!("DATA/{}", String::from(*clearname));