2019-10-30 12:29:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.CompilationSteps
|
|
|
|
|
{
|
|
|
|
|
public class IgnoreDisabledMods : ACompilationStep
|
|
|
|
|
{
|
|
|
|
|
private readonly IEnumerable<string> _allEnabledMods;
|
2019-11-18 00:17:06 +00:00
|
|
|
|
private readonly MO2Compiler _mo2Compiler;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
2019-11-03 16:45:49 +00:00
|
|
|
|
public IgnoreDisabledMods(ACompiler compiler) : base(compiler)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2019-11-18 00:17:06 +00:00
|
|
|
|
_mo2Compiler = (MO2Compiler) compiler;
|
2019-11-11 20:03:27 +00:00
|
|
|
|
var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IsAlwaysEnabled(f.Value)).Select(f => f.Key).ToHashSet();
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
2019-11-11 20:03:27 +00:00
|
|
|
|
_allEnabledMods = _mo2Compiler.SelectedProfiles
|
|
|
|
|
.SelectMany(p => File.ReadAllLines(Path.Combine(_mo2Compiler.MO2Folder, "profiles", p, "modlist.txt")))
|
2019-10-30 12:29:06 +00:00
|
|
|
|
.Where(line => line.StartsWith("+") || line.EndsWith("_separator"))
|
|
|
|
|
.Select(line => line.Substring(1))
|
|
|
|
|
.Concat(alwaysEnabled)
|
|
|
|
|
.Select(line => Path.Combine("mods", line) + "\\")
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Directive Run(RawSourceFile source)
|
|
|
|
|
{
|
|
|
|
|
if (!source.Path.StartsWith("mods") || _allEnabledMods.Any(mod => source.Path.StartsWith(mod)))
|
|
|
|
|
return null;
|
|
|
|
|
var r = source.EvolveTo<IgnoredDirectly>();
|
|
|
|
|
r.Reason = "Disabled Mod";
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 02:24:42 +00:00
|
|
|
|
public override IState GetState()
|
|
|
|
|
{
|
|
|
|
|
return new State();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
|
|
|
|
private 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 &&
|
|
|
|
|
data.General.notes.Contains(Consts.WABBAJACK_ALWAYS_ENABLE))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
[JsonObject("IgnoreDisabledMods")]
|
|
|
|
|
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 IgnoreDisabledMods(compiler);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
}
|