wabbajack/Wabbajack.Compiler/CompilationSteps/IgnoreDisabledMods.cs

57 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2021-09-27 12:42:46 +00:00
using Wabbajack.DTOs;
using Wabbajack.DTOs.Directives;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Compiler.CompilationSteps;
public class IgnoreDisabledMods : ACompilationStep
{
2021-10-23 16:51:17 +00:00
private readonly IEnumerable<AbsolutePath> _allEnabledMods;
private readonly MO2Compiler _mo2Compiler;
public IgnoreDisabledMods(ACompiler compiler) : base(compiler)
{
2021-10-23 16:51:17 +00:00
_mo2Compiler = (MO2Compiler) compiler;
2022-09-27 03:02:39 +00:00
if (!compiler.Settings.IsMO2Modlist)
{
Disabled = true;
return;
}
_allEnabledMods = _mo2Compiler._settings.AllProfiles
2021-10-23 16:51:17 +00:00
.SelectMany(p => _mo2Compiler._settings.Source.Combine("profiles", p, "modlist.txt").ReadAllLines())
.Where(line => line.StartsWith("+") || line.EndsWith("_separator"))
.Select(line => line[1..].ToRelativePath().RelativeTo(_mo2Compiler.MO2ModsFolder))
.Concat(_mo2Compiler.Mo2Settings.AlwaysEnabled.Select(r => r.RelativeTo(_mo2Compiler.Settings.Source)))
//.Except(alwaysDisabled)
.ToList();
}
2021-10-23 16:51:17 +00:00
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
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;
}
2021-10-23 16:51:17 +00:00
public static bool HasFlagInNotes(dynamic data, string flag)
{
if (data == null)
return false;
if (data.General != null && data.General.notes != null &&
data.General.notes.Contains(
flag))
return true;
2021-10-23 16:51:17 +00:00
return data.General != null && data.General.comments != null &&
data.General.comments.Contains(flag);
}
2021-10-23 16:51:17 +00:00
}