From 87b05277834b2e13adca2713d9d9956e36dba777 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 5 Dec 2016 15:57:23 -0500 Subject: [PATCH] Handle MTYP chunk --- src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index efe2d69..7a26a0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,6 +59,7 @@ pub struct NrgMetadata { pub cuex_chunk: Option, pub daox_chunk: Option, pub sinf_chunk: Option, + pub mtyp_chunk: Option, } impl NrgMetadata { @@ -70,6 +71,7 @@ impl NrgMetadata { cuex_chunk: None, daox_chunk: None, sinf_chunk: None, + mtyp_chunk: None, } } } @@ -98,6 +100,11 @@ impl fmt::Display for NrgMetadata { Some(ref chunk) => try!(write!(f, "\n\n\ {}", chunk)), } + match self.mtyp_chunk { + None => {}, + Some(ref chunk) => try!(write!(f, "\n\n\ + {}", chunk)), + } Ok(()) } } @@ -330,6 +337,33 @@ impl fmt::Display for NrgSinf { } +#[derive(Debug)] +pub struct NrgMtyp { + pub size: u32, + pub unknown: u32, +} + +impl NrgMtyp { + fn new() -> NrgMtyp { + NrgMtyp { + size: 0, + unknown: 0, + } + } +} + +impl fmt::Display for NrgMtyp { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Chunk ID: MTYP\n\ + Chunk description: Media Type (?)\n\ + Chunk size: {} Bytes\n\ + Unknown field: 0x{:04X}", + self.size, + self.unknown) + } +} + + pub fn parse_nrg_metadata(img_name: String) -> Result { let mut nm = NrgMetadata::new(); @@ -402,8 +436,7 @@ fn read_nrg_chunks(fd: &mut File, nm: &mut NrgMetadata) -> Result "CDTX" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, "ETN2" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, "SINF" => { nm.sinf_chunk = Some(try!(read_nrg_sinf(fd))); }, - "MTYP" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, - // "MTYP" => { try!(read_nrg_mytp(fd)); }, + "MTYP" => { nm.mtyp_chunk = Some(try!(read_nrg_mtyp(fd))); }, "DINF" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, "TOCT" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, "RELO" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, @@ -604,7 +637,10 @@ fn read_nrg_sinf(fd: &mut File) -> Result { } -#[cfg(dead_code)] -fn read_nrg_mytp(fd: &mut File) -> Result { - unimplemented!(); +/// Reads the Media Type (?) chunk (MTYP). +fn read_nrg_mtyp(fd: &mut File) -> Result { + let mut chunk = NrgMtyp::new(); + chunk.size = try!(read_u32(fd)); + chunk.unknown = try!(read_u32(fd)); + Ok(chunk) }