string UnpackFile(string bundlePath, string contentRelativePath, string outputDirName) { var outputDir = Path.Combine(Paths.TempBundleContent, outputDirName); var exitCode = QuickBms.UnpackFile(bundlePath, contentRelativePath, outputDir); return(exitCode == 0 ? Path.Combine(outputDir, contentRelativePath) : null); }
public void BuildAsync( bool checkScripts, bool checkXml, bool checkBundles, ProgressChangedEventHandler progressHandler, RunWorkerCompletedEventHandler completedHandler) { var ignoredModNames = GetIgnoredModNames(); var modDirPaths = (Directory.Exists(Paths.ModsDirectory)) ? Directory.GetDirectories(Paths.ModsDirectory, "mod*", SearchOption.TopDirectoryOnly) .Where(path => !ignoredModNames.Any(name => name.EqualsIgnoreCase(new DirectoryInfo(path).Name))) .ToList() : new List <string>(); ModCount = modDirPaths.Count; if (ModCount == 0) { Program.MainForm.ShowMessage("Can't find any mods in the Mods directory."); } var bgWorker = new BackgroundWorker { WorkerReportsProgress = true }; bgWorker.DoWork += (sender, e) => { var i = 0; ScriptCount = XmlCount = BundleCount = 0; foreach (var modDirPath in modDirPaths) { var modName = Path.GetFileName(modDirPath); var filePaths = Directory.GetFiles(modDirPath, "*", SearchOption.AllDirectories); var scriptPaths = filePaths.Where(path => ModFile.IsScript(path)); var xmlPaths = filePaths.Where(path => ModFile.IsXml(path)); var bundlePaths = filePaths.Where(path => ModFile.IsBundle(path)); ScriptCount += scriptPaths.Count(); XmlCount += xmlPaths.Count(); BundleCount += bundlePaths.Count(); if (checkScripts) { Files.AddRange(GetModFilesFromPaths(scriptPaths, Categories.Script, modName)); } if (checkXml) { Files.AddRange(GetModFilesFromPaths(xmlPaths, Categories.Xml, modName)); } if (checkBundles) { foreach (var bundlePath in bundlePaths) { var contentPaths = QuickBms.GetBundleContentPaths(bundlePath); Files.AddRange(GetModFilesFromPaths(contentPaths, Categories.BundleText, modName, bundlePath)); } } var progressPct = (int)((float)++i / modDirPaths.Count * 100f); bgWorker.ReportProgress(progressPct, modName as object); } if (checkBundles) { System.Threading.Thread.Sleep(500); // Wait for progress bar to fill completely } }; bgWorker.RunWorkerCompleted += completedHandler; bgWorker.ProgressChanged += progressHandler; bgWorker.RunWorkerAsync(); }
bool GetUnpackedFiles(string contentRelativePath, ref MergeSource source1, ref MergeSource source2) { if (_vanillaFile == null) { ProgressInfo.CurrentAction = "Searching for corresponding vanilla bundle"; var bundleDirsList = Directory.GetDirectories(Paths.BundlesDirectory) .Select(path => Path.Combine(path, "bundles")) .Concat( Directory.GetDirectories(Paths.DlcDirectory) .Where(path => new Regex("DLC[0-9]*$", RegexOptions.IgnoreCase).IsMatch(path) || new Regex("ep[0-9]$", RegexOptions.IgnoreCase).IsMatch(path) || new Regex("bob$", RegexOptions.IgnoreCase).IsMatch(path)) .Select(path => Path.Combine(path, Paths.BundleBase, "bundles")) ) .Where(path => Directory.Exists(path)) .OrderBy(path => path, new LoadOrderComparer()) .ToList(); // Ensure patch bundle directories are always last var patchDirs = bundleDirsList.FindAll(x => x.Contains("patch")); var bundleDirs = bundleDirsList .Except(patchDirs) .Union(patchDirs) .ToArray(); for (int i = bundleDirs.Length - 1; i >= 0; --i) // Search vanilla directories in reverse { // order, as patches & DLC override content. var bundleFiles = Directory.GetFiles(bundleDirs[i], "*.bundle"); foreach (var bundle in bundleFiles) { var contentPaths = QuickBms.GetBundleContentPaths(bundle); if (contentPaths.Any(path => path.EqualsIgnoreCase(contentRelativePath))) { _vanillaFile = new FileInfo(bundle); break; } } if (_vanillaFile != null) { break; } } if (_vanillaFile != null) { ProgressInfo.CurrentAction = "Unpacking vanilla bundle content file"; var vanillaContentPath = UnpackFile(_vanillaFile.FullName, contentRelativePath, "Vanilla"); _vanillaFile = new FileInfo(vanillaContentPath); } } if (source1.TextFile == null) { ProgressInfo.CurrentAction = $"Unpacking bundle content file for {source1.Name}"; var modContentFile1 = UnpackFile(source1.Bundle.FullName, contentRelativePath, "Mod 1"); if (modContentFile1 == null) { return(false); } source1.TextFile = new FileInfo(modContentFile1); } ProgressInfo.CurrentAction = $"Unpacking bundle content file for {source2.Name}"; var modContentFile2 = UnpackFile(source2.Bundle.FullName, contentRelativePath, "Mod 2"); if (modContentFile2 == null) { return(false); } source2.TextFile = new FileInfo(modContentFile2); return(true); }