private void compareFilesToolStripMenuItem_Click(object sender, EventArgs e) { if (lngFile == null) { return; } openFileDialog.FilterIndex = 1; openFileDialog.InitialDirectory = Path.GetDirectoryName(filePath); openFileDialog.FileName = Path.GetFileName(filePath).Replace(".xml", ".lng"); if (openFileDialog.ShowDialog() == DialogResult.OK) { try { LngFile two = new LngFile(File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)); openFileDialog.Dispose(); saveFileDialog.FilterIndex = 2; saveFileDialog.InitialDirectory = Path.GetDirectoryName(filePath); saveFileDialog.FileName = Path.GetFileName(filePath).Replace(".lng", "Differences.xml"); if (saveFileDialog.ShowDialog() == DialogResult.OK) { LngFile differences = lngFile.GetDifferences(two); differences.WriteXml(File.Open(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)); saveFileDialog.Dispose(); } } catch (Exception ex) { MessageBox.Show("The program failed to compare the files:" + Environment.NewLine + Environment.NewLine + ex.Message, "Ego Language Editor", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void exportAsXMLToolStripMenuItem_Click(object sender, EventArgs e) { if (lngFile != null) { saveFileDialog.FilterIndex = 2; saveFileDialog.InitialDirectory = Path.GetDirectoryName(filePath); saveFileDialog.FileName = Path.GetFileName(filePath).Replace(".lng", ".xml"); if (saveFileDialog.ShowDialog() == DialogResult.OK) { LNG = lngFile.WriteXml(File.Open(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read), (DataTable)lngDataGridView.DataSource); saveFileDialog.Dispose(); } } else { MessageBox.Show("There must already be an opened language file in order to save it as an xml file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private static void Convert(string f) { string magic; string xmlMagic; using (var fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)) { PkgBinaryReader reader = new PkgBinaryReader(fs); magic = reader.ReadString(4); // Skip first byte since BXMLBig starts with \0 causing empty string reader.Seek(1, SeekOrigin.Begin); xmlMagic = reader.ReadString(3); } if (xmlMagic == "\"Rr" || xmlMagic == "BXM") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read); XmlFile file = new XmlFile(fsi); file.Write(fso, XMLType.Text); Console.WriteLine("Success! XML converted."); } else if (magic == "LNGT") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read); LngFile file = new LngFile(fsi); file.WriteXml(fso); Console.WriteLine("Success! Lng converted."); } else if (magic == "!pkg") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); using var fso = File.Open(f + ".json", FileMode.Create, FileAccess.Write, FileShare.Read); PkgFile file = PkgFile.ReadPkg(fsi); file.WriteJson(fso); Console.WriteLine("Success! Pkg converted."); } else { bool isJSON = false; JsonException jsonEx = null; try { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); using var fso = File.Open(f + ".pkg", FileMode.Create, FileAccess.Write, FileShare.Read); PkgFile pkgFile = PkgFile.ReadJson(fsi); pkgFile.WritePkg(fso); Console.WriteLine("Success! JSON converted."); isJSON = true; } catch (JsonException e) { jsonEx = e; } if (!isJSON) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(f); } catch (XmlException e) { throw new AggregateException("Could not determine the file type! Showing json, and xml errors: ", jsonEx, e); } if (xmlDoc.DocumentElement.Name == "language") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); using var fso = File.Open(f + ".lng", FileMode.Create, FileAccess.Write, FileShare.Read); DataSet dataSet = new DataSet("language"); dataSet.ReadXml(fsi, XmlReadMode.ReadSchema); LngFile file = new LngFile(dataSet); file.Write(fso); Console.WriteLine("Success! XML converted."); } else { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read); XmlFile file = new XmlFile(fsi); file.Write(fso); Console.WriteLine("Success! XML converted."); } } } }
private static void Convert(string f) { var fileName = Path.GetFileName(f); var ext = Path.GetExtension(f); string magic; string xmlMagic; using (var fs = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read)) { PkgBinaryReader reader = new PkgBinaryReader(fs); magic = reader.ReadString(4); // Skip first byte since BXMLBig starts with \0 causing empty string reader.Seek(1, SeekOrigin.Begin); xmlMagic = reader.ReadString(3); } if (xmlMagic == "\"Rr" || xmlMagic == "BXM") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); XmlFile file = new XmlFile(fsi); using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read); file.Write(fso, XMLType.Text); Console.WriteLine("Success! XML converted."); } else if (magic == "LNGT") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); LngFile file = new LngFile(fsi); using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read); file.WriteXml(fso); Console.WriteLine("Success! Lng converted."); } else if (magic == "!pkg") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); PkgFile file = PkgFile.ReadPkg(fsi); using var fso = File.Open(f + ".json", FileMode.Create, FileAccess.Write, FileShare.Read); file.WriteJson(fso); Console.WriteLine("Success! Pkg converted."); } else if (ext == ".tpk") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); var tpk = new TpkFile(); tpk.Read(fsi); Console.WriteLine($"Tpk name '{tpk.Name}', image format '{tpk.Format}'."); var dds = tpk.ToDds(); using var fso = File.Open(f + ".dds", FileMode.Create, FileAccess.Write, FileShare.Read); dds.Write(fso, -1); Console.WriteLine("Success! Tpk converted."); } else if (fileName.EndsWith(".tpk.dds")) { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); var dds = new DdsFile(fsi); var tpk = new TpkFile() { Name = fileName.Remove(fileName.IndexOf('.')) }; tpk.FromDds(dds); using var fso = File.Open(f + ".tpk", FileMode.Create, FileAccess.Write, FileShare.Read); tpk.Write(fso); Console.WriteLine("Success! DDS converted."); } else { bool isJSON = false; JsonException jsonEx = null; try { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); PkgFile pkgFile = PkgFile.ReadJson(fsi); using var fso = File.Open(f + ".pkg", FileMode.Create, FileAccess.Write, FileShare.Read); pkgFile.WritePkg(fso); Console.WriteLine("Success! JSON converted."); isJSON = true; } catch (JsonException e) { jsonEx = e; } if (!isJSON) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(f); } catch (XmlException e) { throw new AggregateException("Could not determine the file type! Showing json, and xml errors: ", jsonEx, e); } if (xmlDoc.DocumentElement.Name == "language") { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); DataSet dataSet = new DataSet("language"); dataSet.ReadXml(fsi, XmlReadMode.ReadSchema); LngFile file = new LngFile(dataSet); using var fso = File.Open(f + ".lng", FileMode.Create, FileAccess.Write, FileShare.Read); file.Write(fso); Console.WriteLine("Success! XML converted."); } else { using var fsi = File.Open(f, FileMode.Open, FileAccess.Read, FileShare.Read); XmlFile file = new XmlFile(fsi); using var fso = File.Open(f + ".xml", FileMode.Create, FileAccess.Write, FileShare.Read); file.Write(fso); Console.WriteLine("Success! XML converted."); } } } }