From 3976d7e52671df39eaf4fb2e86c3bbdf79d6fdfb Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sun, 24 Nov 2019 16:03:36 -0700 Subject: [PATCH] Macro-level progress bar updates. --- Wabbajack.Common/StatusUpdate.cs | 14 ++++++++--- Wabbajack.Common/Utils.cs | 14 +++++++++++ Wabbajack.Lib/AInstaller.cs | 9 ++++--- Wabbajack.Lib/MO2Compiler.cs | 25 +++++++++++++++---- Wabbajack.Lib/MO2Installer.cs | 28 +++++++++++++++++----- Wabbajack.VirtualFileSystem/VirtualFile.cs | 18 +++++++++++--- 6 files changed, 88 insertions(+), 20 deletions(-) diff --git a/Wabbajack.Common/StatusUpdate.cs b/Wabbajack.Common/StatusUpdate.cs index a9d9be90..809eba74 100644 --- a/Wabbajack.Common/StatusUpdate.cs +++ b/Wabbajack.Common/StatusUpdate.cs @@ -33,19 +33,27 @@ namespace Wabbajack.Common public void NextStep(string name) { _internalCurrentStep += 1; + Utils.Log(name); _step.OnNext(_internalCurrentStep); _stepName.OnNext(name); - _progress.OnNext(0.0f); + MakeUpdate(0.0f); + } + + private float OverAllStatus(float sub_status) + { + var per_step = 1.0f / _internalMaxStep; + var macro = _internalCurrentStep * per_step; + return macro + (per_step * sub_status); } public void MakeUpdate(float progress) { - _progress.OnNext(progress); + _progress.OnNext(OverAllStatus(progress)); } public void MakeUpdate(int max, int curr) { - _progress.OnNext((float)curr / ((float) (max == 0 ? 1 : max))); + MakeUpdate((float)curr / (max == 0 ? 1 : max)); } } diff --git a/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index c295514f..aa553d94 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -473,6 +473,20 @@ namespace Wabbajack.Common }); } + public static void PMap(this IEnumerable coll, WorkQueue queue, StatusUpdateTracker updateTracker, + Action f) + { + var cnt = 0; + var collist = coll.ToList(); + collist.PMap(queue, itm => + { + updateTracker.MakeUpdate(collist.Count, Interlocked.Increment(ref cnt)); + f(itm); + return true; + }); + } + + public static List PMap(this IEnumerable coll, WorkQueue queue, Func f) { diff --git a/Wabbajack.Lib/AInstaller.cs b/Wabbajack.Lib/AInstaller.cs index e8703251..12488410 100644 --- a/Wabbajack.Lib/AInstaller.cs +++ b/Wabbajack.Lib/AInstaller.cs @@ -121,7 +121,7 @@ namespace Wabbajack.Lib .ToList(); Info("Installing Archives"); - archives.PMap(Queue,a => InstallArchive(a.Archive, a.AbsolutePath, grouped[a.Archive.Hash])); + archives.PMap(Queue, UpdateTracker,a => InstallArchive(a.Archive, a.AbsolutePath, grouped[a.Archive.Hash])); } private void InstallArchive(Archive archive, string absolutePath, IGrouping grouping) @@ -334,8 +334,9 @@ namespace Wabbajack.Lib Utils.Log("Optimizing Modlist directives"); var indexed = ModList.Directives.ToDictionary(d => d.To); + UpdateTracker.NextStep("Looking for files to delete"); Directory.EnumerateFiles(OutputFolder, "*", DirectoryEnumerationOptions.Recursive) - .PMap(Queue, f => + .PMap(Queue, UpdateTracker, f => { var relative_to = f.RelativeTo(OutputFolder); Utils.Status($"Checking if modlist file {relative_to}"); @@ -348,7 +349,8 @@ namespace Wabbajack.Lib File.Delete(f); }); - indexed.Values.PMap(Queue, d => + UpdateTracker.NextStep("Looking for unmodified files"); + indexed.Values.PMap(Queue, UpdateTracker, d => { // Bit backwards, but we want to return null for // all files we *want* installed. We return the files @@ -364,6 +366,7 @@ namespace Wabbajack.Lib }).Where(d => d != null) .Do(d => indexed.Remove(d.To)); + UpdateTracker.NextStep("Updating Modlist"); Utils.Log($"Optimized {ModList.Directives.Count} directives to {indexed.Count} required"); var requiredArchives = indexed.Values.OfType() .GroupBy(d => d.ArchiveHashPath[0]) diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index e88ea3ec..113ae6b8 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -72,7 +72,7 @@ namespace Wabbajack.Lib protected override bool _Begin() { - ConfigureProcessor(10); + ConfigureProcessor(16); UpdateTracker.Reset(); UpdateTracker.NextStep("Gathering information"); Info("Looking for other profiles"); @@ -161,7 +161,8 @@ namespace Wabbajack.Lib Info($"Found {AllFiles.Count} files to build into mod list"); - Info("Verifying destinations"); + UpdateTracker.NextStep("Verifying destinations"); + var dups = AllFiles.GroupBy(f => f.Path) .Where(fs => fs.Count() > 1) .Select(fs => @@ -177,6 +178,9 @@ namespace Wabbajack.Lib ExtraFiles = new ConcurrentBag(); + + UpdateTracker.NextStep("Loading INIs"); + ModInis = Directory.EnumerateDirectories(Path.Combine(MO2Folder, "mods")) .Select(f => { @@ -191,12 +195,12 @@ namespace Wabbajack.Lib var stack = MakeStack(); - UpdateTracker.NextStep("Running Compilation Stack"); var results = AllFiles.PMap(Queue, UpdateTracker, f => RunStack(stack, f)).ToList(); // Add the extra files that were generated by the stack - Info($"Adding {ExtraFiles.Count} that were generated by the stack"); + + UpdateTracker.NextStep($"Adding {ExtraFiles.Count} that were generated by the stack"); results = results.Concat(ExtraFiles).ToList(); var nomatch = results.OfType(); @@ -227,10 +231,15 @@ namespace Wabbajack.Lib } + UpdateTracker.NextStep("Verifying Files"); zEditIntegration.VerifyMerges(this); + + UpdateTracker.NextStep("Gathering Archives"); GatherArchives(); + UpdateTracker.NextStep("Including Archive Metadata"); IncludeArchiveMetadata(); + UpdateTracker.NextStep("Building Patches"); BuildPatches(); ModList = new ModList @@ -248,16 +257,22 @@ namespace Wabbajack.Lib Website = ModListWebsite ?? "" }; + UpdateTracker.NextStep("Running Validation"); + ValidateModlist.RunValidation(ModList); + UpdateTracker.NextStep("Generating Report"); GenerateReport(); + + UpdateTracker.NextStep("Exporting Modlist"); ExportModList(); ResetMembers(); ShowReport(); - Info("Done Building Modlist"); + UpdateTracker.NextStep("Done Building Modlist"); + return true; } diff --git a/Wabbajack.Lib/MO2Installer.cs b/Wabbajack.Lib/MO2Installer.cs index 79972d25..f953671b 100644 --- a/Wabbajack.Lib/MO2Installer.cs +++ b/Wabbajack.Lib/MO2Installer.cs @@ -30,8 +30,7 @@ namespace Wabbajack.Lib protected override bool _Begin() { - ConfigureProcessor(RecommendQueueSize()); - ValidateFreeSpace(); + ConfigureProcessor(17, RecommendQueueSize()); var game = GameRegistry.Games[ModList.GameType]; if (GameFolder == null) @@ -47,7 +46,10 @@ namespace Wabbajack.Lib return false; } + UpdateTracker.NextStep("Validating Game ESMs"); ValidateGameESMs(); + + UpdateTracker.NextStep("Validating Modlist"); ValidateModlist.RunValidation(ModList); Directory.CreateDirectory(OutputFolder); @@ -67,10 +69,16 @@ namespace Wabbajack.Lib } } + UpdateTracker.NextStep("Optimizing Modlist"); OptimizeModlist(); + UpdateTracker.NextStep("Hashing Archives"); HashArchives(); + + UpdateTracker.NextStep("Downloading Missing Archives"); DownloadArchives(); + + UpdateTracker.NextStep("Hashing Remaining Archives"); HashArchives(); var missing = ModList.Archives.Where(a => !HashedArchives.ContainsKey(a.Hash)).ToList(); @@ -84,20 +92,28 @@ namespace Wabbajack.Lib Error("Cannot continue, was unable to download one or more archives"); } + UpdateTracker.NextStep("Priming VFS"); PrimeVFS(); + UpdateTracker.NextStep("Building Folder Structure"); BuildFolderStructure(); + + UpdateTracker.NextStep("Installing Archives"); InstallArchives(); + + UpdateTracker.NextStep("Installing Included files"); InstallIncludedFiles(); + + UpdateTracker.NextStep("Installing Archive Metas"); InstallIncludedDownloadMetas(); + + UpdateTracker.NextStep("Building BSAs"); BuildBSAs(); + UpdateTracker.NextStep("Generating Merges"); zEditIntegration.GenerateMerges(this); - Info("Installation complete! You may exit the program."); - // Removed until we decide if we want this functionality - // Nexus devs weren't sure this was a good idea, I (halgari) agree. - //AskToEndorse(); + UpdateTracker.NextStep("Installation complete! You may exit the program."); return true; } diff --git a/Wabbajack.VirtualFileSystem/VirtualFile.cs b/Wabbajack.VirtualFileSystem/VirtualFile.cs index 075c2a3f..efc9553a 100644 --- a/Wabbajack.VirtualFileSystem/VirtualFile.cs +++ b/Wabbajack.VirtualFileSystem/VirtualFile.cs @@ -93,8 +93,20 @@ namespace Wabbajack.VirtualFileSystem public bool IsNative => Parent == null; - public IEnumerable ThisAndAllChildren => - Children.SelectMany(child => child.ThisAndAllChildren).Append(this); + private IEnumerable _thisAndAllChildren = null; + + public IEnumerable ThisAndAllChildren + { + get + { + if (_thisAndAllChildren == null) + { + _thisAndAllChildren = Children.SelectMany(child => child.ThisAndAllChildren).Append(this).ToList(); + } + + return _thisAndAllChildren; + } + } /// @@ -267,4 +279,4 @@ namespace Wabbajack.VirtualFileSystem _fullPath = fullPath; } } -} \ No newline at end of file +}