1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-26 06:07:45 +00:00

Properly propagate errors up the stack for game_data::extract

This commit is contained in:
Joshua Goins 2022-08-09 22:43:04 -04:00
parent 22569cf09d
commit e094742690
2 changed files with 6 additions and 11 deletions

View file

@ -152,8 +152,7 @@ impl GameData {
pub fn extract(&self, path: &str) -> Option<MemoryBuffer> {
let hash = calculate_hash(path);
let index_file = self.get_index_file(path)
.expect("Failed to find index file.");
let index_file = self.get_index_file(path)?;
let slice = index_file.entries.iter().find(|s| s.hash == hash);
match slice {
@ -162,10 +161,7 @@ impl GameData {
dat_file.read_from_offset(entry.bitfield.offset())
}
None => {
println!("Entry not found.");
None
}
None => None
}
}
@ -188,9 +184,9 @@ impl GameData {
}
pub fn read_excel_sheet_header(&self, name : &str) -> Option<EXH> {
let root_exl_file = self.extract("exd/root.exl").unwrap();
let root_exl_file = self.extract("exd/root.exl")?;
let root_exl = EXL::from_existing(&root_exl_file).unwrap();
let root_exl = EXL::from_existing(&root_exl_file)?;
for (row, _) in root_exl.entries {
if row == name {
@ -198,7 +194,7 @@ impl GameData {
let path = format!("exd/{new_filename}.exh");
return EXH::from_existing(&self.extract(&path).unwrap())
return EXH::from_existing(&self.extract(&path)?)
}
}

View file

@ -74,8 +74,7 @@ pub struct IndexFile {
impl IndexFile {
/// Creates a new reference to an existing index file, this reads both an index and index2 file.
pub fn from_existing(path: &str) -> Option<IndexFile> {
let mut index_file = std::fs::File::open(path)
.expect("Failed to read index file.");
let mut index_file = std::fs::File::open(path).ok()?;
IndexFile::read(&mut index_file).ok()
}