This commit is contained in:
dece 2020-04-30 19:00:57 +02:00
parent 1f239ce90d
commit d3c8dba0a4

View file

@ -12,28 +12,36 @@ use crate::utils::fs as fs_utils;
/// ///
/// Wraps around `extract_bnd` to load the BND from disk. /// Wraps around `extract_bnd` to load the BND from disk.
pub fn extract_bnd_file(bnd_path: &str, output_path: &str) -> Result<(), UnpackError> { pub fn extract_bnd_file(bnd_path: &str, output_path: &str) -> Result<(), UnpackError> {
let bnd = load_bnd_file(bnd_path)?; let (bnd, data) = load_bnd_file(bnd_path)?;
extract_bnd(bnd, output_path)?; extract_bnd(bnd, data, output_path)?;
Ok(()) Ok(())
} }
/// Extract BND contents to disk. /// 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<u8>, output_path: &str) -> Result<(), UnpackError> {
let output_path = path::Path::new(output_path); let output_path = path::Path::new(output_path);
fs_utils::ensure_dir_exists(output_path)?; fs_utils::ensure_dir_exists(output_path)?;
for info in &bnd.file_infos {
// TODO
}
//output_file.write_all(&decomp_data)?; //output_file.write_all(&decomp_data)?;
Ok(()) Ok(())
} }
/// Load a BND file from disk. /// Load a BND file from disk.
/// ///
/// Wraps around `load_bnd` to load the BND from disk. /// Wraps around `load_bnd` to load the BND from disk. It returns the
pub fn load_bnd_file(bnd_path: &str) -> Result<bnd::Bnd, UnpackError> { /// parsed BND metadata and the whole file as a byte vector.
pub fn load_bnd_file(bnd_path: &str) -> Result<(bnd::Bnd, Vec<u8>), UnpackError> {
let mut bnd_file = fs::File::open(bnd_path)?; let mut bnd_file = fs::File::open(bnd_path)?;
let file_len = bnd_file.metadata()?.len() as usize; let file_len = bnd_file.metadata()?.len() as usize;
let mut bnd_data = vec![0u8; file_len]; let mut bnd_data = vec![0u8; file_len];
bnd_file.read_exact(&mut bnd_data)?; 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. /// Load a BND file from a bytes slice.