public static ODF_File Read(byte[] rawBytes) { if (BitConverter.ToUInt16(rawBytes, 6) != 56) { throw new InvalidDataException("Unsupported ODF File version."); } ODF_File odfFile = new ODF_File(); odfFile.OdfEntries = new List <ODF_Entry>(); int count = BitConverter.ToInt32(rawBytes, 8); int offset = 16; for (int i = 0; i < count; i++) { int subCount = BitConverter.ToInt32(rawBytes, offset + 0); int subOffset = BitConverter.ToInt32(rawBytes, offset + 4) + 16; ODF_Entry odfEntry = new ODF_Entry(); odfEntry.OdfSubEntries = new List <ODF_SubEntry>(); for (int a = 0; a < subCount; a++) { odfEntry.OdfSubEntries.Add(ODF_SubEntry.Read(rawBytes, subOffset)); subOffset += 56; } odfFile.OdfEntries.Add(odfEntry); offset += 16; } return(odfFile); }
public static void Deserialize(string xmlPath) { string saveLocation = String.Format("{0}/{1}", Path.GetDirectoryName(xmlPath), Path.GetFileNameWithoutExtension(xmlPath)); YAXSerializer serializer = new YAXSerializer(typeof(ODF_File), YAXSerializationOptions.DontSerializeNullObjects); ODF_File odfFile = (ODF_File)serializer.DeserializeFromFile(xmlPath); byte[] bytes = odfFile.Write(); File.WriteAllBytes(saveLocation, bytes); }
public static ODF_File Serialize(string path, bool writeXml) { byte[] rawBytes = File.ReadAllBytes(path); ODF_File odfFile = Read(rawBytes); if (writeXml) { YAXSerializer serializer = new YAXSerializer(typeof(ODF_File)); serializer.SerializeToFile(odfFile, path + ".xml"); } return(odfFile); }