mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #199 from wabbajack-tools/better-patch-file-selection
Better selection of patch file sources
This commit is contained in:
commit
96abd7aa30
@ -420,6 +420,19 @@ namespace Wabbajack.Common
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A combination of .Select(func).Where(v => v != default). So select and filter default values.
|
||||
/// </summary>
|
||||
/// <typeparam name="TIn"></typeparam>
|
||||
/// <typeparam name="TOut"></typeparam>
|
||||
/// <param name="coll"></param>
|
||||
/// <param name="func"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<TOut> Keep<TIn, TOut>(this IEnumerable<TIn> coll, Func<TIn, TOut> func) where TOut : IComparable<TOut>
|
||||
{
|
||||
return coll.Select(func).Where(v => v.CompareTo(default) != 0);
|
||||
}
|
||||
|
||||
public static byte[] ReadAll(this Stream ins)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
|
@ -21,10 +21,21 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
|
||||
public override Directive Run(RawSourceFile source)
|
||||
{
|
||||
if (!_indexed.TryGetValue(Path.GetFileName(source.File.Name.ToLower()), out var value))
|
||||
if (!_indexed.TryGetValue(Path.GetFileName(source.File.Name.ToLower()), out var choices))
|
||||
return null;
|
||||
|
||||
var found = value.OrderByDescending(f => (f.FilesInFullPath.First() ?? f).LastModified).First();
|
||||
var mod_ini = ((MO2Compiler)_compiler).ModMetas.FirstOrDefault(f => source.AbsolutePath.StartsWith(f.Key));
|
||||
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();
|
||||
}
|
||||
|
||||
var e = source.EvolveTo<PatchedFromArchive>();
|
||||
e.ArchiveHashPath = found.MakeRelativePaths();
|
||||
@ -53,4 +64,4 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace Wabbajack.Lib
|
||||
public string MO2Folder;
|
||||
|
||||
public string MO2Profile;
|
||||
public Dictionary<string, dynamic> ModMetas { get; set; }
|
||||
|
||||
public MO2Compiler(string mo2Folder)
|
||||
{
|
||||
@ -142,6 +143,13 @@ namespace Wabbajack.Lib
|
||||
})
|
||||
.ToList();
|
||||
|
||||
ModMetas = Directory.EnumerateDirectories(Path.Combine(MO2Folder, "mods"))
|
||||
.Keep(f =>
|
||||
{
|
||||
var path = Path.Combine(f, "meta.ini");
|
||||
return File.Exists(path) ? (f, path.LoadIniFile()) : default;
|
||||
}).ToDictionary(f => f.f + "\\", v => v.Item2);
|
||||
|
||||
IndexedFiles = IndexedArchives.SelectMany(f => f.File.ThisAndAllChildren)
|
||||
.OrderBy(f => f.NestingFactor)
|
||||
.GroupBy(f => f.Hash)
|
||||
@ -254,6 +262,7 @@ namespace Wabbajack.Lib
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void IncludeArchiveMetadata()
|
||||
{
|
||||
Utils.Log($"Including {SelectedArchives.Count} .meta files for downloads");
|
||||
|
@ -156,12 +156,20 @@ namespace Wabbajack.Test
|
||||
var profile = utils.AddProfile();
|
||||
var mod = utils.AddMod();
|
||||
var ini = utils.AddModFile(mod, @"foo.ini", 10);
|
||||
var meta = utils.AddModFile(mod, "meta.ini");
|
||||
|
||||
utils.Configure();
|
||||
|
||||
|
||||
utils.AddManualDownload(
|
||||
var archive = utils.AddManualDownload(
|
||||
new Dictionary<string, byte[]> { { "/baz/foo.ini", File.ReadAllBytes(ini) } });
|
||||
|
||||
File.WriteAllLines(meta, new[]
|
||||
{
|
||||
"[General]",
|
||||
$"installationFile={archive}",
|
||||
});
|
||||
|
||||
// Modify after creating mod archive in the downloads folder
|
||||
File.WriteAllText(ini, "Wabbajack, Wabbajack, Wabbajack!");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user