2018-11-23 07:03:32 +00:00
|
|
|
using FluentValidation.Validators;
|
2019-07-01 01:50:01 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2018-11-23 07:03:32 +00:00
|
|
|
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();
|
|
|
|
|
2019-07-01 01:50:01 +00:00
|
|
|
foreach (var systemFolder in SystemFolders.GetSystemFolders())
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
context.MessageFormatter.AppendArgument("systemFolder", systemFolder);
|
|
|
|
|
|
|
|
if (systemFolder.PathEquals(folder))
|
|
|
|
{
|
2019-07-01 01:50:01 +00:00
|
|
|
context.MessageFormatter.AppendArgument("relationship", "set to");
|
2018-11-23 07:03:32 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (systemFolder.IsParentPath(folder))
|
|
|
|
{
|
|
|
|
context.MessageFormatter.AppendArgument("relationship", "child of");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|