From 4bcf2eb1b16ed09e0162a1756d65d1c4b86bbeb8 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Mon, 1 Jun 2020 20:18:32 -0600 Subject: [PATCH] Make the tests faster by defaulting to not indexing game files --- Wabbajack.Common/LogTime.cs | 22 +++++++++++++++++++ Wabbajack.Common/StatusFileStream.cs | 4 +++- Wabbajack.Common/StatusUpdateTracker.cs | 2 +- Wabbajack.Lib/MO2Compiler.cs | 28 +++++++++++++++++++------ Wabbajack.Test/ACompilerTest.cs | 7 ++++--- Wabbajack.Test/SanityTests.cs | 2 +- 6 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 Wabbajack.Common/LogTime.cs diff --git a/Wabbajack.Common/LogTime.cs b/Wabbajack.Common/LogTime.cs new file mode 100644 index 00000000..669c45ce --- /dev/null +++ b/Wabbajack.Common/LogTime.cs @@ -0,0 +1,22 @@ +using System; +using System.Threading.Tasks; + +namespace Wabbajack.Common +{ + public class LogTime : IAsyncDisposable + { + private readonly string _message; + private readonly DateTime _start; + + public LogTime(string message) + { + _message = message; + _start = DateTime.UtcNow; + } + + public async ValueTask DisposeAsync() + { + Utils.Log($"Log Time: {_message} {DateTime.UtcNow - _start}"); + } + } +} diff --git a/Wabbajack.Common/StatusFileStream.cs b/Wabbajack.Common/StatusFileStream.cs index b477ab15..5638f053 100644 --- a/Wabbajack.Common/StatusFileStream.cs +++ b/Wabbajack.Common/StatusFileStream.cs @@ -9,6 +9,7 @@ namespace Wabbajack.Common private Stream _inner; private WorkQueue? _queue; private DateTime _lastUpdate; + private TimeSpan _span; public StatusFileStream(Stream fs, string message, WorkQueue? queue = null) { @@ -16,6 +17,7 @@ namespace Wabbajack.Common _inner = fs; _message = message; _lastUpdate = DateTime.UnixEpoch; + _span = TimeSpan.FromMilliseconds(500); } public override void Flush() @@ -41,7 +43,7 @@ namespace Wabbajack.Common private void UpdateStatus() { - if (DateTime.Now - _lastUpdate < TimeSpan.FromMilliseconds(500)) + if (DateTime.Now - _lastUpdate < _span) { return; } diff --git a/Wabbajack.Common/StatusUpdateTracker.cs b/Wabbajack.Common/StatusUpdateTracker.cs index b4c9b31b..adadab25 100644 --- a/Wabbajack.Common/StatusUpdateTracker.cs +++ b/Wabbajack.Common/StatusUpdateTracker.cs @@ -49,7 +49,7 @@ namespace Wabbajack.Common public void MakeUpdate(Percent progress) { - _progress.OnNext(OverAllStatus(progress)); + _progress.OnNext(progress); } public void MakeUpdate(int max, int curr) diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index 37628262..64f430ab 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -95,13 +95,27 @@ namespace Wabbajack.Lib Utils.Log($"VFS File Location: {VFSCacheName}"); if (cancel.IsCancellationRequested) return false; - await VFS.IntegrateFromFile(VFSCacheName); - - var roots = new List - { - MO2Folder, GamePath, MO2DownloadsFolder, CompilingGame.GameLocation() - }; + if (VFSCacheName.Exists) + await VFS.IntegrateFromFile(VFSCacheName); + + List roots; + if (UseGamePaths) + { + roots = new List + { + MO2Folder, GamePath, MO2DownloadsFolder, CompilingGame.GameLocation() + }; + } + else + { + roots = new List + { + MO2Folder, MO2DownloadsFolder + }; + + } + // TODO: make this generic so we can add more paths var lootPath = (AbsolutePath)Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @@ -349,6 +363,8 @@ namespace Wabbajack.Lib return true; } + public bool UseGamePaths { get; set; } = true; + private async Task CleanInvalidArchives() { var remove = (await IndexedArchives.PMap(Queue, async a => diff --git a/Wabbajack.Test/ACompilerTest.cs b/Wabbajack.Test/ACompilerTest.cs index 7467253c..1c73b76e 100644 --- a/Wabbajack.Test/ACompilerTest.cs +++ b/Wabbajack.Test/ACompilerTest.cs @@ -33,19 +33,20 @@ namespace Wabbajack.Test base.Dispose(); } - protected async Task ConfigureAndRunCompiler(string profile) + protected async Task ConfigureAndRunCompiler(string profile, bool useGameFiles= false) { var compiler = new MO2Compiler( mo2Folder: utils.MO2Folder, mo2Profile: profile, outputFile: OutputFile(profile)); + compiler.UseGamePaths = useGameFiles; Assert.True(await compiler.Begin()); return compiler; } - protected async Task CompileAndInstall(string profile) + protected async Task CompileAndInstall(string profile, bool useGameFiles = false) { - var compiler = await ConfigureAndRunCompiler(profile); + var compiler = await ConfigureAndRunCompiler(profile, useGameFiles: useGameFiles); Utils.Log("Finished Compiling"); await Install(compiler); return compiler.ModList; diff --git a/Wabbajack.Test/SanityTests.cs b/Wabbajack.Test/SanityTests.cs index 2e810748..4cfd9568 100644 --- a/Wabbajack.Test/SanityTests.cs +++ b/Wabbajack.Test/SanityTests.cs @@ -73,7 +73,7 @@ namespace Wabbajack.Test await utils.AddManualDownload( new Dictionary {{"/baz/biz.pex", await testPex.ReadAllBytesAsync()}}); - await CompileAndInstall(profile); + await CompileAndInstall(profile, useGameFiles: true); await utils.VerifyInstalledGameFile(@"enbstuff\test.pex"); }