2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2012-08-20 23:53:32 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2012-08-21 01:51:00 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Events
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is an EventArgs object used when resolving a Path into a BaseItem
|
|
|
|
|
/// </summary>
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public class ItemResolveEventArgs : PreBeginResolveEventArgs
|
|
|
|
|
{
|
2012-08-21 01:21:03 +00:00
|
|
|
|
public KeyValuePair<string, WIN32_FIND_DATA>[] FileSystemChildren { get; set; }
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-08-20 23:53:32 +00:00
|
|
|
|
public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntry(string path, bool? isFolder)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
for (int i = 0; i < FileSystemChildren.Length; i++)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
KeyValuePair<string, WIN32_FIND_DATA> entry = FileSystemChildren[i];
|
|
|
|
|
|
2012-08-20 23:53:32 +00:00
|
|
|
|
if (isFolder.HasValue)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
if (isFolder.Value && !entry.Value.IsDirectory)
|
2012-08-20 23:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-08-21 01:51:00 +00:00
|
|
|
|
else if (!isFolder.Value && entry.Value.IsDirectory)
|
2012-08-20 23:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 23:53:32 +00:00
|
|
|
|
if (entry.Key.Equals(path, StringComparison.OrdinalIgnoreCase))
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2012-08-20 23:53:32 +00:00
|
|
|
|
|
|
|
|
|
public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntryByName(string name, bool? isFolder)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
for (int i = 0; i < FileSystemChildren.Length; i++)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
KeyValuePair<string, WIN32_FIND_DATA> entry = FileSystemChildren[i];
|
|
|
|
|
|
2012-08-20 23:53:32 +00:00
|
|
|
|
if (isFolder.HasValue)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
if (isFolder.Value && !entry.Value.IsDirectory)
|
2012-08-20 23:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-08-21 01:51:00 +00:00
|
|
|
|
else if (!isFolder.Value && entry.Value.IsDirectory)
|
2012-08-20 23:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ContainsFile(string name)
|
|
|
|
|
{
|
2012-08-20 23:53:32 +00:00
|
|
|
|
return GetFileSystemEntryByName(name, false) != null;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ContainsFolder(string name)
|
|
|
|
|
{
|
2012-08-20 23:53:32 +00:00
|
|
|
|
return GetFileSystemEntryByName(name, true) != null;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is an EventArgs object used before we begin resolving a Path into a BaseItem
|
|
|
|
|
/// File system children have not been collected yet, but consuming events will
|
|
|
|
|
/// have a chance to cancel resolution based on the Path, Parent and FileAttributes
|
|
|
|
|
/// </summary>
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public class PreBeginResolveEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
public string Path { get; set; }
|
2012-07-13 03:50:50 +00:00
|
|
|
|
public Folder Parent { get; set; }
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
public bool Cancel { get; set; }
|
|
|
|
|
|
2012-08-20 23:53:32 +00:00
|
|
|
|
public FileAttributes FileAttributes { get { return FileData.dwFileAttributes; } }
|
|
|
|
|
public WIN32_FIND_DATA FileData { get; set; }
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
public bool IsFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return FileAttributes.HasFlag(FileAttributes.Directory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsHidden
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return FileAttributes.HasFlag(FileAttributes.Hidden);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsSystemFile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return FileAttributes.HasFlag(FileAttributes.System);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-18 19:38:27 +00:00
|
|
|
|
public VirtualFolder VirtualFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Parent != null)
|
|
|
|
|
{
|
|
|
|
|
return Parent.VirtualFolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string VirtualFolderCollectionType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
VirtualFolder vf = VirtualFolder;
|
|
|
|
|
|
|
|
|
|
if (vf == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return vf.CollectionType;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|