From 729b5128dacfb6b4e2a9a232d6f4b3f789983deb Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Fri, 6 Dec 2019 20:54:27 -0600 Subject: [PATCH] Random .Results swapped to async --- Wabbajack.Lib/AInstaller.cs | 4 +- Wabbajack.Lib/MO2Compiler.cs | 2 +- Wabbajack.Lib/MO2Installer.cs | 4 +- Wabbajack.Lib/UI/UIUtils.cs | 48 ------------------- Wabbajack.Lib/VortexInstaller.cs | 2 +- Wabbajack.Test/ACompilerTest.cs | 9 ++-- Wabbajack.Test/AVortexCompilerTest.cs | 9 ++-- Wabbajack.Test/CompilationStackTests.cs | 7 +-- Wabbajack.Test/EndToEndTests.cs | 10 ++-- Wabbajack.Test/SanityTests.cs | 27 ++++++----- Wabbajack.Test/ZEditIntegrationTests.cs | 5 +- .../VirtualFileSystemTests.cs | 2 +- Wabbajack.VirtualFileSystem/Context.cs | 24 +++++----- 13 files changed, 55 insertions(+), 98 deletions(-) diff --git a/Wabbajack.Lib/AInstaller.cs b/Wabbajack.Lib/AInstaller.cs index 1f203427..d22688d1 100644 --- a/Wabbajack.Lib/AInstaller.cs +++ b/Wabbajack.Lib/AInstaller.cs @@ -86,7 +86,7 @@ namespace Wabbajack.Lib /// We don't want to make the installer index all the archives, that's just a waste of time, so instead /// we'll pass just enough information to VFS to let it know about the files we have. /// - public void PrimeVFS() + public async Task PrimeVFS() { VFS.AddKnown(HashedArchives.Select(a => new KnownFile { @@ -100,7 +100,7 @@ namespace Wabbajack.Lib .OfType() .Select(f => new KnownFile { Paths = f.ArchiveHashPath})); - VFS.BackfillMissing(); + await VFS.BackfillMissing(); } public void BuildFolderStructure() diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index 39ddb030..c305001f 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -86,7 +86,7 @@ namespace Wabbajack.Lib Info("Using Profiles: " + string.Join(", ", SelectedProfiles.OrderBy(p => p))); if (cancel.IsCancellationRequested) return false; - VFS.IntegrateFromFile(_vfsCacheName); + await VFS.IntegrateFromFile(_vfsCacheName); var roots = new List() { diff --git a/Wabbajack.Lib/MO2Installer.cs b/Wabbajack.Lib/MO2Installer.cs index 565152bd..67695fd4 100644 --- a/Wabbajack.Lib/MO2Installer.cs +++ b/Wabbajack.Lib/MO2Installer.cs @@ -69,7 +69,7 @@ namespace Wabbajack.Lib if (Directory.Exists(Path.Combine(OutputFolder, "mods")) && WarnOnOverwrite) { - if (Utils.Log(new ConfirmUpdateOfExistingInstall { ModListName = ModList.Name, OutputFolder = OutputFolder}).Task.Result == ConfirmUpdateOfExistingInstall.Choice.Abort) + if ((await Utils.Log(new ConfirmUpdateOfExistingInstall { ModListName = ModList.Name, OutputFolder = OutputFolder }).Task) == ConfirmUpdateOfExistingInstall.Choice.Abort) { Utils.Log("Existing installation at the request of the user, existing mods folder found."); return false; @@ -105,7 +105,7 @@ namespace Wabbajack.Lib if (cancel.IsCancellationRequested) return false; UpdateTracker.NextStep("Priming VFS"); - PrimeVFS(); + await PrimeVFS(); if (cancel.IsCancellationRequested) return false; UpdateTracker.NextStep("Building Folder Structure"); diff --git a/Wabbajack.Lib/UI/UIUtils.cs b/Wabbajack.Lib/UI/UIUtils.cs index 78e80b28..e9ab59e0 100644 --- a/Wabbajack.Lib/UI/UIUtils.cs +++ b/Wabbajack.Lib/UI/UIUtils.cs @@ -12,54 +12,6 @@ namespace Wabbajack.Lib { public static class UIUtils { - - public static string ShowFolderSelectionDialog(string prompt) - { - if (System.Windows.Application.Current.Dispatcher.Thread != Thread.CurrentThread) - { - var task = new TaskCompletionSource(); - System.Windows.Application.Current.Dispatcher.Invoke(() => - { - try - { - task.SetResult(ShowFolderSelectionDialog(prompt)); - } - catch (Exception ex) - { - task.SetException(ex); - } - }); - task.Task.Wait(); - if (task.Task.IsFaulted) - throw task.Task.Exception; - return task.Task.Result; - } - - - var dlg = new CommonOpenFileDialog(); - dlg.Title = prompt; - dlg.IsFolderPicker = true; - dlg.InitialDirectory = Assembly.GetEntryAssembly().Location; - - dlg.AddToMostRecentlyUsedList = false; - dlg.AllowNonFileSystemItems = false; - dlg.DefaultDirectory = Assembly.GetEntryAssembly().Location; - dlg.EnsureFileExists = true; - dlg.EnsurePathExists = true; - dlg.EnsureReadOnly = false; - dlg.EnsureValidNames = true; - dlg.Multiselect = false; - dlg.ShowPlacesList = true; - - if (dlg.ShowDialog() == CommonFileDialogResult.Ok) - { - return dlg.FileName; - // Do something with selected folder string - } - - return null; - } - public static BitmapImage BitmapImageFromResource(string name) => BitmapImageFromStream(System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/Wabbajack;component/" + name)).Stream); public static BitmapImage BitmapImageFromStream(Stream stream) diff --git a/Wabbajack.Lib/VortexInstaller.cs b/Wabbajack.Lib/VortexInstaller.cs index 7476e3fe..591f0ccc 100644 --- a/Wabbajack.Lib/VortexInstaller.cs +++ b/Wabbajack.Lib/VortexInstaller.cs @@ -65,7 +65,7 @@ namespace Wabbajack.Lib Error("Cannot continue, was unable to download one or more archives"); } - PrimeVFS(); + await PrimeVFS(); if (cancel.IsCancellationRequested) return false; BuildFolderStructure(); diff --git a/Wabbajack.Test/ACompilerTest.cs b/Wabbajack.Test/ACompilerTest.cs index af0b37e7..32c328cf 100644 --- a/Wabbajack.Test/ACompilerTest.cs +++ b/Wabbajack.Test/ACompilerTest.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Wabbajack.Common; using Wabbajack.Lib; @@ -28,20 +29,20 @@ namespace Wabbajack.Test utils.Dispose(); } - protected MO2Compiler ConfigureAndRunCompiler(string profile) + protected async Task ConfigureAndRunCompiler(string profile) { var compiler = new MO2Compiler( mo2Folder: utils.MO2Folder, mo2Profile: profile, outputFile: profile + ExtensionManager.Extension); compiler.ShowReportWhenFinished = false; - Assert.IsTrue(compiler.Begin().Result); + Assert.IsTrue(await compiler.Begin()); return compiler; } - protected ModList CompileAndInstall(string profile) + protected async Task CompileAndInstall(string profile) { - var compiler = ConfigureAndRunCompiler(profile); + var compiler = await ConfigureAndRunCompiler(profile); Install(compiler); return compiler.ModList; } diff --git a/Wabbajack.Test/AVortexCompilerTest.cs b/Wabbajack.Test/AVortexCompilerTest.cs index 778cae5d..c7433f87 100644 --- a/Wabbajack.Test/AVortexCompilerTest.cs +++ b/Wabbajack.Test/AVortexCompilerTest.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Wabbajack.Common; using Wabbajack.Lib; @@ -31,13 +32,13 @@ namespace Wabbajack.Test utils.Dispose(); } - protected VortexCompiler ConfigureAndRunCompiler() + protected async Task ConfigureAndRunCompiler() { var vortexCompiler = MakeCompiler(); vortexCompiler.DownloadsFolder = utils.DownloadsFolder; vortexCompiler.StagingFolder = utils.InstallFolder; Directory.CreateDirectory(utils.InstallFolder); - Assert.IsTrue(vortexCompiler.Begin().Result); + Assert.IsTrue(await vortexCompiler.Begin()); return vortexCompiler; } @@ -52,9 +53,9 @@ namespace Wabbajack.Test outputFile: $"test{ExtensionManager.Extension}"); } - protected ModList CompileAndInstall() + protected async Task CompileAndInstall() { - var vortexCompiler = ConfigureAndRunCompiler(); + var vortexCompiler = await ConfigureAndRunCompiler(); Install(vortexCompiler); return vortexCompiler.ModList; } diff --git a/Wabbajack.Test/CompilationStackTests.cs b/Wabbajack.Test/CompilationStackTests.cs index 9fdb1802..31866e05 100644 --- a/Wabbajack.Test/CompilationStackTests.cs +++ b/Wabbajack.Test/CompilationStackTests.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Wabbajack.Lib.CompilationSteps; namespace Wabbajack.Test @@ -7,13 +8,13 @@ namespace Wabbajack.Test public class CompilationStackTests : ACompilerTest { [TestMethod] - public void TestStackSerialization() + public async Task TestStackSerialization() { var profile = utils.AddProfile(); var mod = utils.AddMod("test"); utils.Configure(); - var compiler = ConfigureAndRunCompiler(profile); + var compiler = await ConfigureAndRunCompiler(profile); var stack = compiler.MakeStack(); var serialized = Serialization.Serialize(stack); diff --git a/Wabbajack.Test/EndToEndTests.cs b/Wabbajack.Test/EndToEndTests.cs index 97f4baf2..32728751 100644 --- a/Wabbajack.Test/EndToEndTests.cs +++ b/Wabbajack.Test/EndToEndTests.cs @@ -78,7 +78,7 @@ namespace Wabbajack.Test outputFile: profile + ExtensionManager.Extension); compiler.MO2DownloadsFolder = Path.Combine(utils.DownloadsFolder); compiler.ShowReportWhenFinished = false; - Assert.IsTrue(compiler.Begin().Result); + Assert.IsTrue(await compiler.Begin()); } @@ -139,9 +139,9 @@ namespace Wabbajack.Test File.WriteAllText(dest + ".meta", ini); } - private ModList CompileAndInstall(string profile) + private async Task CompileAndInstall(string profile) { - var compiler = ConfigureAndRunCompiler(profile); + var compiler = await ConfigureAndRunCompiler(profile); Install(compiler); return compiler.ModList; } @@ -158,14 +158,14 @@ namespace Wabbajack.Test installer.Begin().Wait(); } - private MO2Compiler ConfigureAndRunCompiler(string profile) + private async Task ConfigureAndRunCompiler(string profile) { var compiler = new MO2Compiler( mo2Folder: utils.MO2Folder, mo2Profile: profile, outputFile: profile + ExtensionManager.Extension); compiler.ShowReportWhenFinished = false; - Assert.IsTrue(compiler.Begin().Result); + Assert.IsTrue(await compiler.Begin()); return compiler; } } diff --git a/Wabbajack.Test/SanityTests.cs b/Wabbajack.Test/SanityTests.cs index 080eac99..27e164ec 100644 --- a/Wabbajack.Test/SanityTests.cs +++ b/Wabbajack.Test/SanityTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Wabbajack.Common; using Wabbajack.Lib; @@ -14,7 +15,7 @@ namespace Wabbajack.Test public class SanityTests : ACompilerTest { [TestMethod] - public void TestDirectMatch() + public async Task TestDirectMatch() { var profile = utils.AddProfile(); @@ -26,13 +27,13 @@ namespace Wabbajack.Test utils.AddManualDownload( new Dictionary {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}}); - CompileAndInstall(profile); + await CompileAndInstall(profile); utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex"); } [TestMethod] - public void TestDuplicateFilesAreCopied() + public async Task TestDuplicateFilesAreCopied() { var profile = utils.AddProfile(); @@ -47,14 +48,14 @@ namespace Wabbajack.Test utils.AddManualDownload( new Dictionary { { "/baz/biz.pex", File.ReadAllBytes(test_pex) } }); - CompileAndInstall(profile); + await CompileAndInstall(profile); utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex"); utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex.copy"); } [TestMethod] - public void TestUpdating() + public async Task TestUpdating() { var profile = utils.AddProfile(); @@ -73,7 +74,7 @@ namespace Wabbajack.Test { "/baz/modified.pex", File.ReadAllBytes(modified) }, }); - CompileAndInstall(profile); + await CompileAndInstall(profile); utils.VerifyInstalledFile(mod, @"Data\scripts\unchanged.pex"); utils.VerifyInstalledFile(mod, @"Data\scripts\deleted.pex"); @@ -95,7 +96,7 @@ namespace Wabbajack.Test Assert.IsTrue(File.Exists(extra_path)); - CompileAndInstall(profile); + await CompileAndInstall(profile); utils.VerifyInstalledFile(mod, @"Data\scripts\unchanged.pex"); utils.VerifyInstalledFile(mod, @"Data\scripts\deleted.pex"); @@ -108,7 +109,7 @@ namespace Wabbajack.Test [TestMethod] - public void CleanedESMTest() + public async Task CleanedESMTest() { var profile = utils.AddProfile(); var mod = utils.AddMod("Cleaned ESMs"); @@ -123,7 +124,7 @@ namespace Wabbajack.Test utils.VerifyInstalledFile(mod, @"Update.esm"); - var compiler = ConfigureAndRunCompiler(profile); + var compiler = await ConfigureAndRunCompiler(profile); // Update the file and verify that it throws an error. utils.GenerateRandomFileData(game_file, 20); @@ -155,7 +156,7 @@ namespace Wabbajack.Test } [TestMethod] - public void UnmodifiedInlinedFilesArePulledFromArchives() + public async Task UnmodifiedInlinedFilesArePulledFromArchives() { var profile = utils.AddProfile(); var mod = utils.AddMod(); @@ -165,7 +166,7 @@ namespace Wabbajack.Test utils.AddManualDownload( new Dictionary { { "/baz/biz.pex", File.ReadAllBytes(ini) } }); - var modlist = CompileAndInstall(profile); + var modlist = await CompileAndInstall(profile); var directive = modlist.Directives.Where(m => m.To == $"mods\\{mod}\\foo.ini").FirstOrDefault(); Assert.IsNotNull(directive); @@ -173,7 +174,7 @@ namespace Wabbajack.Test } [TestMethod] - public void ModifiedIniFilesArePatchedAgainstFileWithSameName() + public async Task ModifiedIniFilesArePatchedAgainstFileWithSameName() { var profile = utils.AddProfile(); var mod = utils.AddMod(); @@ -195,7 +196,7 @@ namespace Wabbajack.Test // Modify after creating mod archive in the downloads folder File.WriteAllText(ini, "Wabbajack, Wabbajack, Wabbajack!"); - var modlist = CompileAndInstall(profile); + var modlist = await CompileAndInstall(profile); var directive = modlist.Directives.Where(m => m.To == $"mods\\{mod}\\foo.ini").FirstOrDefault(); Assert.IsNotNull(directive); diff --git a/Wabbajack.Test/ZEditIntegrationTests.cs b/Wabbajack.Test/ZEditIntegrationTests.cs index e9c7fbbb..a4b19234 100644 --- a/Wabbajack.Test/ZEditIntegrationTests.cs +++ b/Wabbajack.Test/ZEditIntegrationTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Alphaleonis.Win32.Filesystem; using Microsoft.VisualStudio.TestTools.UnitTesting; using Wabbajack.Common; @@ -11,7 +12,7 @@ namespace Wabbajack.Test public class zEditIntegrationTests : ACompilerTest { [TestMethod] - public void CanCreatezEditPatches() + public async Task CanCreatezEditPatches() { var profile = utils.AddProfile(); var moda = utils.AddMod(); @@ -72,7 +73,7 @@ namespace Wabbajack.Test }); - var modlist = CompileAndInstall(profile); + var modlist = await CompileAndInstall(profile); var directive = modlist.Directives.Where(m => m.To == $"mods\\{moddest}\\merged.esp").FirstOrDefault(); Assert.IsNotNull(directive); diff --git a/Wabbajack.VirtualFileSystem.Test/VirtualFileSystemTests.cs b/Wabbajack.VirtualFileSystem.Test/VirtualFileSystemTests.cs index f0ae8a42..a6669f2e 100644 --- a/Wabbajack.VirtualFileSystem.Test/VirtualFileSystemTests.cs +++ b/Wabbajack.VirtualFileSystem.Test/VirtualFileSystemTests.cs @@ -47,7 +47,7 @@ namespace Wabbajack.VirtualFileSystem.Test { await context.AddRoot(VFS_TEST_DIR_FULL); await context.WriteToFile(Path.Combine(VFS_TEST_DIR_FULL, "vfs_cache.bin")); - context.IntegrateFromFile(Path.Combine(VFS_TEST_DIR_FULL, "vfs_cache.bin")); + await context.IntegrateFromFile(Path.Combine(VFS_TEST_DIR_FULL, "vfs_cache.bin")); } diff --git a/Wabbajack.VirtualFileSystem/Context.cs b/Wabbajack.VirtualFileSystem/Context.cs index 4de60670..e4e55a32 100644 --- a/Wabbajack.VirtualFileSystem/Context.cs +++ b/Wabbajack.VirtualFileSystem/Context.cs @@ -72,7 +72,7 @@ namespace Wabbajack.VirtualFileSystem return await VirtualFile.Analyze(this, null, f, f); }); - var newIndex = IndexRoot.Empty.Integrate(filtered.Concat(allFiles).ToList()); + var newIndex = await IndexRoot.Empty.Integrate(filtered.Concat(allFiles).ToList()); lock (this) { @@ -108,7 +108,7 @@ namespace Wabbajack.VirtualFileSystem return await VirtualFile.Analyze(this, null, f, f); }); - var newIndex = IndexRoot.Empty.Integrate(filtered.Concat(allFiles).ToList()); + var newIndex = await IndexRoot.Empty.Integrate(filtered.Concat(allFiles).ToList()); lock (this) { @@ -166,7 +166,7 @@ namespace Wabbajack.VirtualFileSystem } } - public void IntegrateFromFile(string filename) + public async Task IntegrateFromFile(string filename) { try { @@ -188,7 +188,7 @@ namespace Wabbajack.VirtualFileSystem br.BaseStream.Read(bytes, 0, (int) size); return VirtualFile.Read(this, bytes); }).ToList(); - var newIndex = Index.Integrate(files); + var newIndex = await Index.Integrate(files); lock (this) { Index = newIndex; @@ -252,7 +252,7 @@ namespace Wabbajack.VirtualFileSystem var parents = await indexedState[""] .PMap(Queue,f => VirtualFile.CreateFromPortable(this, indexedState, links, f)); - var newIndex = Index.Integrate(parents); + var newIndex = await Index.Integrate(parents); lock (this) { Index = newIndex; @@ -273,7 +273,7 @@ namespace Wabbajack.VirtualFileSystem _knownFiles.AddRange(known); } - public void BackfillMissing() + public async Task BackfillMissing() { var newFiles = _knownFiles.Where(f => f.Paths.Length == 1) .GroupBy(f => f.Hash) @@ -307,7 +307,7 @@ namespace Wabbajack.VirtualFileSystem } _knownFiles.Where(f => f.Paths.Length > 1).Do(BackFillOne); - var newIndex = Index.Integrate(newFiles.Values.ToList()); + var newIndex = await Index.Integrate(newFiles.Values.ToList()); lock (this) Index = newIndex; @@ -373,7 +373,7 @@ namespace Wabbajack.VirtualFileSystem public ImmutableDictionary> ByName { get; set; } public ImmutableDictionary ByRootPath { get; } - public IndexRoot Integrate(ICollection files) + public async Task Integrate(ICollection files) { Utils.Log($"Integrating {files.Count} files"); var allFiles = AllFiles.Concat(files).GroupBy(f => f.Name).Select(g => g.Last()).ToImmutableList(); @@ -391,10 +391,10 @@ namespace Wabbajack.VirtualFileSystem var byRootPath = Task.Run(() => allFiles.ToImmutableDictionary(f => f.Name)); var result = new IndexRoot(allFiles, - byFullPath.Result, - byHash.Result, - byRootPath.Result, - byName.Result); + await byFullPath, + await byHash, + await byRootPath, + await byName); Utils.Log($"Done integrating"); return result; }