jmrenamer: move DAT/MET filename code to jmmt crate

This commit is contained in:
Lily Tsuru 2023-06-25 18:39:44 -04:00
parent 88375f5581
commit d5f00adc95
3 changed files with 21 additions and 12 deletions

View File

@ -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)))
}

View File

@ -1,4 +1,5 @@
//! Hash Algorithms //! Hash Algorithms
pub mod crc32; pub mod crc32;
pub mod filename;
pub use crc32::*; pub use crc32::*;

View File

@ -3,7 +3,7 @@
//! of an extracted (from image) copy of the game. //! of an extracted (from image) copy of the game.
use std::{fs, io, path::Path}; use std::{fs, io, path::Path};
use jmmt::hash::hash_string; use jmmt::hash::filename::*;
const FILENAME_TABLE : [&str; 20] = [ const FILENAME_TABLE : [&str; 20] = [
// First loaded by the game // First loaded by the game
@ -38,16 +38,6 @@ const FILENAME_TABLE : [&str; 20] = [
"TR_training.pak" "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<()> { fn main() -> io::Result<()> {
// A relatively simple idiot-check. Later on utilities might have a shared library // 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 // Go through the clearname table and rename files in the DATA directory
for clearname in FILENAME_TABLE.iter() { 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_src = format!("DATA/{}", dat_filename);
let dat_clearname = format!("DATA/{}", String::from(*clearname)); let dat_clearname = format!("DATA/{}", String::from(*clearname));