From 7fba212ba365bf2d8906df8be0178c3952199020 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 4 Apr 2020 20:34:00 +0200 Subject: [PATCH] Fixed modlist.txt order --- .../CompilationSteps/IgnoreDisabledMods.cs | 3 +- .../CompilationSteps/IncludeThisProfile.cs | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs b/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs index 7cb8f350..c85b3645 100644 --- a/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs +++ b/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs @@ -40,8 +40,7 @@ namespace Wabbajack.Lib.CompilationSteps return new State(); } - - private static bool IsAlwaysEnabled(dynamic data) + public static bool IsAlwaysEnabled(dynamic data) { if (data == null) return false; diff --git a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs index e2ab4dd1..982ca552 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs @@ -10,7 +10,7 @@ namespace Wabbajack.Lib.CompilationSteps public class IncludeThisProfile : ACompilationStep { private readonly IEnumerable _correctProfiles; - private readonly MO2Compiler _mo2Compiler; + private MO2Compiler _mo2Compiler; public IncludeThisProfile(ACompiler compiler) : base(compiler) { @@ -20,18 +20,17 @@ namespace Wabbajack.Lib.CompilationSteps public override async ValueTask Run(RawSourceFile source) { - if (_correctProfiles.Any(p => source.Path.StartsWith(p))) - { - var data = source.Path.EndsWith("\\modlist.txt") - ? ReadAndCleanModlist(source.AbsolutePath) - : File.ReadAllBytes(source.AbsolutePath); + if (!_correctProfiles.Any(p => source.Path.StartsWith(p))) + return null; - var e = source.EvolveTo(); - e.SourceDataID = _compiler.IncludeFile(data); - return e; - } + var data = source.Path.EndsWith("\\modlist.txt") + ? ReadAndCleanModlist(source.AbsolutePath) + : File.ReadAllBytes(source.AbsolutePath); + + var e = source.EvolveTo(); + e.SourceDataID = _compiler.IncludeFile(data); + return e; - return null; } public override IState GetState() @@ -39,12 +38,17 @@ namespace Wabbajack.Lib.CompilationSteps return new State(); } - private static byte[] ReadAndCleanModlist(string absolutePath) + private byte[] ReadAndCleanModlist(string absolutePath) { - var lines = File.ReadAllLines(absolutePath); - lines = (from line in lines - where !(line.StartsWith("-") && !line.EndsWith("_separator")) - select line).ToArray(); + var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IgnoreDisabledMods.IsAlwaysEnabled(f.Value)) + .Select(f => f.Key) + .Distinct(); + var lines = File.ReadAllLines(absolutePath).Where(l => + { + return l.StartsWith("+") + || alwaysEnabled.Any(x => x == l.Substring(1)) + || l.EndsWith("_separator"); + }).ToArray(); return Encoding.UTF8.GetBytes(string.Join("\r\n", lines)); }