2012-07-11 23:55:27 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2012-07-19 19:22:44 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-07-11 23:55:27 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Events
|
|
|
|
|
{
|
2012-07-19 19:22:44 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is an EventArgs object used when resolving a Path into a BaseItem
|
|
|
|
|
/// </summary>
|
2012-07-11 23:55:27 -07:00
|
|
|
|
public class ItemResolveEventArgs : PreBeginResolveEventArgs
|
|
|
|
|
{
|
|
|
|
|
public IEnumerable<KeyValuePair<string, FileAttributes>> FileSystemChildren { get; set; }
|
|
|
|
|
|
|
|
|
|
public KeyValuePair<string, FileAttributes>? GetFolderByName(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<string, FileAttributes> entry in FileSystemChildren)
|
|
|
|
|
{
|
|
|
|
|
if (!entry.Value.HasFlag(FileAttributes.Directory))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public KeyValuePair<string, FileAttributes>? GetFileByName(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<string, FileAttributes> entry in FileSystemChildren)
|
|
|
|
|
{
|
|
|
|
|
if (entry.Value.HasFlag(FileAttributes.Directory))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ContainsFile(string name)
|
|
|
|
|
{
|
|
|
|
|
return GetFileByName(name) != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ContainsFolder(string name)
|
|
|
|
|
{
|
|
|
|
|
return GetFolderByName(name) != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-19 19:22:44 -07: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-11 23:55:27 -07:00
|
|
|
|
public class PreBeginResolveEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
public string Path { get; set; }
|
2012-07-12 20:50:50 -07:00
|
|
|
|
public Folder Parent { get; set; }
|
2012-07-11 23:55:27 -07:00
|
|
|
|
|
|
|
|
|
public bool Cancel { get; set; }
|
|
|
|
|
|
|
|
|
|
public FileAttributes FileAttributes { get; set; }
|
|
|
|
|
|
|
|
|
|
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 12:38:27 -07: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-11 23:55:27 -07:00
|
|
|
|
}
|
|
|
|
|
}
|