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-01-07 13:50:11 +00:00
|
|
|
|
var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IsAlwaysEnabled(f.Value)).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-03-25 12:47:25 +00:00
|
|
|
|
.SelectMany(p => _mo2Compiler.MO2Folder.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)
|
|
|
|
|
.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-04-04 18:34:00 +00:00
|
|
|
|
public static bool IsAlwaysEnabled(dynamic data)
|
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(
|
|
|
|
|
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))
|
2019-10-30 12:29:06 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-04 01:26:26 +00:00
|
|
|
|
}
|