public void ExportPkg(TextWriter textWriter) { using var dataStream = Fragment.GetDataStream(true); var package = PkgFile.ReadPkg(dataStream); package.WriteJson(textWriter); }
public void ImportPkg(Stream stream) { PkgFile pkg = PkgFile.ReadJson(stream); using (MemoryStream pkgData = new MemoryStream()) { pkg.WritePkg(pkgData); switch (Package.ResourceType) { case "AnimClip": case "AnimClipCrowd": Package.GetFragment("temp", 0).SetData(pkgData.ToArray()); break; case "EventGraph": Package.GetFragment("node", 0).SetData(pkgData.ToArray()); break; default: Package.Fragments[0].SetData(pkgData.ToArray()); break; } } }
public void ImportPkg(Stream stream) { var pkg = PkgFile.ReadJson(stream); using var ms = new MemoryStream(); pkg.WritePkg(ms); Fragment.SetData(ms.ToArray()); }
private void ImportExecute() { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); bool?result = openFileDialog.ShowDialog(); if (result == true) { FileStream f = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read); PkgFile.ImportDataFromStream(f); f.Close(); } }
private void ExportExecute() { Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog(); saveFileDialog.FileName = PkgFile.GetPreferredFileName(); bool?result = saveFileDialog.ShowDialog(); if (result == true) { FileStream f = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write); PkgFile.ExportDataToStream(f); f.Close(); } }
public static PkgData Create(PkgFile parentFile, string type) { switch (type) { case "stri": return(new PkgStringData(parentFile)); case "woid": return(new PkgWoidData(parentFile)); case "mat4": return(new PkgMat4Data(parentFile)); case "fp32": return(new PkgFp32Data(parentFile)); case "bool": return(new PkgBoolData(parentFile)); case "rgba": return(new PkgRgbaData(parentFile)); case "shnm": return(new PkgShnmData(parentFile)); case "vec3": return(new PkgVec3Data(parentFile)); case "ui32": return(new PkgUi32Data(parentFile)); case "si32": return(new PkgSi32Data(parentFile)); case "ui64": return(new PkgUi64Data(parentFile)); case "si64": return(new PkgSi64Data(parentFile)); case "vec4": return(new PkgVec4Data(parentFile)); case "quat": return(new PkgQuatData(parentFile)); default: throw new Exception("Data type not supported! " + type); } }
public void ExportPkg(TextWriter textWriter) { PkgFile package; switch (Package.ResourceType) { case "AnimClip": case "AnimClipCrowd": package = PkgFile.ReadPkg(Package.GetFragment("temp", 0).GetDataStream(true)); break; case "EventGraph": package = PkgFile.ReadPkg(Package.GetFragment("node", 0).GetDataStream(true)); break; default: package = PkgFile.ReadPkg(Package.Fragments[0].GetDataStream(true)); break; } package.WriteJson(textWriter); }
public static PkgData Create(PkgFile parentFile, string type) { return(type switch { "stri" => new PkgStringData(parentFile), "woid" => new PkgWoidData(parentFile), "mat4" => new PkgMat4Data(parentFile), "fp32" => new PkgFp32Data(parentFile), "bool" => new PkgBoolData(parentFile), "rgba" => new PkgRgbaData(parentFile), "shnm" => new PkgShnmData(parentFile), "vec3" => new PkgVec3Data(parentFile), "ui32" => new PkgUi32Data(parentFile), "si32" => new PkgSi32Data(parentFile), "ui64" => new PkgUi64Data(parentFile), "si64" => new PkgSi64Data(parentFile), "vec4" => new PkgVec4Data(parentFile), "quat" => new PkgQuatData(parentFile), "bbox" => new PkgBboxData(parentFile), "ui16" => new PkgUi16Data(parentFile), "ui08" => new PkgUi08Data(parentFile), _ => throw new Exception("Data type not supported! " + type), });
public override void LoadData(object data) { ClearData(); foreach (var resView in ((ResourcesWorkspaceViewModel)data).Resources) { var resource = resView.Resource; foreach (var fragment in resource.Fragments) { try { using var ds = fragment.GetDecompressDataStream(true); if (PkgFile.IsPkgFile(ds)) { Packages.Add(new ErpPackageViewModel(resView, fragment)); } } catch { // TODO: log } } } DisplayName = "Pkg Files " + packages.Count; }
public PkgWoidData(PkgFile parentFile) : base(parentFile) { }
public PkgShnmData(PkgFile parentFile) : base(parentFile) { }
public PkgQuatData(PkgFile parentFile) : base(parentFile) { }
public PkgMat4Data(PkgFile parentFile) : base(parentFile) { }
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."); } } } }
public FileEditViewModel(PkgFile pkgFile) { this.PkgFile = pkgFile; }
public PkgRgbaData(PkgFile parentFile) : base(parentFile) { }
public static PkgData Create(PkgBinaryReader reader, PkgFile parentFile) { return(Create(parentFile, reader.ReadString(4))); }
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 PkgUi64Data(PkgFile parentFile) : base(parentFile) { }
static void Main(string[] args) { if (args.Length == 0 || args.Length > 2) { PrintUsage(); return; } if (args.Length == 1) { if (args[0] == "--version") { PrintVersion(); return; } } bool verbose = false; if (args[0] == "-v") { verbose = true; Console.WriteLine("Verbose output mode is set"); } string sourcePath = args[args.Length - 1]; if (verbose) { Console.WriteLine("Source extract file is " + Path.GetFullPath(sourcePath)); } if (!File.Exists(sourcePath)) { Console.WriteLine("Could not find file at " + sourcePath + ". Please ensure that your filename is correct."); return; } Console.WriteLine("============================================================================"); Console.WriteLine("Starting extraction of rom from " + sourcePath + "..."); Console.WriteLine("============================================================================"); string extractedRomPath = ""; RpxFile rpxFile = null; PsbFile psbFile = null; PkgFile pkgFile = null; SrlFile srlFile = null; // Identifies filetype of the file argument, // then instantiates file with file's location and verbose if (RpxFile.IsRpx(sourcePath)) { Console.WriteLine("RPX file detected!"); rpxFile = new RpxFile(sourcePath, verbose); } else if (PsbFile.IsPsb(sourcePath)) { Console.WriteLine("PSB file detected!"); psbFile = new PsbFile(sourcePath, verbose); } else if (PkgFile.IsPkg(sourcePath)) { pkgFile = new PkgFile(sourcePath, verbose); } else if (SrlFile.IsSrl(sourcePath)) { Console.WriteLine("SRL file detected!"); srlFile = new SrlFile(sourcePath, verbose); } // Create the list of rom extractors List <IRomExtractor> romExtractors = new List <IRomExtractor>(); if (rpxFile != null) { romExtractors.Add(new NesVcExtractor(rpxFile, verbose)); romExtractors.Add(new SnesVcExtractor(rpxFile.DecompressedPath, verbose)); romExtractors.Add(new FdsVcExtractor(rpxFile, verbose)); } else if (psbFile != null) { romExtractors.Add(new GbaVcExtractor(psbFile, verbose)); } else if (pkgFile != null) { romExtractors.Add(new PceVcExtractor(pkgFile, verbose)); } else if (Path.GetExtension(sourcePath) == ".sfrom") { romExtractors.Add(new SnesVcExtractor(sourcePath, verbose)); } else if (srlFile != null) { romExtractors.Add(new DsVcExtractor(srlFile, verbose)); } // Check with each extractor until a valid rom is found, // Then extract the rom with the appropriate extractor foreach (var romExtractor in romExtractors) { if (romExtractor.IsValidRom()) { extractedRomPath = romExtractor.ExtractRom(); break; } } if (!String.IsNullOrEmpty(extractedRomPath)) { Console.WriteLine("============================================================================"); Console.WriteLine(sourcePath + " has been extracted to " + extractedRomPath + " successfully."); Console.WriteLine("============================================================================"); } else { Console.WriteLine("============================================================================"); Console.WriteLine("FAILURE: Could not successfully identify the rom type for " + sourcePath); Console.WriteLine("============================================================================"); } }
public PkgFp32Data(PkgFile parentFile) : base(parentFile) { }
public PkgDataList(PkgFile parentFile) : base(parentFile) { values = new List <T>(); }
public PkgBoolData(PkgFile parentFile) : base(parentFile) { }
public PkgVec3Data(PkgFile parentFile) : base(parentFile) { }
public PkgStringData(PkgFile parentFile) : base(parentFile) { strgOffset = new Dictionary <string, int>(); strgData = new MemoryStream(); }
public PceVcExtractor(PkgFile pkgFile, bool verbose = false) { this.verbose = verbose; this.pkgFile = pkgFile; }