diff --git a/src/lib.rs b/src/lib.rs index db8214a..efe2d69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,6 +58,7 @@ pub struct NrgMetadata { pub chunk_offset: u64, pub cuex_chunk: Option, pub daox_chunk: Option, + pub sinf_chunk: Option, } impl NrgMetadata { @@ -68,6 +69,7 @@ impl NrgMetadata { chunk_offset: 0, cuex_chunk: None, daox_chunk: None, + sinf_chunk: None, } } } @@ -91,6 +93,11 @@ impl fmt::Display for NrgMetadata { Some(ref chunk) => try!(write!(f, "\n\n\ {}", chunk)), } + match self.sinf_chunk { + None => {}, + Some(ref chunk) => try!(write!(f, "\n\n\ + {}", chunk)), + } Ok(()) } } @@ -296,6 +303,33 @@ impl fmt::Display for NrgDaoxTrack { } +#[derive(Debug)] +pub struct NrgSinf { + pub size: u32, + pub nb_tracks: u32, +} + +impl NrgSinf { + fn new() -> NrgSinf { + NrgSinf { + size: 0, + nb_tracks: 0, + } + } +} + +impl fmt::Display for NrgSinf { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Chunk ID: SINF\n\ + Chunk description: Session Information\n\ + Chunk size: {} Bytes\n\ + Number of tracks in the session: {}", + self.size, + self.nb_tracks) + } +} + + pub fn parse_nrg_metadata(img_name: String) -> Result { let mut nm = NrgMetadata::new(); @@ -367,9 +401,8 @@ fn read_nrg_chunks(fd: &mut File, nm: &mut NrgMetadata) -> Result "DAOX" => { nm.daox_chunk = Some(try!(read_nrg_daox(fd))); }, "CDTX" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, "ETN2" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, - "SINF" => { 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)); }, - // "SINF" => { try!(read_nrg_sinf(fd)); }, // "MTYP" => { try!(read_nrg_mytp(fd)); }, "DINF" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, "TOCT" => { try!(skip_unhandled_chunk(fd, &chunk_id)); }, @@ -562,9 +595,12 @@ fn read_nrg_daox_track(fd: &mut File) -> Result { } -#[cfg(dead_code)] -fn read_nrg_sinf(fd: &mut File) -> Result { - unimplemented!(); +/// Reads the NRG Session Information chunk (SINF). +fn read_nrg_sinf(fd: &mut File) -> Result { + let mut chunk = NrgSinf::new(); + chunk.size = try!(read_u32(fd)); + chunk.nb_tracks = try!(read_u32(fd)); + Ok(chunk) }