WAD Refactor

Refactored some of the code for the wadfile reading. Moved out the
readers into their own separate file, and moved some utilities around to
create wad utilities for more modularity.
This commit is contained in:
2025-03-31 19:30:26 -04:00
parent 8de9d56c2d
commit fb802a8d2b
7 changed files with 93 additions and 87 deletions

26
src/wad/wadfile/utils.rs Normal file
View File

@@ -0,0 +1,26 @@
use std::fs::File;
use std::io::{self, Read};
use std::path::Path;
/// Validates a WAD file to make sure that it is a legitimate file
///
/// Parameters:
/// - path: &str - Path to the WAD to validate
pub fn validate_wad(path: &str) -> io::Result<bool> {
let wad_file = Path::new(path);
// Check to see if the WAD exists
if !(wad_file.exists()) {
// Return back false because we didn't pass a valid file
return Ok(false);
}
// If the file exists open it and read the first 4 bytes
// of the file and see if we get "IWAD" or "PWAD"
let mut file = File::open(wad_file)?;
let mut magic = [0u8; 4];
file.read_exact(&mut magic)?;
// Now we return based on what we found
Ok(magic == *b"IWAD" || magic == *b"PWAD")
}