wabbajack/Wabbajack.Lib/CompilationSteps/IgnoreDisabledMods.cs

67 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using Newtonsoft.Json;
using Wabbajack.Common;
namespace Wabbajack.Lib.CompilationSteps
{
public class IgnoreDisabledMods : ACompilationStep
{
2020-03-25 23:15:19 +00:00
private readonly IEnumerable<AbsolutePath> _allEnabledMods;
private readonly MO2Compiler _mo2Compiler;
public IgnoreDisabledMods(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (MO2Compiler) compiler;
2020-01-07 13:50:11 +00:00
var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IsAlwaysEnabled(f.Value)).Select(f => f.Key).Distinct();
_allEnabledMods = _mo2Compiler.SelectedProfiles
2020-03-25 12:47:25 +00:00
.SelectMany(p => _mo2Compiler.MO2Folder.Combine("profiles", p, "modlist.txt").ReadAllLines())
.Where(line => line.StartsWith("+") || line.EndsWith("_separator"))
2020-03-25 23:15:19 +00:00
.Select(line => line.Substring(1).RelativeTo(_mo2Compiler.MO2ModsFolder))
.Concat(alwaysEnabled)
.ToList();
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
2020-03-28 02:54:14 +00:00
if (!source.AbsolutePath.InFolder(_mo2Compiler.MO2ModsFolder)) return null;
if (_allEnabledMods.Any(mod => source.AbsolutePath.InFolder(mod)))
return null;
var r = source.EvolveTo<IgnoredDirectly>();
r.Reason = "Disabled Mod";
return r;
}
public override IState GetState()
{
return new State();
}
2020-04-04 18:34:00 +00:00
public static bool IsAlwaysEnabled(dynamic data)
{
if (data == null)
return false;
if (data.General != null && data.General.notes != null &&
data.General.notes.Contains(
Consts.WABBAJACK_ALWAYS_ENABLE))
return true;
if (data.General != null && data.General.comments != null &&
2020-02-05 05:17:12 +00:00
data.General.comments.Contains(Consts.WABBAJACK_ALWAYS_ENABLE))
return true;
return false;
}
[JsonObject("IgnoreDisabledMods")]
public class State : IState
{
public ICompilationStep CreateStep(ACompiler compiler)
{
return new IgnoreDisabledMods(compiler);
}
}
}
}