private static ContentsDescriptionObject ReadContentsDescriptionObject(Stream strm, int offset = 0) { byte[] buf = new byte[18]; strm.Read(buf, offset, 18); ContentsDescriptionObject cd = new ContentsDescriptionObject(); cd.size = BitConverter.ToUInt64(buf, 0); cd.title_length = BitConverter.ToUInt16(buf, 8); cd.artist_length = BitConverter.ToUInt16(buf, 8 + 2); cd.copy_length = BitConverter.ToUInt16(buf, 8 + 2 + 2); cd.description_length = BitConverter.ToUInt16(buf, 8 + 2 + 2 + 2); cd.rating_length = BitConverter.ToUInt16(buf, 8 + 2 + 2 + 2 + 2); byte[] buf_body = new byte[cd.size - 18 - 16]; strm.Read(buf_body, offset, buf_body.Length); if (cd.title_length > 0) { cd.title = Encoding.Unicode.GetString(buf_body, 0, cd.title_length - 2); } if (cd.artist_length > 0) { cd.artist = Encoding.Unicode.GetString(buf_body, cd.title_length, cd.artist_length - 2); } if (cd.copy_length > 0) { cd.copyright = Encoding.Unicode.GetString(buf_body, cd.title_length + cd.artist_length, cd.copy_length - 2); } if (cd.description_length > 0) { cd.description = Encoding.Unicode.GetString(buf_body, cd.title_length + cd.artist_length + cd.copy_length, cd.description_length - 2); } if (cd.rating_length > 0) { cd.rating = Encoding.Unicode.GetString(buf_body, cd.title_length + cd.artist_length + cd.copy_length + cd.description_length, cd.rating_length - 2); } return(cd); }
public static List <KeyValuePair <string, object> > Read(Stream stream, bool createImageObject) { var header = new HeaderObject(); Guid guid = ReadGuid(stream); if (!guid.Equals(GUID_HEADER_OBJECT)) { return(null); } var buf = new byte[14]; stream.Read(buf, 0, 14); header.size = BitConverter.ToUInt64(buf, 0); header.count = BitConverter.ToUInt32(buf, 8); List <KeyValuePair <string, object> > ecd = null; List <KeyValuePair <string, object> > heo = null; ContentsDescriptionObject cd = default(ContentsDescriptionObject); for (int i = 0; i < header.count; i++) { var guid_sub = ReadGuid(stream, 0); Logger.Debug(guid_sub.ToString() + " , " + stream.Position); if (guid_sub.Equals(GUID_CONTENTS_DESCRIPTION_OBJECT)) { cd = ReadContentsDescriptionObject(stream, 0); } else if (guid_sub.Equals(GUID_EXTENDED_CONTENTS_DESCRIPTION_OBJECT)) { ecd = ReadExtendedContentsDescriptionObject(stream, 0); } else if (guid_sub.Equals(GUID_HEADER_EXTENSION_OBJECT)) { heo = ReadHeaderExtensionObject(stream, 0); } else { byte[] buf_size = new byte[8]; stream.Read(buf_size, 0, 8); stream.Seek((long)BitConverter.ToUInt64(buf_size, 0) - 16 - 8, SeekOrigin.Current); } } if (ecd != null) { if (ecd.Find((e) => e.Key == "TITLE").Key == null && !String.IsNullOrEmpty(cd.title)) { ecd.Add(new KeyValuePair <string, object>("TITLE", cd.title)); } if (ecd.Find((e) => e.Key == "ARTIST").Key == null && !String.IsNullOrEmpty(cd.artist)) { ecd.Add(new KeyValuePair <string, object>("ARTIST", cd.artist)); } if (ecd.Find((e) => e.Key == "COMMENT").Key == null && !String.IsNullOrEmpty(cd.description)) { ecd.Add(new KeyValuePair <string, object>("COMMENT", cd.description)); } if (heo != null) { ecd.AddRange(heo); } return(ecd); } else { var tag = new List <KeyValuePair <string, object> >(); if (cd.title != null) { tag.Add(new KeyValuePair <string, object>("TITLE", cd.title)); } if (cd.artist != null) { tag.Add(new KeyValuePair <string, object>("ARTIST", cd.artist)); } if (cd.description != null) { tag.Add(new KeyValuePair <string, object>("COMMENT", cd.description)); } return(tag); } }