Tweaked disk access a little bit more

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti 2012-08-21 10:42:40 -04:00
parent 9029d939f3
commit 76d365fcf9
15 changed files with 44 additions and 41 deletions

View File

@ -84,35 +84,25 @@ namespace MediaBrowser.Controller.Events
/// </summary> /// </summary>
public class PreBeginResolveEventArgs : EventArgs public class PreBeginResolveEventArgs : EventArgs
{ {
public string Path { get; set; }
public Folder Parent { get; set; } public Folder Parent { get; set; }
public bool Cancel { get; set; } public bool Cancel { get; set; }
public FileAttributes FileAttributes { get { return FileData.dwFileAttributes; } } public LazyFileInfo File { get; set; }
public WIN32_FIND_DATA FileData { get; set; }
public bool IsFolder public string Path
{ {
get get
{ {
return FileAttributes.HasFlag(FileAttributes.Directory); return File.Path;
} }
} }
public bool IsHidden public bool IsDirectory
{ {
get get
{ {
return FileAttributes.HasFlag(FileAttributes.Hidden); return File.FileInfo.dwFileAttributes.HasFlag(FileAttributes.Directory);
}
}
public bool IsSystemFile
{
get
{
return FileAttributes.HasFlag(FileAttributes.System);
} }
} }

View File

@ -53,6 +53,22 @@ namespace MediaBrowser.Controller.IO
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = FileData.MAX_ALTERNATE)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FileData.MAX_ALTERNATE)]
public string cAlternate; public string cAlternate;
public bool IsHidden
{
get
{
return dwFileAttributes.HasFlag(FileAttributes.Hidden);
}
}
public bool IsSystemFile
{
get
{
return dwFileAttributes.HasFlag(FileAttributes.System);
}
}
public bool IsDirectory public bool IsDirectory
{ {
get get

View File

@ -110,7 +110,7 @@ namespace MediaBrowser.Controller
/// </summary> /// </summary>
void ItemController_PreBeginResolvePath(object sender, PreBeginResolveEventArgs e) 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 // Ignore hidden files and folders
e.Cancel = true; e.Cancel = true;
@ -129,13 +129,10 @@ namespace MediaBrowser.Controller
/// </summary> /// </summary>
void ItemController_BeginResolvePath(object sender, ItemResolveEventArgs e) 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;
}
} }
} }

View File

@ -23,9 +23,8 @@ namespace MediaBrowser.Controller.Library
{ {
PreBeginResolveEventArgs args = new PreBeginResolveEventArgs() PreBeginResolveEventArgs args = new PreBeginResolveEventArgs()
{ {
Path = path,
Parent = parent, Parent = parent,
FileData = fileData, File = new LazyFileInfo() { Path = path, FileInfo = fileData },
Cancel = false Cancel = false
}; };
@ -101,9 +100,8 @@ namespace MediaBrowser.Controller.Library
ItemResolveEventArgs args = new ItemResolveEventArgs() ItemResolveEventArgs args = new ItemResolveEventArgs()
{ {
Path = path, File = new LazyFileInfo() { Path = path, FileInfo = fileData },
FileSystemChildren = fileSystemChildren, FileSystemChildren = fileSystemChildren,
FileData = fileData,
Parent = parent, Parent = parent,
Cancel = false Cancel = false
}; };
@ -296,8 +294,7 @@ namespace MediaBrowser.Controller.Library
item.DateModified = Directory.GetLastAccessTime(path); item.DateModified = Directory.GetLastAccessTime(path);
ItemResolveEventArgs args = new ItemResolveEventArgs(); ItemResolveEventArgs args = new ItemResolveEventArgs();
args.Path = path; args.File = new LazyFileInfo() { Path = path };
args.FileData = FileData.GetFileData(path);
args.FileSystemChildren = ConvertFileSystemEntries(Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly)); args.FileSystemChildren = ConvertFileSystemEntries(Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly));
await Kernel.Instance.ExecuteMetadataProviders(item, args).ConfigureAwait(false); await Kernel.Instance.ExecuteMetadataProviders(item, args).ConfigureAwait(false);

View File

@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.Providers
{ {
return Task.Run(() => return Task.Run(() =>
{ {
if (args.IsFolder) if (args.IsDirectory)
{ {
var baseItem = item as BaseItem; var baseItem = item as BaseItem;

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Resolvers
{ {
// Return audio if the path is a file and has a matching extension // Return audio if the path is a file and has a matching extension
if (!args.IsFolder) if (!args.IsDirectory)
{ {
if (IsAudioFile(args.Path)) if (IsAudioFile(args.Path))
{ {

View File

@ -81,7 +81,7 @@ namespace MediaBrowser.Controller.Resolvers
return; 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 // See if a different path came out of the resolver than what went in
if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase)) if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase))
@ -97,6 +97,10 @@ namespace MediaBrowser.Controller.Resolvers
fileData = FileData.GetFileData(item.Path); fileData = FileData.GetFileData(item.Path);
} }
} }
else
{
fileData = args.File.FileInfo;
}
item.DateCreated = fileData.CreationTime; item.DateCreated = fileData.CreationTime;

View File

@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Resolvers
protected override Folder Resolve(ItemResolveEventArgs args) protected override Folder Resolve(ItemResolveEventArgs args)
{ {
if (args.IsFolder) if (args.IsDirectory)
{ {
return new Folder(); return new Folder();
} }

View File

@ -26,7 +26,7 @@ namespace MediaBrowser.Controller.Resolvers
protected override T Resolve(ItemResolveEventArgs args) protected override T Resolve(ItemResolveEventArgs args)
{ {
// If the path is a file check for a matching extensions // If the path is a file check for a matching extensions
if (!args.IsFolder) if (!args.IsDirectory)
{ {
if (IsVideoFile(args.Path)) if (IsVideoFile(args.Path))
{ {

View File

@ -15,7 +15,7 @@ namespace MediaBrowser.Controller.Resolvers
protected override VirtualFolder Resolve(ItemResolveEventArgs args) 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(); return new VirtualFolder();
} }

View File

@ -12,7 +12,7 @@ namespace MediaBrowser.Movies.Resolvers
{ {
protected override BoxSet Resolve(ItemResolveEventArgs args) 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) if (Path.GetFileName(args.Path).IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1)
{ {

View File

@ -16,7 +16,7 @@ namespace MediaBrowser.Movies.Resolvers
{ {
protected override Movie Resolve(ItemResolveEventArgs args) 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"); var metadataFile = args.GetFileSystemEntryByName("movie.xml");
@ -52,8 +52,7 @@ namespace MediaBrowser.Movies.Resolvers
ItemResolveEventArgs childArgs = new ItemResolveEventArgs() ItemResolveEventArgs childArgs = new ItemResolveEventArgs()
{ {
Path = child.Path, File = child,
FileData = child.FileInfo,
FileSystemChildren = new LazyFileInfo[] { } FileSystemChildren = new LazyFileInfo[] { }
}; };

View File

@ -28,7 +28,7 @@ namespace MediaBrowser.TV
void ItemController_PreBeginResolvePath(object sender, PreBeginResolveEventArgs e) 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) if (e.Parent is Season || e.Parent is Series)
{ {

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.TV.Resolvers
{ {
protected override Season Resolve(ItemResolveEventArgs args) protected override Season Resolve(ItemResolveEventArgs args)
{ {
if (args.IsFolder && args.Parent is Series) if (args.Parent is Series && args.IsDirectory)
{ {
Season season = new Season(); Season season = new Season();

View File

@ -12,7 +12,7 @@ namespace MediaBrowser.TV.Resolvers
{ {
protected override Series Resolve(ItemResolveEventArgs args) 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 // Optimization to avoid running these tests against Seasons
if (args.Parent is Series) if (args.Parent is Series)