You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/Validation/Paths/SystemFolderValidator.cs

39 lines
1.2 KiB

using FluentValidation.Validators;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Validation.Paths
{
public class SystemFolderValidator : PropertyValidator
{
protected override string GetDefaultMessageTemplate() => "Path '{path}' is {relationship} system folder {systemFolder}";
protected override bool IsValid(PropertyValidatorContext context)
{
var folder = context.PropertyValue.ToString();
context.MessageFormatter.AppendArgument("path", folder);
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;
}
}
}