internal List <sFsFileInfo> DeSerializeFAT(byte[] buffer) { var l = new List <sFsFileInfo>(); try { using (var ms = new MemoryStream(buffer)) { using (var br = new BinaryReader(ms, Encoding.UTF8)) { int magicByte = br.ReadByte(); if (magicByte != MAGIC_BYTE) { throw new ApplicationException("Magic byte not found"); } var fileCount = br.ReadInt32(); // 4 bytes, number of file stored on the disk for (var i = 0; i < fileCount; i++) { var fileName = BinSerializer.DeSerializeStringInUTF8(br.ReadBytes(sFsFileInfo.MAX_FILE_NAME_SIZE)); // 16 bytes l.Add(new sFsFileInfo(fileName, false) { StartAddr = br.ReadInt32(), // 4 bytes Length = br.ReadInt32(), // 4 bytes Attribute = (sFsFileAttribute)br.ReadByte(), // 1 bytes LastModificationDate = new DateTime(br.ReadInt64()) // 8 bytes }); } } } } catch (System.Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); return(null); } return(l); }
internal List <FileInfo> DeSerializeMetadata(byte[] buffer) { var l = new List <FileInfo>(); try { using (var ms = new MemoryStream(buffer)) { using (var br = new BinaryReader(ms, Encoding.UTF8)) { int magicByte = br.ReadByte(); if (magicByte != MAGIC_BYTE) { throw new ApplicationException("Magic byte not found"); } var fileCount = br.ReadInt32(); // 4 for (var i = 0; i < fileCount; i++) { var fileName = BinSerializer.DeSerializeStringInUTF8(br.ReadBytes(FileInfo.MAX_FILE_NAME_SIZE)); l.Add(new FileInfo(fileName) { StartPage = br.ReadInt32(), Length = br.ReadInt32(), Created = new DateTime(br.ReadInt64()) // 8 }); } } } } catch (System.Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); return(null); } return(l); }