private void dumpXMLToolStripMenuItem_Click(object sender, EventArgs e) { if (modFileList.SelectedNode != null) { DumpXML(ActiveMod.FileDirectory + "\\" + modFileList.SelectedNode.FullPath); } void DumpXML(string filepath) { try { string fileName = filepath + ".xml"; using (var writer = new FileStream(fileName, FileMode.Create)) using (var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(fs)) { var File = new CR2W.CR2WFile(reader); File.SerializeToXml(writer); } Logger.LogString("Dumping XML successful.", Logtype.Success); } catch (Exception ex) { Logger.LogString("Dumping XML failed.", Logtype.Error); } } }
private void dumpChunksToXMLToolStripMenuItem_Click(object sender, EventArgs e) { if (modFileList.SelectedNode != null) { SaveFileDialog sFileDialog = new SaveFileDialog { Filter = "XML File|*.xml", Title = "Save XML File", InitialDirectory = MainController.Get().Configuration.InitialFileDirectory + "\\" + modFileList.SelectedNode.FullPath, OverwritePrompt = true, FileName = ActiveMod.FileDirectory + "\\" + modFileList.SelectedNode.FullPath + ".chunk.xml" }; DialogResult result = sFileDialog.ShowDialog(); if (result == DialogResult.OK) { FileStream writer = new FileStream(sFileDialog.FileName, FileMode.Create); DumpChunkXML(writer); } } void DumpChunkXML(FileStream writer) { try { string filePath = ActiveMod.FileDirectory + "\\" + modFileList.SelectedNode.FullPath; string fileName = writer.Name; using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(fs)) { var File = new CR2W.CR2WFile(reader); File.FileName = modFileList.SelectedNode.FullPath; File.SerializeChunksToXml(writer); writer.Flush(); writer.Close(); } //vl: ugly way to suppress ugly xmlns string text = ""; using (StreamReader streamReader = File.OpenText(fileName)) //vl: TODO: what about encoding?? { text = streamReader.ReadToEnd(); text = text.Replace(" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); } File.WriteAllText(fileName, text); Logger.LogString("Dumping chunks XML successful.", Logtype.Success); } catch (Exception ex) { Logger.LogString(ex.Message, Logtype.Error); Logger.LogString(ex.StackTrace, Logtype.Error); Logger.LogString("Dumping chunks XML failed.", Logtype.Error); } } }