Browse Source

add new file method overloads

Luke Pulverenti 8 years ago
parent
commit
7987e64d38

+ 8 - 3
BDInfo/BDROM.cs

@@ -137,19 +137,19 @@ namespace BDInfo
             }
             }
 
 
             if (DirectoryBDJO != null &&
             if (DirectoryBDJO != null &&
-                _fileSystem.GetFiles(DirectoryBDJO.FullName).Any())
+                _fileSystem.GetFilePaths(DirectoryBDJO.FullName).Any())
             {
             {
                 IsBDJava = true;
                 IsBDJava = true;
             }
             }
 
 
             if (DirectorySNP != null &&
             if (DirectorySNP != null &&
-                GetFiles(DirectorySNP.FullName, ".mnv").Any())
+                GetFilePaths(DirectorySNP.FullName, ".mnv").Any())
             {
             {
                 IsPSP = true;
                 IsPSP = true;
             }
             }
 
 
             if (DirectorySSIF != null &&
             if (DirectorySSIF != null &&
-                _fileSystem.GetFiles(DirectorySSIF.FullName).Any())
+                _fileSystem.GetFilePaths(DirectorySSIF.FullName).Any())
             {
             {
                 Is3D = true;
                 Is3D = true;
             }
             }
@@ -209,6 +209,11 @@ namespace BDInfo
             return _fileSystem.GetFiles(path, new[] { extension }, false, false);
             return _fileSystem.GetFiles(path, new[] { extension }, false, false);
         }
         }
 
 
+        private IEnumerable<string> GetFilePaths(string path, string extension)
+        {
+            return _fileSystem.GetFilePaths(path, new[] { extension }, false, false);
+        }
+
         public void Scan()
         public void Scan()
         {
         {
             List<TSStreamClipFile> errorStreamClipFiles = new List<TSStreamClipFile>();
             List<TSStreamClipFile> errorStreamClipFiles = new List<TSStreamClipFile>();

+ 30 - 2
Emby.Common.Implementations/IO/ManagedFileSystem.cs

@@ -662,7 +662,7 @@ namespace Emby.Common.Implementations.IO
 
 
         public IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
         public IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
         {
         {
-            return GetFiles(path, null, true, recursive);
+            return GetFiles(path, null, false, recursive);
         }
         }
 
 
         public IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
         public IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
@@ -790,9 +790,37 @@ namespace Emby.Common.Implementations.IO
         }
         }
 
 
         public IEnumerable<string> GetFilePaths(string path, bool recursive = false)
         public IEnumerable<string> GetFilePaths(string path, bool recursive = false)
+        {
+            return GetFilePaths(path, null, false, recursive);
+        }
+
+        public IEnumerable<string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
         {
         {
             var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
             var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
-            return Directory.EnumerateFiles(path, "*", searchOption);
+
+            // On linux and osx the search pattern is case sensitive
+            // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
+            if (enableCaseSensitiveExtensions && extensions != null && extensions.Length == 1)
+            {
+                return Directory.EnumerateFiles(path, "*" + extensions[0], searchOption);
+            }
+
+            var files = Directory.EnumerateFiles(path, "*", searchOption);
+
+            if (extensions != null && extensions.Length > 0)
+            {
+                files = files.Where(i =>
+                {
+                    var ext = Path.GetExtension(i);
+                    if (ext == null)
+                    {
+                        return false;
+                    }
+                    return extensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
+                });
+            }
+
+            return files;
         }
         }
 
 
         public IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false)
         public IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false)

+ 3 - 3
Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs

@@ -178,18 +178,18 @@ namespace Emby.Server.Implementations.FileOrganization
         /// <param name="extensions">The extensions.</param>
         /// <param name="extensions">The extensions.</param>
         private void DeleteLeftOverFiles(string path, IEnumerable<string> extensions)
         private void DeleteLeftOverFiles(string path, IEnumerable<string> extensions)
         {
         {
-            var eligibleFiles = _fileSystem.GetFiles(path, extensions.ToArray(), false, true)
+            var eligibleFiles = _fileSystem.GetFilePaths(path, extensions.ToArray(), false, true)
                 .ToList();
                 .ToList();
 
 
             foreach (var file in eligibleFiles)
             foreach (var file in eligibleFiles)
             {
             {
                 try
                 try
                 {
                 {
-                    _fileSystem.DeleteFile(file.FullName);
+                    _fileSystem.DeleteFile(file);
                 }
                 }
                 catch (Exception ex)
                 catch (Exception ex)
                 {
                 {
-                    _logger.ErrorException("Error deleting file {0}", ex, file.FullName);
+                    _logger.ErrorException("Error deleting file {0}", ex, file);
                 }
                 }
             }
             }
         }
         }

+ 2 - 2
Emby.Server.Implementations/Library/LibraryManager.cs

@@ -1255,9 +1255,9 @@ namespace Emby.Server.Implementations.Library
 
 
         private string GetCollectionType(string path)
         private string GetCollectionType(string path)
         {
         {
-            return _fileSystem.GetFiles(path, new[] { ".collection" }, true, false)
+            return _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false)
                 .Select(i => _fileSystem.GetFileNameWithoutExtension(i))
                 .Select(i => _fileSystem.GetFileNameWithoutExtension(i))
-                .FirstOrDefault();
+                .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 1 - 0
MediaBrowser.Model/IO/IFileSystem.cs

@@ -298,6 +298,7 @@ namespace MediaBrowser.Model.IO
         /// <param name="recursive">if set to <c>true</c> [recursive].</param>
         /// <param name="recursive">if set to <c>true</c> [recursive].</param>
         /// <returns>IEnumerable&lt;System.String&gt;.</returns>
         /// <returns>IEnumerable&lt;System.String&gt;.</returns>
         IEnumerable<string> GetFilePaths(string path, bool recursive = false);
         IEnumerable<string> GetFilePaths(string path, bool recursive = false);
+        IEnumerable<string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive);
 
 
         /// <summary>
         /// <summary>
         /// Gets the file system entry paths.
         /// Gets the file system entry paths.