2019-10-30 12:29:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-12-04 01:26:26 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2020-03-25 23:15:19 +00:00
|
|
|
|
private readonly IEnumerable<AbsolutePath> _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;
|
2020-08-10 17:18:16 +00:00
|
|
|
|
var alwaysEnabled = _mo2Compiler.ModInis.Where(f => HasFlagInNotes(f.Value, Consts.WABBAJACK_ALWAYS_ENABLE)).Select(f => f.Key).Distinct();
|
|
|
|
|
var alwaysDisabled = _mo2Compiler.ModInis
|
|
|
|
|
.Where(f => HasFlagInNotes(f.Value, Consts.WABBAJACK_ALWAYS_DISABLE)).Select(f => f.Key).Distinct();
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
2019-11-11 20:03:27 +00:00
|
|
|
|
_allEnabledMods = _mo2Compiler.SelectedProfiles
|
2020-10-18 12:59:49 +00:00
|
|
|
|
.SelectMany(p => _mo2Compiler.SourcePath.Combine("profiles", p, "modlist.txt").ReadAllLines())
|
2019-10-30 12:29:06 +00:00
|
|
|
|
.Where(line => line.StartsWith("+") || line.EndsWith("_separator"))
|
2020-03-25 23:15:19 +00:00
|
|
|
|
.Select(line => line.Substring(1).RelativeTo(_mo2Compiler.MO2ModsFolder))
|
2019-10-30 12:29:06 +00:00
|
|
|
|
.Concat(alwaysEnabled)
|
2020-08-10 17:18:16 +00:00
|
|
|
|
.Except(alwaysDisabled)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 18:14:05 +00:00
|
|
|
|
public override async ValueTask<Directive?> Run(RawSourceFile source)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2020-03-28 02:54:14 +00:00
|
|
|
|
if (!source.AbsolutePath.InFolder(_mo2Compiler.MO2ModsFolder)) return null;
|
|
|
|
|
if (_allEnabledMods.Any(mod => source.AbsolutePath.InFolder(mod)))
|
2019-10-30 12:29:06 +00:00
|
|
|
|
return null;
|
|
|
|
|
var r = source.EvolveTo<IgnoredDirectly>();
|
|
|
|
|
r.Reason = "Disabled Mod";
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:18:16 +00:00
|
|
|
|
public static bool HasFlagInNotes(dynamic data, string flag)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (data == null)
|
|
|
|
|
return false;
|
|
|
|
|
if (data.General != null && data.General.notes != null &&
|
|
|
|
|
data.General.notes.Contains(
|
2020-08-10 17:18:16 +00:00
|
|
|
|
flag))
|
2019-10-30 12:29:06 +00:00
|
|
|
|
return true;
|
2020-08-10 17:18:16 +00:00
|
|
|
|
|
|
|
|
|
return data.General != null && data.General.comments != null &&
|
|
|
|
|
data.General.comments.Contains(flag);
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-04 01:26:26 +00:00
|
|
|
|
}
|