From 0b74c04c863ccff30a8582417e652ac89fa72b04 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sat, 20 Jun 2020 17:10:43 -0600 Subject: [PATCH] And priority to how game files are resolved --- CHANGELOG.md | 2 +- Wabbajack.Lib/ACompiler.cs | 2 ++ Wabbajack.Lib/CompilationSteps/DirectMatch.cs | 18 +++++++++++++++++- .../CompilationSteps/IncludePatches.cs | 3 ++- Wabbajack.Lib/Data.cs | 1 + Wabbajack.Lib/MO2Compiler.cs | 11 ++++++++--- Wabbajack.VirtualFileSystem/VirtualFile.cs | 3 +++ 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbcde670..48810097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ #### Version - 2.1.0.0 - ??? * Game files are available as downloads automatically during compilation/installation * Game files are patched/copied/used in BSA creation automatically -* CleanedESM support removed from the compiler stack (still usable during installation for backwards compatability) +* CleanedESM support removed from the compiler stack (still usable during installation for backwards compatibility) * VR games automatically pull from base games if they are required and are installed during compilation #### Version - 2.0.9.4 - 6/16/2020 diff --git a/Wabbajack.Lib/ACompiler.cs b/Wabbajack.Lib/ACompiler.cs index dca73208..46885cc8 100644 --- a/Wabbajack.Lib/ACompiler.cs +++ b/Wabbajack.Lib/ACompiler.cs @@ -47,6 +47,8 @@ namespace Wabbajack.Lib public ModList ModList = new ModList(); public List IndexedArchives = new List(); + public Dictionary ArchivesByFullPath { get; set; } = new Dictionary(); + public Dictionary> IndexedFiles = new Dictionary>(); public ACompiler(int steps) diff --git a/Wabbajack.Lib/CompilationSteps/DirectMatch.cs b/Wabbajack.Lib/CompilationSteps/DirectMatch.cs index 0f57cee3..91ae982d 100644 --- a/Wabbajack.Lib/CompilationSteps/DirectMatch.cs +++ b/Wabbajack.Lib/CompilationSteps/DirectMatch.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using Alphaleonis.Win32.Filesystem; using Newtonsoft.Json; +using Wabbajack.Lib.Downloaders; +using Wabbajack.VirtualFileSystem; namespace Wabbajack.Lib.CompilationSteps { @@ -11,13 +13,27 @@ namespace Wabbajack.Lib.CompilationSteps { } + public static int GetFilePriority(MO2Compiler compiler, VirtualFile file) + { + var archive = file.TopParent; + var adata = compiler.ArchivesByFullPath[archive.AbsoluteName]; + if (adata.State is GameFileSourceDownloader.State gs) + { + return gs.Game == compiler.CompilingGame.Game ? 1 : 3; + } + + return 2; + } + public override async ValueTask Run(RawSourceFile source) { + var mo2Compiler = (MO2Compiler)_compiler; if (!_compiler.IndexedFiles.TryGetValue(source.Hash, out var found)) return null; var result = source.EvolveTo(); var match = found.Where(f => f.Name.FileName == source.Path.FileName) - .OrderBy(f => f.NestingFactor) + .OrderBy(f => GetFilePriority(mo2Compiler, f)) + .ThenBy(f => f.NestingFactor) .FirstOrDefault() ?? found.OrderBy(f => f.NestingFactor).FirstOrDefault(); diff --git a/Wabbajack.Lib/CompilationSteps/IncludePatches.cs b/Wabbajack.Lib/CompilationSteps/IncludePatches.cs index 7d8cc4ec..4fb886bc 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludePatches.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludePatches.cs @@ -80,7 +80,8 @@ namespace Wabbajack.Lib.CompilationSteps { // Just match some file in the archive based on the smallest delta difference found = arch.SelectMany(a => a.ThisAndAllChildren) - .OrderBy(o => Math.Abs(o.Size - source.File.Size)) + .OrderBy(o => DirectMatch.GetFilePriority(_mo2Compiler, o)) + .ThenBy(o => Math.Abs(o.Size - source.File.Size)) .First(); } } diff --git a/Wabbajack.Lib/Data.cs b/Wabbajack.Lib/Data.cs index 450bfe43..cc0cab5e 100644 --- a/Wabbajack.Lib/Data.cs +++ b/Wabbajack.Lib/Data.cs @@ -290,6 +290,7 @@ namespace Wabbajack.Lib public string Meta = string.Empty; public string Name = string.Empty; public VirtualFile File { get; } + public AbstractDownloadState? State { get; set; } public IndexedArchive(VirtualFile file) { diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index 8ee64682..079966d9 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -221,7 +221,9 @@ namespace Wabbajack.Lib } } - await CleanInvalidArchives(); + IndexedArchives = IndexedArchives.DistinctBy(a => a.File.AbsoluteName).ToList(); + + await CleanInvalidArchivesAndFillState(); UpdateTracker.NextStep("Finding Install Files"); ModListOutputFolder.CreateDirectory(); @@ -293,6 +295,8 @@ namespace Wabbajack.Lib .Where(f => f.Item1 != default) .Select(f => new KeyValuePair(f.Item1, f.Item2))); + ArchivesByFullPath = IndexedArchives.ToDictionary(a => a.File.AbsoluteName); + if (cancel.IsCancellationRequested) return false; var stack = MakeStack(); UpdateTracker.NextStep("Running Compilation Stack"); @@ -359,15 +363,16 @@ namespace Wabbajack.Lib return true; } + public bool UseGamePaths { get; set; } = true; - private async Task CleanInvalidArchives() + private async Task CleanInvalidArchivesAndFillState() { var remove = (await IndexedArchives.PMap(Queue, async a => { try { - await ResolveArchive(a); + a.State = (await ResolveArchive(a)).State; return null; } catch diff --git a/Wabbajack.VirtualFileSystem/VirtualFile.cs b/Wabbajack.VirtualFileSystem/VirtualFile.cs index 96106c6c..58345be5 100644 --- a/Wabbajack.VirtualFileSystem/VirtualFile.cs +++ b/Wabbajack.VirtualFileSystem/VirtualFile.cs @@ -125,6 +125,9 @@ namespace Wabbajack.VirtualFileSystem } + public VirtualFile TopParent => IsNative ? this : Parent.TopParent; + + public T ThisAndAllChildrenReduced(T acc, Func fn) { acc = fn(acc, this);