/// <summary> /// Replaces all SWF files in a specified PCC. As each export is scanned, if it is a GFX export and a correspondingly named packagename.sf file exists, it will be repalced. /// </summary> /// <param name="gfxSourceFolder">Source folder, with gfx files in the root.</param> /// <param name="destinationFile">File to update GFX files in</param> public static int replaceSWFs(string gfxSourceFolder, string destinationFile, BackgroundWorker worker = null) { bool replaced = false; string[] gfxfiles = System.IO.Directory.GetFiles(gfxSourceFolder, "*.swf"); List<String> packobjnames = new List<String>(); foreach (string gfxfile in gfxfiles) { string packobjname = Path.GetFileNameWithoutExtension(gfxfile); writeVerboseLine("SWF in source folder: " + packobjname); packobjnames.Add(packobjname); } if (gfxfiles.Length > 0) { string backupfile = destinationFile + ".bak"; if (File.Exists(backupfile)) { File.Delete(backupfile); } File.Move(destinationFile, backupfile); writeVerboseLine("Scanning " + destinationFile); int numReplaced = 0; PCCObject pcc = new PCCObject(backupfile); int numExports = pcc.Exports.Count; for (int i = 0; i < numExports; i++) { PCCObject.ExportEntry exp = pcc.Exports[i]; if (exp.ClassName == "GFxMovieInfo") { string packobjname = exp.PackageFullName + "." + exp.ObjectName; int index = packobjnames.IndexOf(packobjname); if (index > -1) { writeVerboseLine("#" + i + " Replacing " + exp.PackageFullName + "." + exp.ObjectName); replace_swf_file(exp, gfxfiles[index]); numReplaced++; replaced = true; } } if (worker != null && numReplaced % 10 == 0) { //Console.WriteLine("Progress: " + i + " / "+numExports); worker.ReportProgress((int)(((double)i / numExports) * 100)); } } writeVerboseLine("Replaced " + numReplaced + " files, saving."); if (replaced) { //pcc.saveByReconstructing(destinationFile); //34 is default Console.WriteLine("Saving pcc..."); pcc.save(destinationFile); return VerifyPCC(destinationFile); } else { Console.WriteLine("No SWFs replaced"); File.Move(backupfile, destinationFile); return 0; } } else { Console.WriteLine("No source GFX files were found."); return 1; } }
/// <summary> /// Replaces a single SWF file in a specified PCC. As each export is scanned, if it is a GFX export and the name matches the input gfx filename, it will be replaced. /// </summary> /// <param name="gfxFile">GFX file to insert (SWF)</param> /// <param name="destinationFile">File to update GFX files in</param> /// <param name="targetExport">Target export to scan for. If none is specified the filename is used as the packname/object name export to find</param> public static int replaceSingleSWF(string gfxFile, string destinationFile, string targetExport = null) { string inpackobjname = Path.GetFileNameWithoutExtension(gfxFile); if (targetExport != null) { inpackobjname = targetExport; } string backupfile = destinationFile + ".bak"; if (File.Exists(backupfile)) { File.Delete(backupfile); } File.Move(destinationFile, backupfile); writeVerboseLine("Scanning " + destinationFile); PCCObject pcc = new PCCObject(backupfile); int numExports = pcc.Exports.Count; bool replaced = false; for (int i = 0; i < numExports; i++) { PCCObject.ExportEntry exp = pcc.Exports[i]; if (exp.ClassName == "GFxMovieInfo") { string packobjname = exp.PackageFullName + "." + exp.ObjectName; if (packobjname.ToLower() == inpackobjname.ToLower()) { Console.WriteLine("#" + i + " Replacing " + exp.PackageFullName + "." + exp.ObjectName); replace_swf_file(exp, gfxFile); replaced = true; break; } } } if (replaced) { Console.WriteLine("Saving pcc..."); pcc.save(destinationFile); return VerifyPCC(destinationFile); } else { Console.WriteLine("No GFX file in the PCC with the name of " + inpackobjname + " was found."); File.Move(backupfile, destinationFile); return 1; } }