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.
47 lines
1.3 KiB
47 lines
1.3 KiB
using FluentValidation.Validators;
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
namespace NzbDrone.Core.Validation.Paths
|
|
{
|
|
public class StartupFolderValidator : PropertyValidator
|
|
{
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
public StartupFolderValidator(IAppFolderInfo appFolderInfo)
|
|
{
|
|
_appFolderInfo = appFolderInfo;
|
|
}
|
|
|
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' cannot be {relationship} the start up folder";
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var startupFolder = _appFolderInfo.StartUpFolder;
|
|
var folder = context.PropertyValue.ToString();
|
|
context.MessageFormatter.AppendArgument("path", folder);
|
|
|
|
if (startupFolder.PathEquals(folder))
|
|
{
|
|
context.MessageFormatter.AppendArgument("relationship", "set to");
|
|
|
|
return false;
|
|
}
|
|
|
|
if (startupFolder.IsParentPath(folder))
|
|
{
|
|
context.MessageFormatter.AppendArgument("relationship", "child of");
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|