From 84b27b2a9c4fe8d03a4ccebb9083d42d9a43d171 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Mon, 11 May 2020 17:14:45 -0500 Subject: [PATCH 1/2] Readded a nuked feature Was originally from this commit: 7fba212ba365bf2d8906df8be0178c3952199020 --- .../CompilationSteps/IncludeThisProfile.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs index 4d0141a3..8e3be39b 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs @@ -39,10 +39,17 @@ namespace Wabbajack.Lib.CompilationSteps return new State(); } - private static async Task ReadAndCleanModlist(AbsolutePath absolutePath) - { - var lines = await absolutePath.ReadAllLinesAsync(); - lines = lines.Where(line => !(line.StartsWith("-") && !line.EndsWith("_separator"))).ToArray(); + private async Task ReadAndCleanModlist(AbsolutePath absolutePath) + { + var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IgnoreDisabledMods.IsAlwaysEnabled(f.Value)) + .Select(f => f.Key) + .Distinct(); + var lines = File.ReadAllLines(absolutePath.ToString()).Where(l => + { + return l.StartsWith("+") + || alwaysEnabled.Any(x => x.Equals(l.Substring(1))) + || l.EndsWith("_separator"); + }).ToArray(); return Encoding.UTF8.GetBytes(string.Join("\r\n", lines)); } From 233013c4959d4fdeb3acc5dbf6f2ed40be888c34 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 12 May 2020 19:48:57 -0600 Subject: [PATCH 2/2] use async IO and Paths api Let's see how I can code in GitHub's editor --- .../CompilationSteps/IncludeThisProfile.cs | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs index 8e3be39b..665be40d 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludeThisProfile.cs @@ -1,65 +1,65 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Alphaleonis.Win32.Filesystem; -using Newtonsoft.Json; -using Wabbajack.Common; - -namespace Wabbajack.Lib.CompilationSteps -{ - public class IncludeThisProfile : ACompilationStep - { - private readonly IEnumerable _correctProfiles; - private MO2Compiler _mo2Compiler; - - public IncludeThisProfile(ACompiler compiler) : base(compiler) - { - _mo2Compiler = (MO2Compiler) compiler; - _correctProfiles = _mo2Compiler.SelectedProfiles.Select(p => _mo2Compiler.MO2ProfileDir.Parent.Combine(p)).ToList(); - } - - public override async ValueTask Run(RawSourceFile source) - { - if (!_correctProfiles.Any(p => source.AbsolutePath.InFolder(p))) - return null; - - var data = source.Path.FileName == Consts.ModListTxt - ? await ReadAndCleanModlist(source.AbsolutePath) - : await source.AbsolutePath.ReadAllBytesAsync(); - - var e = source.EvolveTo(); - e.SourceDataID = await _compiler.IncludeFile(data); - return e; - - } - - public override IState GetState() - { - return new State(); - } - - private async Task ReadAndCleanModlist(AbsolutePath absolutePath) +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Alphaleonis.Win32.Filesystem; +using Newtonsoft.Json; +using Wabbajack.Common; + +namespace Wabbajack.Lib.CompilationSteps +{ + public class IncludeThisProfile : ACompilationStep + { + private readonly IEnumerable _correctProfiles; + private MO2Compiler _mo2Compiler; + + public IncludeThisProfile(ACompiler compiler) : base(compiler) + { + _mo2Compiler = (MO2Compiler) compiler; + _correctProfiles = _mo2Compiler.SelectedProfiles.Select(p => _mo2Compiler.MO2ProfileDir.Parent.Combine(p)).ToList(); + } + + public override async ValueTask Run(RawSourceFile source) + { + if (!_correctProfiles.Any(p => source.AbsolutePath.InFolder(p))) + return null; + + var data = source.Path.FileName == Consts.ModListTxt + ? await ReadAndCleanModlist(source.AbsolutePath) + : await source.AbsolutePath.ReadAllBytesAsync(); + + var e = source.EvolveTo(); + e.SourceDataID = await _compiler.IncludeFile(data); + return e; + + } + + public override IState GetState() + { + return new State(); + } + + private async Task ReadAndCleanModlist(AbsolutePath absolutePath) { var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IgnoreDisabledMods.IsAlwaysEnabled(f.Value)) .Select(f => f.Key) .Distinct(); - var lines = File.ReadAllLines(absolutePath.ToString()).Where(l => + var lines = (await absolutePath.ReadAllLinesAsync()).Where(l => { return l.StartsWith("+") || alwaysEnabled.Any(x => x.Equals(l.Substring(1))) || l.EndsWith("_separator"); }).ToArray(); - return Encoding.UTF8.GetBytes(string.Join("\r\n", lines)); - } - - [JsonObject("IncludeThisProfile")] - public class State : IState - { - public ICompilationStep CreateStep(ACompiler compiler) - { - return new IncludeThisProfile(compiler); - } - } - } -} + return Encoding.UTF8.GetBytes(string.Join("\r\n", lines)); + } + + [JsonObject("IncludeThisProfile")] + public class State : IState + { + public ICompilationStep CreateStep(ACompiler compiler) + { + return new IncludeThisProfile(compiler); + } + } + } +}