diff options
14 files changed, 52 insertions, 140 deletions
diff --git a/MediaBrowser.Api/EnvironmentService.cs b/MediaBrowser.Api/EnvironmentService.cs index 9d11178c8..d88d85594 100644 --- a/MediaBrowser.Api/EnvironmentService.cs +++ b/MediaBrowser.Api/EnvironmentService.cs @@ -207,11 +207,6 @@ namespace MediaBrowser.Api { var entries = new DirectoryInfo(request.Path).EnumerateFileSystemInfos().Where(i => { - if (i.Attributes.HasFlag(FileAttributes.System)) - { - return false; - } - if (!request.IncludeHidden && i.Attributes.HasFlag(FileAttributes.Hidden)) { return false; diff --git a/MediaBrowser.Controller/Drawing/ImageExtensions.cs b/MediaBrowser.Controller/Drawing/ImageExtensions.cs index 79b877b94..847c5dbe0 100644 --- a/MediaBrowser.Controller/Drawing/ImageExtensions.cs +++ b/MediaBrowser.Controller/Drawing/ImageExtensions.cs @@ -73,23 +73,23 @@ namespace MediaBrowser.Controller.Drawing { // http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx - if (format.HasFlag(PixelFormat.Indexed)) + if (format == PixelFormat.Indexed) { return false; } - if (format.HasFlag(PixelFormat.Undefined)) + if (format == PixelFormat.Undefined) { return false; } - if (format.HasFlag(PixelFormat.DontCare)) + if (format == PixelFormat.DontCare) { return false; } - if (format.HasFlag(PixelFormat.Format16bppArgb1555)) + if (format == PixelFormat.Format16bppArgb1555) { return false; } - if (format.HasFlag(PixelFormat.Format16bppGrayScale)) + if (format == PixelFormat.Format16bppGrayScale) { return false; } @@ -160,7 +160,7 @@ namespace MediaBrowser.Controller.Drawing } // Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here - var thumbnail = bmp.PixelFormat.HasFlag(PixelFormat.Indexed) ? new Bitmap(croppedWidth, croppedHeight) : new Bitmap(croppedWidth, croppedHeight, bmp.PixelFormat); + var thumbnail = bmp.PixelFormat == PixelFormat.Indexed ? new Bitmap(croppedWidth, croppedHeight) : new Bitmap(croppedWidth, croppedHeight, bmp.PixelFormat); // Preserve the original resolution thumbnail.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution); diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 974b3f864..2852843ef 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -279,7 +279,7 @@ namespace MediaBrowser.Controller.Entities // Record the name of each file // Need to sort these because accoring to msdn docs, our i/o methods are not guaranteed in any order foreach (var file in ResolveArgs.FileSystemChildren - .Where(i => !i.Attributes.HasFlag(FileAttributes.System)) + .Where(i => (i.Attributes & FileAttributes.System) != FileAttributes.System) .OrderBy(f => f.Name)) { sb.Append(file.Name); @@ -363,12 +363,15 @@ namespace MediaBrowser.Controller.Entities return new ItemResolveArgs(ConfigurationManager.ApplicationPaths); } + var isDirectory = false; + if (UseParentPathToCreateResolveArgs) { path = System.IO.Path.GetDirectoryName(path); + isDirectory = true; } - pathInfo = pathInfo ?? FileSystem.GetFileSystemInfo(path); + pathInfo = pathInfo ?? (isDirectory ? new DirectoryInfo(path) : FileSystem.GetFileSystemInfo(path)); if (pathInfo == null || !pathInfo.Exists) { diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index 6d1e3e05a..8896d4fc1 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -35,7 +35,7 @@ namespace MediaBrowser.Controller.IO foreach (var entry in entries) { - var isDirectory = entry.Attributes.HasFlag(FileAttributes.Directory); + var isDirectory = (entry.Attributes & FileAttributes.Directory) == FileAttributes.Directory; if (resolveShortcuts && FileSystem.IsShortcut(entry.FullName)) { diff --git a/MediaBrowser.Controller/IO/NativeMethods.cs b/MediaBrowser.Controller/IO/NativeMethods.cs index 2f15f124d..5b9bf52a8 100644 --- a/MediaBrowser.Controller/IO/NativeMethods.cs +++ b/MediaBrowser.Controller/IO/NativeMethods.cs @@ -217,103 +217,6 @@ namespace MediaBrowser.Controller.IO public string cAlternate; /// <summary> - /// Gets a value indicating whether this instance is hidden. - /// </summary> - /// <value><c>true</c> if this instance is hidden; otherwise, <c>false</c>.</value> - public bool IsHidden - { - get - { - return dwFileAttributes.HasFlag(FileAttributes.Hidden); - } - } - - /// <summary> - /// Gets a value indicating whether this instance is system file. - /// </summary> - /// <value><c>true</c> if this instance is system file; otherwise, <c>false</c>.</value> - public bool IsSystemFile - { - get - { - return dwFileAttributes.HasFlag(FileAttributes.System); - } - } - - /// <summary> - /// Gets a value indicating whether this instance is directory. - /// </summary> - /// <value><c>true</c> if this instance is directory; otherwise, <c>false</c>.</value> - public bool IsDirectory - { - get - { - return dwFileAttributes.HasFlag(FileAttributes.Directory); - } - } - - /// <summary> - /// Gets the creation time UTC. - /// </summary> - /// <value>The creation time UTC.</value> - public DateTime CreationTimeUtc - { - get - { - return ParseFileTime(ftCreationTime); - } - } - - /// <summary> - /// Gets the last access time UTC. - /// </summary> - /// <value>The last access time UTC.</value> - public DateTime LastAccessTimeUtc - { - get - { - return ParseFileTime(ftLastAccessTime); - } - } - - /// <summary> - /// Gets the last write time UTC. - /// </summary> - /// <value>The last write time UTC.</value> - public DateTime LastWriteTimeUtc - { - get - { - return ParseFileTime(ftLastWriteTime); - } - } - - /// <summary> - /// Parses the file time. - /// </summary> - /// <param name="filetime">The filetime.</param> - /// <returns>DateTime.</returns> - private DateTime ParseFileTime(FILETIME filetime) - { - long highBits = filetime.dwHighDateTime; - highBits = highBits << 32; - - var val = highBits + (long) filetime.dwLowDateTime; - - if (val < 0L) - { - return DateTime.MinValue; - } - - if (val > 2650467743999999999L) - { - return DateTime.MaxValue; - } - - return DateTime.FromFileTimeUtc(val); - } - - /// <summary> /// Gets or sets the path. /// </summary> /// <value>The path.</value> diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index dd2afcb3f..7e84350b3 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -26,12 +26,11 @@ namespace MediaBrowser.Controller.Library /// <summary> /// Resolves a path into a BaseItem /// </summary> - /// <param name="path">The path.</param> - /// <param name="parent">The parent.</param> /// <param name="fileInfo">The file info.</param> + /// <param name="parent">The parent.</param> /// <returns>BaseItem.</returns> /// <exception cref="System.ArgumentNullException"></exception> - BaseItem ResolvePath(string path, Folder parent = null, FileSystemInfo fileInfo = null); + BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null); /// <summary> /// Resolves a set of files into a list of BaseItem diff --git a/MediaBrowser.Controller/Library/ItemResolveArgs.cs b/MediaBrowser.Controller/Library/ItemResolveArgs.cs index 0ddf61f19..9ca2b6ad5 100644 --- a/MediaBrowser.Controller/Library/ItemResolveArgs.cs +++ b/MediaBrowser.Controller/Library/ItemResolveArgs.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Controller.Library { get { - return FileInfo.Attributes.HasFlag(FileAttributes.Directory); + return (FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory; } } @@ -80,7 +80,7 @@ namespace MediaBrowser.Controller.Library { get { - return FileInfo.Attributes.HasFlag(FileAttributes.Hidden); + return (FileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden; } } @@ -92,7 +92,7 @@ namespace MediaBrowser.Controller.Library { get { - return FileInfo.Attributes.HasFlag(FileAttributes.System); + return (FileInfo.Attributes & FileAttributes.System) == FileAttributes.System; } } @@ -213,7 +213,7 @@ namespace MediaBrowser.Controller.Library /// <exception cref="System.IO.FileNotFoundException"></exception> public void AddMetadataFile(string path) { - var file = FileSystem.GetFileSystemInfo(path); + var file = new FileInfo(path); if (!file.Exists) { diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs index 046dd7698..921bbb808 100644 --- a/MediaBrowser.Controller/Library/TVUtils.cs +++ b/MediaBrowser.Controller/Library/TVUtils.cs @@ -197,12 +197,17 @@ namespace MediaBrowser.Controller.Library { var attributes = child.Attributes; - if (attributes.HasFlag(FileAttributes.Hidden) || attributes.HasFlag(FileAttributes.System)) + if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } - if (attributes.HasFlag(FileAttributes.Directory)) + if ((attributes & FileAttributes.System) == FileAttributes.System) + { + continue; + } + + if ((attributes & FileAttributes.Directory) == FileAttributes.Directory) { if (IsSeasonFolder(child.FullName)) { diff --git a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs index 9c76680c7..c54659453 100644 --- a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs +++ b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs @@ -96,7 +96,7 @@ namespace MediaBrowser.Controller.Resolvers } // See if a different path came out of the resolver than what went in - if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase)) { var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null; diff --git a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs index 612dc0d42..ebb79e96b 100644 --- a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs +++ b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs @@ -47,20 +47,30 @@ namespace MediaBrowser.Server.Implementations.Library { var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path)); - if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase) || string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase)) { return false; } // Drives will sometimes be hidden - if (args.Path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase)) + if (args.Path.EndsWith(Path.VolumeSeparatorChar + "\\", StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + // Shares will sometimes be hidden + if (args.Path.StartsWith("\\", StringComparison.OrdinalIgnoreCase)) { - if (new DriveInfo(args.Path).IsReady) + // Look for a share, e.g. \\server\movies + // Is there a better way to detect if a path is a share without using native code? + if (args.Path.Substring(2).Split(Path.DirectorySeparatorChar).Length == 2) { return false; } - - _logger.Error("Operating system reports drive is not ready: {0}", args.Path); } return true; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index fb05c8c43..bc122ff6d 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -446,24 +446,21 @@ namespace MediaBrowser.Server.Implementations.Library /// <summary> /// Resolves a path into a BaseItem /// </summary> - /// <param name="path">The path.</param> - /// <param name="parent">The parent.</param> /// <param name="fileInfo">The file info.</param> + /// <param name="parent">The parent.</param> /// <returns>BaseItem.</returns> /// <exception cref="System.ArgumentNullException"></exception> - public BaseItem ResolvePath(string path, Folder parent = null, FileSystemInfo fileInfo = null) + public BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null) { - if (string.IsNullOrEmpty(path)) + if (fileInfo == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("fileInfo"); } - fileInfo = fileInfo ?? FileSystem.GetFileSystemInfo(path); - var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths) { Parent = parent, - Path = path, + Path = fileInfo.FullName, FileInfo = fileInfo }; @@ -534,7 +531,7 @@ namespace MediaBrowser.Server.Implementations.Library { try { - var item = ResolvePath(f.FullName, parent, f) as T; + var item = ResolvePath(f, parent) as T; if (item != null) { @@ -567,7 +564,7 @@ namespace MediaBrowser.Server.Implementations.Library Directory.CreateDirectory(rootFolderPath); } - var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(rootFolderPath); + var rootFolder = RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(new DirectoryInfo(rootFolderPath)); // Add in the plug-in folders foreach (var child in PluginFolderCreators) @@ -585,7 +582,7 @@ namespace MediaBrowser.Server.Implementations.Library /// <returns>UserRootFolder.</returns> public UserRootFolder GetUserRootFolder(string userRootPath) { - return _userRootFolders.GetOrAdd(userRootPath, key => RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ?? (UserRootFolder)ResolvePath(userRootPath)); + return _userRootFolders.GetOrAdd(userRootPath, key => RetrieveItem(userRootPath.GetMBId(typeof(UserRootFolder))) as UserRootFolder ?? (UserRootFolder)ResolvePath(new DirectoryInfo(userRootPath))); } /// <summary> diff --git a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs index ef303008d..5a4e27108 100644 --- a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs +++ b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs @@ -56,7 +56,7 @@ namespace MediaBrowser.Server.Implementations.Library if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path)) { //we use our resolve args name here to get the name of the containg folder, not actual video file - item.Name = GetMBName(item.ResolveArgs.FileInfo.Name, item.ResolveArgs.FileInfo.Attributes.HasFlag(FileAttributes.Directory)); + item.Name = GetMBName(item.ResolveArgs.FileInfo.Name, (item.ResolveArgs.FileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory); } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index 60a262fab..fa34a6a2e 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -40,7 +40,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio } // If we contain an album assume we are an artist folder - return args.FileSystemChildren.Where(i => i.Attributes.HasFlag(FileAttributes.Directory)).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName)) ? new MusicArtist() : null; + return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName)) ? new MusicArtist() : null; } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index f54c78f35..a21c15f4f 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -135,7 +135,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies // Loop through each child file/folder and see if we find a video foreach (var child in args.FileSystemChildren) { - if (child.Attributes.HasFlag(FileAttributes.Directory)) + if ((child.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { if (IsDvdDirectory(child.Name)) { |
