Radarr/src/NzbDrone.Core/Validation/Paths/SystemFolderValidator.cs

41 lines
1.1 KiB
C#

using FluentValidation.Validators;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Validation.Paths
{
public class SystemFolderValidator : PropertyValidator
{
public SystemFolderValidator()
: base("Is {relationship} system folder {systemFolder}")
{
}
protected override bool IsValid(PropertyValidatorContext context)
{
var folder = context.PropertyValue.ToString();
foreach (var systemFolder in SystemFolders.GetSystemFolders())
{
context.MessageFormatter.AppendArgument("systemFolder", systemFolder);
if (systemFolder.PathEquals(folder))
{
context.MessageFormatter.AppendArgument("relationship", "set to");
return false;
}
if (systemFolder.IsParentPath(folder))
{
context.MessageFormatter.AppendArgument("relationship", "child of");
return false;
}
}
return true;
}
}
}