2019-10-30 12:29:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-12-04 01:26:26 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-11-15 13:06:34 +00:00
|
|
|
|
using Wabbajack.VirtualFileSystem;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2019-11-15 13:06:34 +00:00
|
|
|
|
.GroupBy(f => Path.GetFileName(f.Name).ToLower())
|
2019-10-30 12:29:06 +00:00
|
|
|
|
.ToDictionary(f => f.Key);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 01:26:26 +00:00
|
|
|
|
public override async ValueTask<Directive> Run(RawSourceFile source)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2019-11-21 21:32:58 +00:00
|
|
|
|
if (!_indexed.TryGetValue(Path.GetFileName(source.File.Name.ToLower()), out var choices))
|
2019-10-30 12:29:06 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
2019-11-21 22:35:59 +00:00
|
|
|
|
var mod_ini = ((MO2Compiler)_compiler).ModMetas.FirstOrDefault(f => source.Path.StartsWith(f.Key));
|
2019-11-21 21:32:58 +00:00
|
|
|
|
var installationFile = mod_ini.Value?.General?.installationFile;
|
|
|
|
|
|
|
|
|
|
var found = choices.FirstOrDefault(
|
|
|
|
|
f => Path.GetFileName(f.FilesInFullPath.First().Name) == installationFile);
|
|
|
|
|
|
|
|
|
|
if (found == null)
|
|
|
|
|
{
|
|
|
|
|
found = choices.OrderBy(f => f.NestingFactor)
|
|
|
|
|
.ThenByDescending(f => (f.FilesInFullPath.First() ?? f).LastModified)
|
|
|
|
|
.First();
|
|
|
|
|
}
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
|
|
|
|
var e = source.EvolveTo<PatchedFromArchive>();
|
2019-11-22 05:19:42 +00:00
|
|
|
|
e.FromHash = found.Hash;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
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-11-21 21:32:58 +00:00
|
|
|
|
}
|