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.
27 lines
774 B
Rust
27 lines
774 B
Rust
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")
|
|
}
|