public static TObject Deserialize <TObject>(String inFile, ByteOrderEnum byteOrder = ByteOrderEnum.BigEndian, Boolean writeLog = false) where TObject : class { using (MemoryStream ms = new MemoryStream()) { var xmlDoc = CryXmlSerializer.ReadFile(inFile, byteOrder, writeLog); xmlDoc.Save(ms); ms.Seek(0, SeekOrigin.Begin); XmlSerializer xs = new XmlSerializer(typeof(TObject)); return(xs.Deserialize(ms) as TObject); } }
public void Smelt(String path, Boolean overwrite = true) { this._overwrite = overwrite; try { if (File.Exists(path)) { if (Path.GetExtension(path) == ".dcb") { using (BinaryReader br = new BinaryReader(File.OpenRead(path))) { var legacy = new FileInfo(path).Length < 0x0e2e00; var df = new DataForge(br, legacy); df.Save(Path.ChangeExtension(path, "xml")); } } else { if (!_overwrite) { if (!File.Exists(Path.ChangeExtension(path, "raw"))) { File.Move(path, Path.ChangeExtension(path, "raw")); path = Path.ChangeExtension(path, "raw"); } } var xml = CryXmlSerializer.ReadFile(path); if (xml != null) { xml.Save(Path.ChangeExtension(path, "xml")); } else { Console.WriteLine("{0} already in XML format", path); } } } } catch (Exception ex) { Console.WriteLine("Error converting {0}: {1}", path, ex.Message); } }