From ce85e8e8985666420eb0d03dc4f3611a4bb7de98 Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 14 Apr 2020 18:39:42 +0200 Subject: [PATCH] rustfmt --- src/name_hashes.rs | 1 - src/parsers/bhd.rs | 67 +++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/name_hashes.rs b/src/name_hashes.rs index 16b360c..4065eb3 100644 --- a/src/name_hashes.rs +++ b/src/name_hashes.rs @@ -36,7 +36,6 @@ pub fn load_name_map(path: &str) -> Result, Error> { names.insert(hash.to_string(), name[2..].to_string()); } } - println!("{:?}", names); Ok(names) } diff --git a/src/parsers/bhd.rs b/src/parsers/bhd.rs index 8948dd9..6786868 100644 --- a/src/parsers/bhd.rs +++ b/src/parsers/bhd.rs @@ -1,17 +1,18 @@ use std::collections::HashMap; -use std::fs::File; +use std::fs; +use std::io; extern crate nom; -use nom::{IResult}; use nom::combinator::verify; use nom::multi::count; use nom::number::complete::*; use nom::sequence::tuple; +use nom::IResult; #[derive(Debug)] pub struct BhdHeader { pub magic: u32, - pub unk04: i8, // PC=0, PS3=-1 + pub unk04: i8, // PC=0, PS3=-1 pub unk05: i8, pub unk06: i8, pub unk07: i8, @@ -24,23 +25,28 @@ pub struct BhdHeader { const MAGIC: u32 = 0x35444842; fn parse_header(i: &[u8]) -> IResult<&[u8], BhdHeader> { - let (i, (magic, flags, unk08, file_len, num_buckets, ofs_buckets)) = - tuple(( - verify(le_u32, |m| *m == MAGIC), - count(le_i8, 4), - le_u32, - le_u32, - le_u32, - le_u32, - ))(i)?; - Ok((i, BhdHeader { - magic, - unk04: flags[0], unk05: flags[1], unk06: flags[2], unk07: flags[3], - unk08, - file_len, - num_buckets, - ofs_buckets, - })) + let (i, (magic, flags, unk08, file_len, num_buckets, ofs_buckets)) = tuple(( + verify(le_u32, |m| *m == MAGIC), + count(le_i8, 4), + le_u32, + le_u32, + le_u32, + le_u32, + ))(i)?; + Ok(( + i, + BhdHeader { + magic, + unk04: flags[0], + unk05: flags[1], + unk06: flags[2], + unk07: flags[3], + unk08, + file_len, + num_buckets, + ofs_buckets, + }, + )) } #[derive(Debug)] @@ -79,7 +85,7 @@ pub fn parse(i: &[u8]) -> IResult<&[u8], Bhd> { let (i, header) = parse_header(i)?; let (i, bucket_infos) = count(parse_bucket_info, header.num_buckets as usize)(i)?; - let mut buckets: Vec> = vec!(); + let mut buckets: Vec> = vec![]; for b in 0..header.num_buckets { let bucket_info = &bucket_infos[b as usize]; let bucket_data = &full_file[bucket_info.offset as usize..]; @@ -87,10 +93,23 @@ pub fn parse(i: &[u8]) -> IResult<&[u8], Bhd> { buckets.push(bucket); } - Ok((i, Bhd { header, bucket_infos, buckets })) + Ok(( + i, + Bhd { + header, + bucket_infos, + buckets, + }, + )) } /// Extract files from a BHD/BDT pair. -pub fn extract(bhd: &Bhd, bdt_file: &File, names: &HashMap, outputpath: &str) { - // TODO +pub fn extract( + bhd: &Bhd, + bdt_file: &fs::File, + names: &HashMap, + outputpath: &str, +) -> Result<(), io::Error> { + fs::create_dir(outputpath)?; + Ok(()) }