From d3c8dba0a4a17be30ee9d1c093282a53da5cd971 Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 30 Apr 2020 19:00:57 +0200 Subject: [PATCH] bnd: WIP --- src/unpackers/bnd.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/unpackers/bnd.rs b/src/unpackers/bnd.rs index 68c9137..20e2a8c 100644 --- a/src/unpackers/bnd.rs +++ b/src/unpackers/bnd.rs @@ -12,28 +12,36 @@ use crate::utils::fs as fs_utils; /// /// Wraps around `extract_bnd` to load the BND from disk. pub fn extract_bnd_file(bnd_path: &str, output_path: &str) -> Result<(), UnpackError> { - let bnd = load_bnd_file(bnd_path)?; - extract_bnd(bnd, output_path)?; + let (bnd, data) = load_bnd_file(bnd_path)?; + extract_bnd(bnd, data, output_path)?; Ok(()) } /// Extract BND contents to disk. -pub fn extract_bnd(bnd: bnd::Bnd, output_path: &str) -> Result<(), UnpackError> { +/// +/// Files in the BND are written in the output_path directory, creating it if needed, without +/// preserving directory structure. If the BND do not contain paths, it will be named after its ID. +/// If it does not have IDs, consecutive integers will be used. +pub fn extract_bnd(bnd: bnd::Bnd, data: Vec, output_path: &str) -> Result<(), UnpackError> { let output_path = path::Path::new(output_path); fs_utils::ensure_dir_exists(output_path)?; + for info in &bnd.file_infos { + // TODO + } //output_file.write_all(&decomp_data)?; Ok(()) } /// Load a BND file from disk. /// -/// Wraps around `load_bnd` to load the BND from disk. -pub fn load_bnd_file(bnd_path: &str) -> Result { +/// Wraps around `load_bnd` to load the BND from disk. It returns the +/// parsed BND metadata and the whole file as a byte vector. +pub fn load_bnd_file(bnd_path: &str) -> Result<(bnd::Bnd, Vec), UnpackError> { let mut bnd_file = fs::File::open(bnd_path)?; let file_len = bnd_file.metadata()?.len() as usize; let mut bnd_data = vec![0u8; file_len]; bnd_file.read_exact(&mut bnd_data)?; - load_bnd(&bnd_data) + Ok((load_bnd(&bnd_data)?, bnd_data)) } /// Load a BND file from a bytes slice.