aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Validation/FileExistsAttribute.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/slskd/Common/Validation/FileExistsAttribute.cs b/src/slskd/Common/Validation/FileExistsAttribute.cs
new file mode 100644
index 00000000..5453c0ba
--- /dev/null
+++ b/src/slskd/Common/Validation/FileExistsAttribute.cs
@@ -0,0 +1,20 @@
+namespace slskd.Validation
+{
+ using System.ComponentModel.DataAnnotations;
+ using System.IO;
+
+ public class FileExistsAttribute : ValidationAttribute
+ {
+ protected override ValidationResult IsValid(object value, ValidationContext validationContext)
+ {
+ var file = Path.GetFullPath(value.ToString());
+
+ if (!string.IsNullOrEmpty(file) && !File.Exists(file))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field specifies a non-existent file '{file}'.");
+ }
+
+ return ValidationResult.Success;
+ }
+ }
+} \ No newline at end of file