diff --git a/BDInfo/BDROM.cs b/BDInfo/BDROM.cs index 2faeb405e..d42e381da 100644 --- a/BDInfo/BDROM.cs +++ b/BDInfo/BDROM.cs @@ -135,13 +135,13 @@ namespace BDInfo { IsBDPlus = true; } - + if (DirectoryBDJO != null && _fileSystem.GetFiles(DirectoryBDJO.FullName).Any()) { IsBDJava = true; } - + if (DirectorySNP != null && GetFiles(DirectorySNP.FullName, ".mnv").Any()) { @@ -206,7 +206,7 @@ namespace BDInfo private IEnumerable GetFiles(string path, string extension) { - return _fileSystem.GetFiles(path).Where(i => string.Equals(i.Extension, extension, StringComparison.OrdinalIgnoreCase)); + return _fileSystem.GetFiles(path, new[] { extension }, false, false); } public void Scan() diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index 0c1c02cd5..ed940eca5 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -657,14 +657,41 @@ namespace Emby.Common.Implementations.IO { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return ToMetadata(path, new DirectoryInfo(path).EnumerateDirectories("*", searchOption)); + return ToMetadata(new DirectoryInfo(path).EnumerateDirectories("*", searchOption)); } public IEnumerable GetFiles(string path, bool recursive = false) + { + return GetFiles(path, null, true, recursive); + } + + public IEnumerable GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return ToMetadata(path, new DirectoryInfo(path).EnumerateFiles("*", 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 ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], searchOption)); + } + + var files = new DirectoryInfo(path).EnumerateFiles("*", searchOption); + + if (extensions != null && extensions.Length > 0) + { + files = files.Where(i => + { + var ext = i.Extension; + if (ext == null) + { + return false; + } + return extensions.Contains(ext, StringComparer.OrdinalIgnoreCase); + }); + } + + return ToMetadata(files); } public IEnumerable GetFileSystemEntries(string path, bool recursive = false) @@ -674,14 +701,14 @@ namespace Emby.Common.Implementations.IO if (EnableFileSystemRequestConcat) { - return ToMetadata(path, directoryInfo.EnumerateDirectories("*", searchOption)) - .Concat(ToMetadata(path, directoryInfo.EnumerateFiles("*", searchOption))); + return ToMetadata(directoryInfo.EnumerateDirectories("*", searchOption)) + .Concat(ToMetadata(directoryInfo.EnumerateFiles("*", searchOption))); } - return ToMetadata(path, directoryInfo.EnumerateFileSystemInfos("*", searchOption)); + return ToMetadata(directoryInfo.EnumerateFileSystemInfos("*", searchOption)); } - private IEnumerable ToMetadata(string parentPath, IEnumerable infos) + private IEnumerable ToMetadata(IEnumerable infos) { return infos.Select(GetFileSystemMetadata); } @@ -776,7 +803,7 @@ namespace Emby.Common.Implementations.IO public virtual void SetExecutable(string path) { - + } } } diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index 020038422..8f62e6d27 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -286,19 +286,12 @@ namespace Emby.Dlna { try { - var allFiles = _fileSystem.GetFiles(path) + var xmlFies = _fileSystem.GetFilePaths(path) + .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase)) .ToList(); - var xmlFies = allFiles - .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) - .ToList(); - - var parseFiles = new List(); - - parseFiles.AddRange(xmlFies); - - return parseFiles - .Select(i => ParseProfileFile(i.FullName, type)) + return xmlFies + .Select(i => ParseProfileFile(i, type)) .Where(i => i != null) .ToList(); } @@ -322,16 +315,9 @@ namespace Emby.Dlna { DeviceProfile profile; - if (string.Equals(Path.GetExtension(path), ".xml", StringComparison.OrdinalIgnoreCase)) - { - var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); + var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - profile = ReserializeProfile(tempProfile); - } - else - { - profile = (DeviceProfile)_jsonSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - } + profile = ReserializeProfile(tempProfile); profile.Id = path.ToLower().GetMD5().ToString("N"); profile.ProfileType = type; @@ -553,15 +539,13 @@ namespace Emby.Dlna class DlnaProfileEntryPoint : IServerEntryPoint { private readonly IApplicationPaths _appPaths; - private readonly IJsonSerializer _jsonSerializer; private readonly IFileSystem _fileSystem; private readonly IXmlSerializer _xmlSerializer; - public DlnaProfileEntryPoint(IApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer) + public DlnaProfileEntryPoint(IApplicationPaths appPaths, IFileSystem fileSystem, IXmlSerializer xmlSerializer) { _appPaths = appPaths; _fileSystem = fileSystem; - _jsonSerializer = jsonSerializer; _xmlSerializer = xmlSerializer; } diff --git a/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index 2850c3a61..b035fdcfd 100644 --- a/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/Emby.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -151,8 +151,7 @@ namespace Emby.Server.Implementations.FileOrganization /// The extensions. private void DeleteLeftOverFiles(string path, IEnumerable extensions) { - var eligibleFiles = _fileSystem.GetFiles(path, true) - .Where(i => extensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase)) + var eligibleFiles = _fileSystem.GetFiles(path, extensions.ToArray(), false, true) .ToList(); foreach (var file in eligibleFiles) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 026486efc..17e678615 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -448,7 +448,7 @@ namespace Emby.Server.Implementations.Library if (parent != null) { - await parent.ValidateChildren(new Progress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false) .ConfigureAwait(false); + await parent.ValidateChildren(new Progress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false).ConfigureAwait(false); } } else if (parent != null) @@ -941,7 +941,7 @@ namespace Emby.Server.Implementations.Library return CreateItemByName(MusicArtist.GetPath, name); } - private T CreateItemByName(Func getPathFn, string name) + private T CreateItemByName(Func getPathFn, string name) where T : BaseItem, new() { if (typeof(T) == typeof(MusicArtist)) @@ -1255,8 +1255,7 @@ namespace Emby.Server.Implementations.Library private string GetCollectionType(string path) { - return _fileSystem.GetFiles(path, false) - .Where(i => string.Equals(i.Extension, ".collection", StringComparison.OrdinalIgnoreCase)) + return _fileSystem.GetFiles(path, new[] { ".collection" }, true, false) .Select(i => _fileSystem.GetFileNameWithoutExtension(i)) .FirstOrDefault(); } @@ -2474,29 +2473,36 @@ namespace Emby.Server.Implementations.Library return GetNamingOptions(new LibraryOptions()); } + private NamingOptions _namingOptions; + private string[] _videoFileExtensions; public NamingOptions GetNamingOptions(LibraryOptions libraryOptions) { - var options = new ExtendedNamingOptions(); - - // These cause apps to have problems - options.AudioFileExtensions.Remove(".m3u"); - options.AudioFileExtensions.Remove(".wpl"); - - if (!libraryOptions.EnableArchiveMediaFiles) + if (_namingOptions == null) { - options.AudioFileExtensions.Remove(".rar"); - options.AudioFileExtensions.Remove(".zip"); + var options = new ExtendedNamingOptions(); + + // These cause apps to have problems + options.AudioFileExtensions.Remove(".m3u"); + options.AudioFileExtensions.Remove(".wpl"); + + //if (!libraryOptions.EnableArchiveMediaFiles) + { + options.AudioFileExtensions.Remove(".rar"); + options.AudioFileExtensions.Remove(".zip"); + } + + //if (!libraryOptions.EnableArchiveMediaFiles) + { + options.VideoFileExtensions.Remove(".rar"); + options.VideoFileExtensions.Remove(".zip"); + } + + options.VideoFileExtensions.Add(".tp"); + _namingOptions = options; + _videoFileExtensions = _namingOptions.VideoFileExtensions.ToArray(); } - if (!libraryOptions.EnableArchiveMediaFiles) - { - options.VideoFileExtensions.Remove(".rar"); - options.VideoFileExtensions.Remove(".zip"); - } - - options.VideoFileExtensions.Add(".tp"); - - return options; + return _namingOptions; } public ItemLookupInfo ParseName(string name) @@ -2515,12 +2521,14 @@ namespace Emby.Server.Implementations.Library public IEnumerable