wabbajack/Wabbajack.Lib/CompilationSteps/IgnoreStartsWith.cs

52 lines
1.3 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Wabbajack.Lib.CompilationSteps
{
public class IgnoreStartsWith : ACompilationStep
{
private readonly string _prefix;
private readonly string _reason;
public IgnoreStartsWith(ACompiler compiler, string prefix) : base(compiler)
{
_prefix = prefix;
_reason = string.Format("Ignored because path starts with {0}", _prefix);
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
2020-03-25 12:47:25 +00:00
if (!((string)source.Path).StartsWith(_prefix))
{
2020-03-25 12:47:25 +00:00
return null;
}
2020-03-25 12:47:25 +00:00
var result = source.EvolveTo<IgnoredDirectly>();
result.Reason = _reason;
return result;
}
public override IState GetState()
{
return new State(_prefix);
}
[JsonObject("IgnoreStartsWith")]
public class State : IState
{
public string Prefix { get; set; }
public State(string prefix)
{
Prefix = prefix;
}
public ICompilationStep CreateStep(ACompiler compiler)
{
return new IgnoreStartsWith(compiler, Prefix);
}
}
}
}