And priority to how game files are resolved

This commit is contained in:
Timothy Baldridge 2020-06-20 17:10:43 -06:00
parent 6c74279bfd
commit 0b74c04c86
7 changed files with 34 additions and 6 deletions

View File

@ -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

View File

@ -47,6 +47,8 @@ namespace Wabbajack.Lib
public ModList ModList = new ModList();
public List<IndexedArchive> IndexedArchives = new List<IndexedArchive>();
public Dictionary<AbsolutePath, IndexedArchive> ArchivesByFullPath { get; set; } = new Dictionary<AbsolutePath, IndexedArchive>();
public Dictionary<Hash, IEnumerable<VirtualFile>> IndexedFiles = new Dictionary<Hash, IEnumerable<VirtualFile>>();
public ACompiler(int steps)

View File

@ -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<Directive?> Run(RawSourceFile source)
{
var mo2Compiler = (MO2Compiler)_compiler;
if (!_compiler.IndexedFiles.TryGetValue(source.Hash, out var found)) return null;
var result = source.EvolveTo<FromArchive>();
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();

View File

@ -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();
}
}

View File

@ -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)
{

View File

@ -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<AbsolutePath, dynamic>(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

View File

@ -125,6 +125,9 @@ namespace Wabbajack.VirtualFileSystem
}
public VirtualFile TopParent => IsNative ? this : Parent.TopParent;
public T ThisAndAllChildrenReduced<T>(T acc, Func<T, VirtualFile, T> fn)
{
acc = fn(acc, this);