public override string GetData(Int32 index) { PkgBinaryReader reader = new PkgBinaryReader(strgData); reader.Seek(index, SeekOrigin.Begin); return(Type + " " + reader.ReadString()); }
public override void Read(PkgBinaryReader reader) { var numData = ReadHeader(reader); for (var i = 0; i < numData; ++i) { values.Add(reader.ReadString(16)); } }
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."); } } } }
public static PkgData Create(PkgBinaryReader reader, PkgFile parentFile) { return(Create(parentFile, reader.ReadString(4))); }