@@ -18,49 +18,49 @@ public class ValidationResult
1818
1919 public static class ValidationUtils
2020 {
21- public static ValidationResult IsDirValid ( string dir , string itemName )
22- {
23- var result = new ValidationResult ( ) { IsSuccess = true , FieldName = itemName } ;
24-
25- if ( dir . Trim ( ) == "" )
26- {
27- result . IsSuccess = false ;
28- result . ErrorMessage = "Dir is required" ;
29- return result ;
30- }
31-
32- Regex dirRegex = new Regex ( @"^(([a-zA-Z]:)|(\\{2}[^\/\\:*?<>|]+)) (\\([^\/\\:*?<>|]*))*(\\)?$" ) ;
33- Regex dirRegexNotRooted = new Regex ( @"(\\([^\/\\:*?<>|]*))*(\\)?$" ) ;
34- if ( Path . IsPathRooted ( dir ) )
35- {
36- if ( ! dirRegex . IsMatch ( dir ) )
37- {
38- result . IsSuccess = false ;
39- result . ErrorMessage = "Dir is invalid" ;
40- return result ;
41- }
42- }
43- else
44- {
45- if ( ! dirRegexNotRooted . IsMatch ( dir ) )
46- {
47- result . IsSuccess = false ;
48- result . ErrorMessage = "Dir is invalid" ;
49- return result ;
50- }
51- }
52-
53- if ( ! Directory . Exists ( dir ) )
54- {
55- result . IsSuccess = false ;
56- result . ErrorMessage = "Dir does not exist" ;
57- return result ;
58- }
59-
60- return result ;
61- }
62-
63- public static ValidationResult IsNotEmpty ( string text , string itemName )
21+ public static ValidationResult IsDirValid ( string dir , string itemName )
22+ {
23+ var result = new ValidationResult ( ) { IsSuccess = true , FieldName = itemName } ;
24+
25+ if ( dir . Trim ( ) == "" )
26+ {
27+ result . IsSuccess = false ;
28+ result . ErrorMessage = "Dir is required" ;
29+ return result ;
30+ }
31+
32+ Regex dirRegex = new Regex ( @"^(([a-zA-Z]:)|(\\{2}[^\/\\:*?<>|]+))(\\([^\/\\:*?<>|]*))*(\\)?$" ) ;
33+ Regex dirRegexNotRooted = new Regex ( @"(\\([^\/\\:*?<>|]*))*(\\)?$" ) ;
34+ if ( Path . IsPathRooted ( dir ) )
35+ {
36+ if ( ! dirRegex . IsMatch ( dir ) )
37+ {
38+ result . IsSuccess = false ;
39+ result . ErrorMessage = "Dir is invalid" ;
40+ return result ;
41+ }
42+ }
43+ else
44+ {
45+ if ( ! dirRegexNotRooted . IsMatch ( dir ) )
46+ {
47+ result . IsSuccess = false ;
48+ result . ErrorMessage = "Dir is invalid" ;
49+ return result ;
50+ }
51+ }
52+
53+ if ( ! Directory . Exists ( dir ) )
54+ {
55+ result . IsSuccess = false ;
56+ result . ErrorMessage = "Dir does not exist" ;
57+ return result ;
58+ }
59+
60+ return result ;
61+ }
62+
63+ public static ValidationResult IsNotEmpty ( string text , string itemName )
6464 {
6565 var result = new ValidationResult ( ) { IsSuccess = true , FieldName = itemName } ;
6666
0 commit comments