From 76d365fcf902665f56df7a1c85263a1368a33a2e Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 21 Aug 2012 10:42:40 -0400 Subject: [PATCH] Tweaked disk access a little bit more --- .../Events/ItemResolveEventArgs.cs | 20 +++++-------------- MediaBrowser.Controller/IO/FileData.cs | 16 +++++++++++++++ MediaBrowser.Controller/Kernel.cs | 11 ++++------ .../Library/ItemController.cs | 9 +++------ .../ImageFromMediaLocationProvider.cs | 2 +- .../Resolvers/AudioResolver.cs | 2 +- .../Resolvers/BaseItemResolver.cs | 6 +++++- .../Resolvers/FolderResolver.cs | 2 +- .../Resolvers/VideoResolver.cs | 2 +- .../Resolvers/VirtualFolderResolver.cs | 2 +- .../Resolvers/BoxSetResolver.cs | 2 +- .../Resolvers/MovieResolver.cs | 5 ++--- MediaBrowser.TV/Plugin.cs | 2 +- MediaBrowser.TV/Resolvers/SeasonResolver.cs | 2 +- MediaBrowser.TV/Resolvers/SeriesResolver.cs | 2 +- 15 files changed, 44 insertions(+), 41 deletions(-) diff --git a/MediaBrowser.Controller/Events/ItemResolveEventArgs.cs b/MediaBrowser.Controller/Events/ItemResolveEventArgs.cs index 18df73b51..72eebc5f6 100644 --- a/MediaBrowser.Controller/Events/ItemResolveEventArgs.cs +++ b/MediaBrowser.Controller/Events/ItemResolveEventArgs.cs @@ -84,35 +84,25 @@ namespace MediaBrowser.Controller.Events /// public class PreBeginResolveEventArgs : EventArgs { - public string Path { get; set; } public Folder Parent { get; set; } public bool Cancel { get; set; } - public FileAttributes FileAttributes { get { return FileData.dwFileAttributes; } } - public WIN32_FIND_DATA FileData { get; set; } + public LazyFileInfo File { get; set; } - public bool IsFolder + public string Path { get { - return FileAttributes.HasFlag(FileAttributes.Directory); + return File.Path; } } - public bool IsHidden + public bool IsDirectory { get { - return FileAttributes.HasFlag(FileAttributes.Hidden); - } - } - - public bool IsSystemFile - { - get - { - return FileAttributes.HasFlag(FileAttributes.System); + return File.FileInfo.dwFileAttributes.HasFlag(FileAttributes.Directory); } } diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index 92b4a6986..98332c794 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -53,6 +53,22 @@ namespace MediaBrowser.Controller.IO [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FileData.MAX_ALTERNATE)] public string cAlternate; + public bool IsHidden + { + get + { + return dwFileAttributes.HasFlag(FileAttributes.Hidden); + } + } + + public bool IsSystemFile + { + get + { + return dwFileAttributes.HasFlag(FileAttributes.System); + } + } + public bool IsDirectory { get diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 440457161..3ee9505c6 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -110,7 +110,7 @@ namespace MediaBrowser.Controller /// void ItemController_PreBeginResolvePath(object sender, PreBeginResolveEventArgs e) { - if (e.IsHidden || e.IsSystemFile) + if (e.File.FileInfo.IsHidden || e.File.FileInfo.IsSystemFile) { // Ignore hidden files and folders e.Cancel = true; @@ -129,13 +129,10 @@ namespace MediaBrowser.Controller /// void ItemController_BeginResolvePath(object sender, ItemResolveEventArgs e) { - if (e.IsFolder) + if (e.ContainsFile(".ignore")) { - if (e.ContainsFile(".ignore")) - { - // Ignore any folders containing a file called .ignore - e.Cancel = true; - } + // Ignore any folders containing a file called .ignore + e.Cancel = true; } } diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs index e99fa94a0..9fd77fb0d 100644 --- a/MediaBrowser.Controller/Library/ItemController.cs +++ b/MediaBrowser.Controller/Library/ItemController.cs @@ -23,9 +23,8 @@ namespace MediaBrowser.Controller.Library { PreBeginResolveEventArgs args = new PreBeginResolveEventArgs() { - Path = path, Parent = parent, - FileData = fileData, + File = new LazyFileInfo() { Path = path, FileInfo = fileData }, Cancel = false }; @@ -101,9 +100,8 @@ namespace MediaBrowser.Controller.Library ItemResolveEventArgs args = new ItemResolveEventArgs() { - Path = path, + File = new LazyFileInfo() { Path = path, FileInfo = fileData }, FileSystemChildren = fileSystemChildren, - FileData = fileData, Parent = parent, Cancel = false }; @@ -296,8 +294,7 @@ namespace MediaBrowser.Controller.Library item.DateModified = Directory.GetLastAccessTime(path); ItemResolveEventArgs args = new ItemResolveEventArgs(); - args.Path = path; - args.FileData = FileData.GetFileData(path); + args.File = new LazyFileInfo() { Path = path }; args.FileSystemChildren = ConvertFileSystemEntries(Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly)); await Kernel.Instance.ExecuteMetadataProviders(item, args).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs index 8e5364893..2a5e0394c 100644 --- a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs @@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.Providers { return Task.Run(() => { - if (args.IsFolder) + if (args.IsDirectory) { var baseItem = item as BaseItem; diff --git a/MediaBrowser.Controller/Resolvers/AudioResolver.cs b/MediaBrowser.Controller/Resolvers/AudioResolver.cs index 11f8729b4..26b4da310 100644 --- a/MediaBrowser.Controller/Resolvers/AudioResolver.cs +++ b/MediaBrowser.Controller/Resolvers/AudioResolver.cs @@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Resolvers { // Return audio if the path is a file and has a matching extension - if (!args.IsFolder) + if (!args.IsDirectory) { if (IsAudioFile(args.Path)) { diff --git a/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs b/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs index e91f5a6e8..8b27d4d2e 100644 --- a/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs +++ b/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs @@ -81,7 +81,7 @@ namespace MediaBrowser.Controller.Resolvers return; } - WIN32_FIND_DATA fileData = args.FileData; + WIN32_FIND_DATA fileData; // See if a different path came out of the resolver than what went in if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase)) @@ -97,6 +97,10 @@ namespace MediaBrowser.Controller.Resolvers fileData = FileData.GetFileData(item.Path); } } + else + { + fileData = args.File.FileInfo; + } item.DateCreated = fileData.CreationTime; diff --git a/MediaBrowser.Controller/Resolvers/FolderResolver.cs b/MediaBrowser.Controller/Resolvers/FolderResolver.cs index 27944dab2..62fe2f6fb 100644 --- a/MediaBrowser.Controller/Resolvers/FolderResolver.cs +++ b/MediaBrowser.Controller/Resolvers/FolderResolver.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Resolvers protected override Folder Resolve(ItemResolveEventArgs args) { - if (args.IsFolder) + if (args.IsDirectory) { return new Folder(); } diff --git a/MediaBrowser.Controller/Resolvers/VideoResolver.cs b/MediaBrowser.Controller/Resolvers/VideoResolver.cs index bd676cb87..8192fa99b 100644 --- a/MediaBrowser.Controller/Resolvers/VideoResolver.cs +++ b/MediaBrowser.Controller/Resolvers/VideoResolver.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Controller.Resolvers protected override T Resolve(ItemResolveEventArgs args) { // If the path is a file check for a matching extensions - if (!args.IsFolder) + if (!args.IsDirectory) { if (IsVideoFile(args.Path)) { diff --git a/MediaBrowser.Controller/Resolvers/VirtualFolderResolver.cs b/MediaBrowser.Controller/Resolvers/VirtualFolderResolver.cs index 15bf943c2..19bf66f29 100644 --- a/MediaBrowser.Controller/Resolvers/VirtualFolderResolver.cs +++ b/MediaBrowser.Controller/Resolvers/VirtualFolderResolver.cs @@ -15,7 +15,7 @@ namespace MediaBrowser.Controller.Resolvers protected override VirtualFolder Resolve(ItemResolveEventArgs args) { - if (args.IsFolder && args.Parent != null && args.Parent.IsRoot) + if (args.IsDirectory && args.Parent != null && args.Parent.IsRoot) { return new VirtualFolder(); } diff --git a/MediaBrowser.Movies/Resolvers/BoxSetResolver.cs b/MediaBrowser.Movies/Resolvers/BoxSetResolver.cs index 8120c979c..79d30e866 100644 --- a/MediaBrowser.Movies/Resolvers/BoxSetResolver.cs +++ b/MediaBrowser.Movies/Resolvers/BoxSetResolver.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.Movies.Resolvers { protected override BoxSet Resolve(ItemResolveEventArgs args) { - if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase)) + if ((args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase) && args.IsDirectory) { if (Path.GetFileName(args.Path).IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1) { diff --git a/MediaBrowser.Movies/Resolvers/MovieResolver.cs b/MediaBrowser.Movies/Resolvers/MovieResolver.cs index 8b2d10d0d..5c2402d49 100644 --- a/MediaBrowser.Movies/Resolvers/MovieResolver.cs +++ b/MediaBrowser.Movies/Resolvers/MovieResolver.cs @@ -16,7 +16,7 @@ namespace MediaBrowser.Movies.Resolvers { protected override Movie Resolve(ItemResolveEventArgs args) { - if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase)) + if ((args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase) && args.IsDirectory) { var metadataFile = args.GetFileSystemEntryByName("movie.xml"); @@ -52,8 +52,7 @@ namespace MediaBrowser.Movies.Resolvers ItemResolveEventArgs childArgs = new ItemResolveEventArgs() { - Path = child.Path, - FileData = child.FileInfo, + File = child, FileSystemChildren = new LazyFileInfo[] { } }; diff --git a/MediaBrowser.TV/Plugin.cs b/MediaBrowser.TV/Plugin.cs index bf03b473d..ab73f2c04 100644 --- a/MediaBrowser.TV/Plugin.cs +++ b/MediaBrowser.TV/Plugin.cs @@ -28,7 +28,7 @@ namespace MediaBrowser.TV void ItemController_PreBeginResolvePath(object sender, PreBeginResolveEventArgs e) { - if (e.IsFolder && System.IO.Path.GetFileName(e.Path).Equals("metadata", StringComparison.OrdinalIgnoreCase)) + if (System.IO.Path.GetFileName(e.Path).Equals("metadata", StringComparison.OrdinalIgnoreCase) && e.IsDirectory) { if (e.Parent is Season || e.Parent is Series) { diff --git a/MediaBrowser.TV/Resolvers/SeasonResolver.cs b/MediaBrowser.TV/Resolvers/SeasonResolver.cs index 85c880a3a..74424e8c2 100644 --- a/MediaBrowser.TV/Resolvers/SeasonResolver.cs +++ b/MediaBrowser.TV/Resolvers/SeasonResolver.cs @@ -11,7 +11,7 @@ namespace MediaBrowser.TV.Resolvers { protected override Season Resolve(ItemResolveEventArgs args) { - if (args.IsFolder && args.Parent is Series) + if (args.Parent is Series && args.IsDirectory) { Season season = new Season(); diff --git a/MediaBrowser.TV/Resolvers/SeriesResolver.cs b/MediaBrowser.TV/Resolvers/SeriesResolver.cs index 5fbee6ff8..b710991cc 100644 --- a/MediaBrowser.TV/Resolvers/SeriesResolver.cs +++ b/MediaBrowser.TV/Resolvers/SeriesResolver.cs @@ -12,7 +12,7 @@ namespace MediaBrowser.TV.Resolvers { protected override Series Resolve(ItemResolveEventArgs args) { - if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("TV", StringComparison.OrdinalIgnoreCase)) + if (args.IsDirectory && (args.VirtualFolderCollectionType ?? string.Empty).Equals("TV", StringComparison.OrdinalIgnoreCase)) { // Optimization to avoid running these tests against Seasons if (args.Parent is Series)