private void extractFile(int n, string exportLocation) { MemoryStream m = DLC.DecompressEntry(n); FileStream fs = new FileStream(exportLocation, FileMode.Create, FileAccess.Write); fs.Write(m.ToArray(), 0, (int)m.Length); fs.Close(); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode t = treeView1.SelectedNode; if (t == null || t.Parent == null || t.Parent.Text != "FileEntries") { return; } int n = t.Index; hb1.ByteProvider = new DynamicByteProvider(DLC.DecompressEntry(n).ToArray()); }
public static List <string> DLCExtractHelper(string file) { // KFreon: Ditching this stuff for Fobs ExtractAllDLC function in Texplorer2.cs // NOTE that the files are normally collected here, now done in Texplorer2.cs return(new List <string>()); List <string> ExtractedFiles = new List <string>(); string[] dlcname = file.Split('\\'); DebugOutput.PrintLn("Temp extracting DLC: " + dlcname[dlcname.Length - 3]); DLCPackage dlc = new DLCPackage(file); List <string> dlcpath = new List <string>(dlc.MyFileName.Split('\\')); dlcpath.RemoveRange(dlcpath.Count - 5, 5); string dlcExtractionPath = String.Join("\\", dlcpath.ToArray()); List <int> Indicies = new List <int>(); for (int i = 0; i < dlc.Files.Count(); i++) { DLCPackage.FileEntryStruct entry = dlc.Files[i]; if (Path.GetExtension(entry.FileName).ToLower() == ".pcc" || Path.GetExtension(entry.FileName).ToLower() == ".tfc") { DebugOutput.PrintLn("Extracting: " + dlc.Files[i].FileName); try { Directory.CreateDirectory(Path.GetDirectoryName(dlcExtractionPath + dlc.Files[i].FileName)); using (FileStream fs = new FileStream(dlcExtractionPath + dlc.Files[i].FileName, FileMode.CreateNew)) dlc.DecompressEntry(i).WriteTo(fs); Indicies.Add(i); } catch (Exception e) { DebugOutput.PrintLn("File " + dlcExtractionPath + entry.FileName + " already exists. Extra: " + e.Message); Console.WriteLine(e.Message); } ExtractedFiles.Add(dlcExtractionPath + entry.FileName); } } dlc.DeleteEntry(Indicies); return(ExtractedFiles); }
public void TestSFARParsing() { GlobalTest.Init(); // Loads compressed packages and attempts to enumerate every object's properties. var sfarsPath = GlobalTest.GetTestSFARsDirectory(); var sfars = Directory.GetFiles(sfarsPath, "*.sfar", SearchOption.AllDirectories); foreach (var s in sfars) { var expectedCompressionType = Path.GetFileNameWithoutExtension(s); Console.WriteLine($"Opening SFAR {s}"); DLCPackage dlc = new DLCPackage(s); Assert.AreEqual(expectedCompressionType, dlc.Header.CompressionScheme); // Enumerate files foreach (var f in dlc.Files) { var lookup = dlc.FindFileEntry(Path.GetFileName(f.FileName)); Assert.AreEqual(dlc.Files[lookup], f); var de = dlc.DecompressEntry(lookup); Assert.AreEqual(f.RealUncompressedSize, de.Length); } } }
public void ScanDLCfolder2() { DebugOutput.PrintLn("\n\nDLC Scan for packed files...\n", true); string dir = ME3Directory.DLCPath; string[] files = Directory.GetFiles(dir, "*.sfar", SearchOption.AllDirectories); if (files.Length == 0) { return; } pbar1.Maximum = files.Length - 1; int count = 0; foreach (string file in files) { if (!file.ToLower().Contains("patch")) { DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0); try { DLCPackage dlc = new DLCPackage(file); DebugOutput.PrintLn("found " + dlc.Files.Length + " files : " + file); for (int j = 0; j < dlc.Files.Length; j++) { if (dlc.Files[j].FileName.ToLower().EndsWith(".pcc")) { string filename = dlc.Files[j].FileName; DebugOutput.PrintLn(" " + j.ToString("d4") + " / " + dlc.Files.Length.ToString("d4") + " : opening " + Path.GetFileName(filename), true); MemoryStream mem = dlc.DecompressEntry(j); File.WriteAllBytes("temp.pcc", mem.ToArray()); using (ME3Package pcc = MEPackageHandler.OpenME3Package("temp.pcc")) { IReadOnlyList <IExportEntry> Exports = pcc.Exports; for (int i = 0; i < Exports.Count; i++) { if (Exports[i].ClassName == "BioConversation") { DebugOutput.PrintLn("Found dialog \"" + Exports[i].ObjectName + "\"", false); ME3BioConversation Dialog = new ME3BioConversation(Exports[i] as ME3ExportEntry); foreach (ME3BioConversation.EntryListStuct e in Dialog.EntryList) { string text = ME3TalkFiles.findDataById(e.refText); if (text.Length != 7 && text != "No Data") { EntryStruct t = new EntryStruct(); t.inDLC = true; t.text = text; t.ID = e.refText; t.indexpcc = i; t.pathafc = "";//Todo t.pathdlc = file; t.pathpcc = filename; t.convname = Exports[i].ObjectName; if (e.SpeakerIndex >= 0 && e.SpeakerIndex < Dialog.SpeakerList.Count) { t.speaker = Dialog.SpeakerList[e.SpeakerIndex].InstancedString; } else { t.speaker = "unknown"; } if (t.speaker == null || t.speaker == "") { t.speaker = "unknown"; } Entries.Add(t); DebugOutput.PrintLn("Requ.: (" + t.speaker + ") " + t.text, false); } } foreach (ME3BioConversation.ReplyListStruct e in Dialog.ReplyList) { string text = ME3TalkFiles.findDataById(e.refText); if (text.Length != 7 && text != "No Data") { EntryStruct t = new EntryStruct(); t.inDLC = true; t.text = text; t.ID = e.refText; t.indexpcc = i; t.pathafc = "";//Todo t.pathdlc = file; t.pathpcc = filename; t.convname = Exports[i].ObjectName; Entries.Add(t); DebugOutput.PrintLn("Reply: " + t.text, false); } } } } } } } if (count % 10 == 0) { Application.DoEvents(); pbar1.Value = count; } count++; } catch (Exception ex) { DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR====="); } } } if (File.Exists("temp.pcc")) { File.Delete("temp.pcc"); } }
private void unpackSFAR(DLCPackage DLC) { AutoTOC.AutoTOC toc = new AutoTOC.AutoTOC(); if (DLC == null || DLC.Files == null) { return; } string result = "pcc; tfc; afc; cnd; tlk; bin; bik; dlc"; if (result == "") { return; } result = result.Trim(); if (result.EndsWith(";")) { result = result.Substring(0, result.Length - 1); } string[] patt = result.Split(';'); string file = DLC.MyFileName; //full path string t1 = Path.GetDirectoryName(file); //cooked string t2 = Path.GetDirectoryName(t1); //DLC_Name string t3 = Path.GetDirectoryName(t2); //DLC string t4 = Path.GetDirectoryName(t3); //BioGame string gamebase = Path.GetDirectoryName(t4); //Mass Effect3 DebugOutput.PrintLn("Extracting DLC with gamebase : " + gamebase); DebugOutput.PrintLn("DLC name : " + t2); if (DLC.Files.Length > 1) { List <int> Indexes = new List <int>(); for (int i = 0; i < DLC.Files.Length; i++) { string DLCpath = DLC.Files[i].FileName; for (int j = 0; j < patt.Length; j++) { if (DLCpath.ToLower().EndsWith(patt[j].Trim().ToLower()) && patt[j].Trim().ToLower() != "") { string relPath = GetRelativePath(DLCpath); string outpath = gamebase + relPath; DebugOutput.PrintLn("Extracting file #" + i.ToString("d4") + ": " + outpath); if (!Directory.Exists(Path.GetDirectoryName(outpath))) { Directory.CreateDirectory(Path.GetDirectoryName(outpath)); } if (!File.Exists(outpath)) { using (FileStream fs = new FileStream(outpath, FileMode.Create)) DLC.DecompressEntry(i).WriteTo(fs); } Indexes.Add(i); Application.DoEvents(); break; } } } DLC.DeleteEntry(Indexes); } // AutoTOC DebugOutput.PrintLn("Updating DLC's PCConsoleTOC.bin"); List <string> FileNames = toc.GetFiles(t2 + "\\"); List <string> tet = new List <string>(t2.Split('\\')); string remov = String.Join("\\", tet.ToArray()); for (int i = 0; i < FileNames.Count; i++) { FileNames[i] = FileNames[i].Substring(remov.Length + 1); } string[] ts = t2.Split('\\'); tet.Clear(); tet.AddRange(ts); string basepath = String.Join("\\", tet.ToArray()) + '\\'; string tocfile = t2 + "\\PCConsoleTOC.bin"; toc.CreateTOC(basepath, tocfile, FileNames.ToArray()); DebugOutput.PrintLn("DLC Done."); }