Преглед изворни кода

Remove ExtendedFileSystemInfo (#9749)

Bond-009 пре 2 година
родитељ
комит
756ee38d01

+ 0 - 13
Emby.Server.Implementations/IO/ExtendedFileSystemInfo.cs

@@ -1,13 +0,0 @@
-#pragma warning disable CS1591
-
-namespace Emby.Server.Implementations.IO
-{
-    public class ExtendedFileSystemInfo
-    {
-        public bool IsHidden { get; set; }
-
-        public bool IsReadOnly { get; set; }
-
-        public bool Exists { get; set; }
-    }
-}

+ 11 - 35
Emby.Server.Implementations/IO/ManagedFileSystem.cs

@@ -267,25 +267,6 @@ namespace Emby.Server.Implementations.IO
             return result;
             return result;
         }
         }
 
 
-        private static ExtendedFileSystemInfo GetExtendedFileSystemInfo(string path)
-        {
-            var result = new ExtendedFileSystemInfo();
-
-            var info = new FileInfo(path);
-
-            if (info.Exists)
-            {
-                result.Exists = true;
-
-                var attributes = info.Attributes;
-
-                result.IsHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
-                result.IsReadOnly = (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
-            }
-
-            return result;
-        }
-
         /// <summary>
         /// <summary>
         /// Takes a filename and removes invalid characters.
         /// Takes a filename and removes invalid characters.
         /// </summary>
         /// </summary>
@@ -403,19 +384,18 @@ namespace Emby.Server.Implementations.IO
                 return;
                 return;
             }
             }
 
 
-            var info = GetExtendedFileSystemInfo(path);
+            var info = new FileInfo(path);
 
 
-            if (info.Exists && info.IsHidden != isHidden)
+            if (info.Exists &&
+                ((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) != isHidden)
             {
             {
                 if (isHidden)
                 if (isHidden)
                 {
                 {
-                    File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
+                    File.SetAttributes(path, info.Attributes | FileAttributes.Hidden);
                 }
                 }
                 else
                 else
                 {
                 {
-                    var attributes = File.GetAttributes(path);
-                    attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
-                    File.SetAttributes(path, attributes);
+                    File.SetAttributes(path, info.Attributes & ~FileAttributes.Hidden);
                 }
                 }
             }
             }
         }
         }
@@ -428,19 +408,20 @@ namespace Emby.Server.Implementations.IO
                 return;
                 return;
             }
             }
 
 
-            var info = GetExtendedFileSystemInfo(path);
+            var info = new FileInfo(path);
 
 
             if (!info.Exists)
             if (!info.Exists)
             {
             {
                 return;
                 return;
             }
             }
 
 
-            if (info.IsReadOnly == readOnly && info.IsHidden == isHidden)
+            if (((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) == readOnly
+                && ((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) == isHidden)
             {
             {
                 return;
                 return;
             }
             }
 
 
-            var attributes = File.GetAttributes(path);
+            var attributes = info.Attributes;
 
 
             if (readOnly)
             if (readOnly)
             {
             {
@@ -448,7 +429,7 @@ namespace Emby.Server.Implementations.IO
             }
             }
             else
             else
             {
             {
-                attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
+                attributes &= ~FileAttributes.ReadOnly;
             }
             }
 
 
             if (isHidden)
             if (isHidden)
@@ -457,17 +438,12 @@ namespace Emby.Server.Implementations.IO
             }
             }
             else
             else
             {
             {
-                attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
+                attributes &= ~FileAttributes.Hidden;
             }
             }
 
 
             File.SetAttributes(path, attributes);
             File.SetAttributes(path, attributes);
         }
         }
 
 
-        private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
-        {
-            return attributes & ~attributesToRemove;
-        }
-
         /// <summary>
         /// <summary>
         /// Swaps the files.
         /// Swaps the files.
         /// </summary>
         /// </summary>