static void ImportPP(string filename, IList <ISubfile> FilesAdding, Regex regex, Regex unencodedRegex) { ppParser pp = new ppParser(filename); string name = Path.GetFileName(filename); int imported = 0; foreach (ppSubfile file in pp.Subfiles) { string fullName = name + "/" + file.Name; if (regex.IsMatch(fullName)) { if (unencodedRegex.IsMatch(fullName)) { FilesAdding.Add( new PPeX.Subfile( new PPSource(file), file.Name, name, ArchiveFileType.Raw)); } else { FilesAdding.Add( new PPeX.Subfile( new PPSource(file), file.Name, name)); } imported++; } } Console.WriteLine("Imported " + imported + "/" + pp.Subfiles.Count + " files"); }
public void injectTest() { Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp"), Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp did not deploy"); form.refreshModList(); var subfiles = new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles; Dictionary <string, uint> CRCValues = new Dictionary <string, uint>(); foreach (IWriteFile kv in subfiles) { using (MemoryStream mem = new MemoryStream()) { kv.WriteTo(mem); byte[] buffer = new byte[mem.Length]; mem.Position = 0; mem.Read(buffer, 0, (int)mem.Length); var value = DamienG.Security.Cryptography.Crc32.Compute(buffer); CRCValues.Add(kv.Name, value); } } foreach (ListViewItem lv in form.lsvMods.Items) { lv.Checked = true; } Assert.IsTrue(form.inject(true, true, true), "Installation injection failed. Log: {0}", form.labelStatus.Text); foreach (Mod m in form.modDict.Values) { Assert.IsTrue(m.Installed, "Backup archive for {0} was not created.", m.Name); } Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2e04_00_TEST.pp"), "jg2e04_00_TEST.pp was not created."); Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p01_00_TEST.pp"), "jg2p01_00_TEST.pp was not created."); Dictionary <string, uint> diff = new Dictionary <string, uint>(); foreach (IWriteFile kv in new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles) { using (MemoryStream mem = new MemoryStream()) { kv.WriteTo(mem); byte[] buffer = new byte[mem.Length]; mem.Position = 0; mem.Read(buffer, 0, (int)mem.Length); var value = DamienG.Security.Cryptography.Crc32.Compute(buffer); if (CRCValues[kv.Name] != value) { diff.Add(kv.Name, value); } } } Dictionary <string, uint> TrueCRC = new Dictionary <string, uint>() { { "jg2_01_05_00.lst", 838774076 }, { "jg2_01_05_01.lst", 1767953068 }, { "jg2_01_05_02.lst", 1609570759 }, { "jg2_01_05_03.lst", 4121681499 }, { "jg2_01_06_05.lst", 32814373 }, { "jg2_01_06_06.lst", 2454317916 }, { "jg2_01_06_08.lst", 3999174270 } }; //Assert.IsFalse(subfiles.Count == new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles.Count, "Subfiles have not changed."); Assert.IsTrue(diff.Count == TrueCRC.Count, "Amount of changes in jg2p00_00_00.pp was incorrect. Expected value: {0}; Actual value: {1}", TrueCRC.Count, diff.Count); foreach (KeyValuePair <string, uint> kv in TrueCRC) { Assert.IsTrue(kv.Value == diff[kv.Key], "CRC check failed after installation. Key: {0}; Expected value: {1}; Actual value: {2}", kv.Key, kv.Value, diff[kv.Key]); } foreach (ListViewItem lv in form.lsvMods.Items) { lv.Checked = false; } Assert.IsTrue(form.inject(false, false, true), "Uninstallation injection failed. Log: {0}", form.labelStatus.Text); Assert.IsTrue(!File.Exists(Environment.CurrentDirectory + @"\testdir\jg2e04_00_TEST.pp"), "jg2e04_00_TEST.pp was not deleted."); Assert.IsTrue(!File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p01_00_TEST.pp"), "jg2p01_00_TEST.pp was not deleted."); foreach (Mod m in form.modDict.Values) { Assert.IsTrue(!m.Installed, "Backup archive for {0} was not deleted.", m.Name); } Assert.IsTrue(subfiles.Count == new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles.Count, "Amount of restored changes in jg2p00_00_00.pp was incorrect. Expected value: {0}; Actual value: {1}", new object[] { subfiles.Count, new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles.Count }); foreach (IWriteFile kv in new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles) { using (MemoryStream mem = new MemoryStream()) { kv.WriteTo(mem); byte[] buffer = new byte[mem.Length]; mem.Position = 0; mem.Read(buffer, 0, (int)mem.Length); var value = DamienG.Security.Cryptography.Crc32.Compute(buffer); Assert.IsTrue(CRCValues[kv.Name] == value, "CRC check failed after uninstallation. Key: {0}; Expected value: {1}; Actual value: {2}", kv.Name, CRCValues[kv.Name], value); } } Assert.IsTrue(Console.ConsoleLog.Count > 0, "Nothing was written to internal console log."); Assert.IsTrue(form.rtbConsole.TextLength > 0, "Nothing was written to external console log."); Configuration.saveMods(form.modDict); }
static void Main(string[] args) { #if DEBUG System.Diagnostics.Debugger.Launch(); #endif ConsoleWriter.WriteLineFormat("AA2Pack v{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()); ConsoleWriter.WriteLineFormat("by {0}", "drpavel"); ConsoleWriter.WriteLine(); if (args.Length == 0 || args.ContainsSwitch("h")) { PrintHelp(); #if DEBUG Console.ReadKey(); #endif return; } bool suppress = args.ContainsSwitch("y"); foreach (string s in args) { if (File.Exists(s)) { //extracting a .pp ConsoleWriter.WriteLineFormat("Processing {0}...", Path.GetFileName(s)); ppParser pp = new ppParser(s); string dirPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(s)), Path.GetFileNameWithoutExtension(s)); if (Directory.Exists(dirPath)) { if (!suppress && !PromptUser("Are you sure you want to overwrite \"" + dirPath + "\"?")) { continue; } } else { Directory.CreateDirectory(dirPath); } int i = 0; foreach (IWriteFile iw in pp.Subfiles) { string path = Path.Combine(dirPath, iw.Name); using (FileStream fs = new FileStream(path, FileMode.Create)) iw.WriteTo(fs); ConsoleWriter.WriteLineFormat("[{0}/{1}] Processed {2}... ({3})", (++i).ToString(), //processed subfiles pp.Subfiles.Count.ToString(), //total subfiles iw.Name, //current subfile string.Format("{0}", Math.Round((double)100 * i / pp.Subfiles.Count) + "%")); } ConsoleWriter.WriteLine(); } else if (Directory.Exists(s)) { //packing into a .pp string ppPath = Path.GetFullPath(s).TrimEnd('\\') + ".pp"; if (File.Exists(ppPath)) { if (!suppress && !PromptUser("Are you sure you want to overwrite \"" + ppPath + "\"?")) { continue; } else { File.Delete(ppPath); } } ppParser pp = new ppParser(ppPath); foreach (string file in Directory.GetFiles(s)) { pp.Subfiles.Add(new Subfile(file)); } var bg = pp.WriteArchive(ppPath, false); bg.ProgressChanged += (sender, e) => { ConsoleWriter.ClearLine(); ConsoleWriter.WriteFormat("Writing " + ppPath + "... ({0})", e.ProgressPercentage + "%"); }; bg.RunWorkerAsync(); while (bg.IsBusy) { System.Threading.Thread.Sleep(50); } ConsoleWriter.ClearLine(); ConsoleWriter.WriteLineFormat("Writing " + ppPath + "... ({0})", "100%"); } } #if DEBUG Console.ReadKey(); #endif }
static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Usage: gdimport <folderWithPPFiles> <dstdir> <basename>"); return(1); } string dstDir = args[1] + "/"; string dName = args[2]; Directory.CreateDirectory(dstDir + dName); var wr = new XXGLTFWriter(dstDir, dName); foreach (var ppName in Directory.GetFiles(args[0], "*.pp", SearchOption.AllDirectories)) { var name = Path.GetFileName(ppName); var bn = Path.GetFileNameWithoutExtension(name); //Directory.CreateDirectory(dstDir + bn); using var ppStream = File.OpenRead(ppName); var fmt = ppFormat.GetFormat(ppStream, out var hdr); if (fmt == null) { continue; } Console.WriteLine(ppName); var parser = new ppParser(ppStream, fmt); foreach (ppSubfile sub in parser.Subfiles) { var ext = Path.GetExtension(sub.Name).Substring(1); switch (ext) { case "tga": case "bmp": wr.SaveTexture(sub.CreateReadStream(), sub.Name); break; case "lst": continue; var lst = new lstParser(sub.CreateReadStream(), sub.Name); File.WriteAllText(dstDir + bn + "/" + sub.Name, lst.Text); break; case "xx": Console.WriteLine(sub.Name); var xx = new xxParser(sub.CreateReadStream(), Path.GetFileNameWithoutExtension(sub.Name)); wr.AddScene(xx); break; default: // Console.WriteLine("Unhandled "+sub.Name); break; } // stop on skeleton if (wr.skins != null && wr.skins.Count > 0) { break; } } } wr.Save(); var usedImages = new HashSet <string>(); foreach (var i in wr.images) { if (!File.Exists(dstDir + i.uri)) { Console.WriteLine("{0} referenced, but does not exist", i.uri); } usedImages.Add(i.uri); } foreach (var pic in Directory.GetFiles(dstDir + dName)) { if (!pic.EndsWith(".png")) { continue; } var cp = dName + "/" + Path.GetFileName(pic); if (!usedImages.Contains(cp)) { Console.WriteLine("{0} pruned.", cp); File.Delete(pic); } } return(0); }
private void btnTest_Click(object sender, EventArgs e) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); //string dir = textBox1.Text;//@"C:\Users\Admin\Documents\GitHub\AA2Install\AA2Pack\bin\x86\Release\jg2p07_00_00"; foreach (ListViewItem item in lsvFiles.Items) //ParallelOptions opt = new ParallelOptions(); //opt.MaxDegreeOfParallelism = 6; //Parallel.ForEach(lsvFiles.Items.Cast<ListViewItem>(), opt, item => { string entry = item.Text; string name = Path.GetFileName(entry); ExtendedArchiveWriter writer = null; if (name.EndsWith(".ppx")) { using (FileStream fs = new FileStream(entry.Replace(".ppx", ".pp"), FileMode.Create)) { byte[] buffer = PPeX.Utility.CreateHeader(new ExtendedArchive(entry)); fs.Write(buffer, 0, buffer.Length); } } else if (name.EndsWith(".pp")) { writer = new ExtendedArchiveWriter(entry + "x", name); ppParser pp = new ppParser(entry); List <ppSubfile> read = pp.Subfiles.Cast <ppSubfile>().ToList(); /*Parallel.ForEach(read, subfile => * { * var arc = new ArchiveFile(new PPSource(subfile), subfile.Name); * lock (writer) * { * writer.Files.Add(arc); * } * * });*/ foreach (IReadFile subfile in pp.Subfiles) { //writer.Files.Add(new ArchiveFile(new PPSource(subfile), subfile.Name)); Application.DoEvents(); } } else { writer = new ExtendedArchiveWriter(entry + ".ppx", name + ".pp"); foreach (string file in Directory.EnumerateFiles(entry)) { if (file.EndsWith("ogg")) { continue; } // writer.Files.Add(new ArchiveFile(new FileSource(file), Path.GetFileName(file))); Application.DoEvents(); } } sw.Stop(); //MessageBox.Show(sw.Elapsed.TotalMilliseconds.ToString()); sw.Restart(); if (writer != null) { writer.Write(); } item.ForeColor = Color.ForestGreen; Application.DoEvents(); //}); } sw.Stop(); MessageBox.Show(sw.Elapsed.TotalMilliseconds.ToString()); }