2019-10-30 12:29:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
using VFS;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.CompilationSteps
|
|
|
|
|
{
|
|
|
|
|
public class IncludePatches : ACompilationStep
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<string, IGrouping<string, VirtualFile>> _indexed;
|
|
|
|
|
|
2019-11-03 16:45:49 +00:00
|
|
|
|
public IncludePatches(ACompiler compiler) : base(compiler)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
|
|
|
|
_indexed = _compiler.IndexedFiles.Values
|
|
|
|
|
.SelectMany(f => f)
|
|
|
|
|
.GroupBy(f => Path.GetFileName(Enumerable.Last(f.Paths)).ToLower())
|
|
|
|
|
.ToDictionary(f => f.Key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Directive Run(RawSourceFile source)
|
|
|
|
|
{
|
|
|
|
|
if (!_indexed.TryGetValue(Path.GetFileName(Enumerable.Last(source.File.Paths).ToLower()), out var value))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var found = value.OrderByDescending(f => (f.TopLevelArchive ?? f).LastModified).First();
|
|
|
|
|
|
|
|
|
|
var e = source.EvolveTo<PatchedFromArchive>();
|
|
|
|
|
e.ArchiveHashPath = found.MakeRelativePaths();
|
|
|
|
|
e.To = source.Path;
|
|
|
|
|
e.Hash = source.File.Hash;
|
|
|
|
|
|
|
|
|
|
Utils.TryGetPatch(found.Hash, source.File.Hash, out var data);
|
|
|
|
|
|
|
|
|
|
if (data != null)
|
|
|
|
|
e.PatchID = _compiler.IncludeFile(data);
|
|
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
public override IState GetState()
|
|
|
|
|
{
|
|
|
|
|
return new State();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonObject("IncludePatches")]
|
|
|
|
|
public class State : IState
|
|
|
|
|
{
|
2019-11-03 16:45:49 +00:00
|
|
|
|
public ICompilationStep CreateStep(ACompiler compiler)
|
2019-10-31 02:24:42 +00:00
|
|
|
|
{
|
|
|
|
|
return new IncludePatches(compiler);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
}
|