1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-17 21:26:22 -04:00
Files
Radarr/src/NzbDrone.Core/Validation/Paths/FileExistsValidator.cs
Mark McDowall 10f5f3c5c8 New: Require password confirmation when setting or changing password
(cherry picked from commit b248163df598dc611ee919d525eb7357256d73d5)
2023-11-19 21:10:52 +02:00

30 lines
832 B
C#

using FluentValidation.Validators;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Validation.Paths
{
public class FileExistsValidator : PropertyValidator
{
private readonly IDiskProvider _diskProvider;
public FileExistsValidator(IDiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
protected override string GetDefaultMessageTemplate() => "File '{file}' does not exist";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return false;
}
context.MessageFormatter.AppendArgument("file", context.PropertyValue.ToString());
return _diskProvider.FileExists(context.PropertyValue.ToString());
}
}
}