2013-02-23 10:54:51 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-02-12 22:11:54 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2015-10-03 21:23:11 -07:00
|
|
|
|
using CommonIO;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Library
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// These are arguments relating to the file system that are collected once and then referred to
|
|
|
|
|
/// whenever needed. Primarily for entity resolution.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ItemResolveArgs : EventArgs
|
|
|
|
|
{
|
2013-03-03 22:43:06 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _app paths
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IServerApplicationPaths _appPaths;
|
|
|
|
|
|
2014-02-12 22:11:54 -07:00
|
|
|
|
public IDirectoryService DirectoryService { get; private set; }
|
|
|
|
|
|
2013-03-03 22:43:06 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ItemResolveArgs" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="appPaths">The app paths.</param>
|
2015-01-27 15:45:59 -07:00
|
|
|
|
/// <param name="directoryService">The directory service.</param>
|
|
|
|
|
public ItemResolveArgs(IServerApplicationPaths appPaths, IDirectoryService directoryService)
|
2013-03-03 22:43:06 -07:00
|
|
|
|
{
|
|
|
|
|
_appPaths = appPaths;
|
2014-02-12 22:11:54 -07:00
|
|
|
|
DirectoryService = directoryService;
|
2013-03-03 22:43:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the file system children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The file system children.</value>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
public IEnumerable<FileSystemMetadata> FileSystemChildren
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2014-01-14 08:50:39 -07:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var dict = FileSystemDictionary;
|
|
|
|
|
|
|
|
|
|
if (dict == null)
|
|
|
|
|
{
|
2015-10-03 20:38:46 -07:00
|
|
|
|
return new List<FileSystemMetadata>();
|
2014-01-14 08:50:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dict.Values;
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the file system dictionary.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The file system dictionary.</value>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
public Dictionary<string, FileSystemMetadata> FileSystemDictionary { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the parent.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The parent.</value>
|
|
|
|
|
public Folder Parent { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the file info.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The file info.</value>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
public FileSystemMetadata FileInfo { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The path.</value>
|
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
|
{
|
2015-11-12 13:51:39 -07:00
|
|
|
|
return FileInfo.IsDirectory;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
|
{
|
2013-06-11 13:35:54 -07:00
|
|
|
|
return (FileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether this instance is vf.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance is vf; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool IsVf
|
|
|
|
|
{
|
|
|
|
|
// we should be considered a virtual folder if we are a child of one of the children of the system root folder.
|
|
|
|
|
// this is a bit of a trick to determine that... the directory name of a sub-child of the root will start with
|
|
|
|
|
// the root but not be equal to it
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!IsDirectory)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 19:21:50 -07:00
|
|
|
|
var parentDir = System.IO.Path.GetDirectoryName(Path) ?? string.Empty;
|
2013-03-03 22:43:06 -07:00
|
|
|
|
|
2016-03-27 14:11:27 -07:00
|
|
|
|
return parentDir.Length > _appPaths.RootFolderPath.Length
|
|
|
|
|
&& parentDir.StartsWith(_appPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether this instance is physical root.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance is physical root; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool IsPhysicalRoot
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-12-08 15:09:06 -07:00
|
|
|
|
return IsDirectory && string.Equals(Path, _appPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the additional locations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The additional locations.</value>
|
|
|
|
|
private List<string> AdditionalLocations { get; set; }
|
|
|
|
|
|
2014-12-14 22:16:23 -07:00
|
|
|
|
public bool HasParent<T>()
|
|
|
|
|
where T : Folder
|
|
|
|
|
{
|
|
|
|
|
var parent = Parent;
|
|
|
|
|
|
|
|
|
|
if (parent != null)
|
|
|
|
|
{
|
|
|
|
|
var item = parent as T;
|
|
|
|
|
|
|
|
|
|
// Just in case the user decided to nest episodes.
|
|
|
|
|
// Not officially supported but in some cases we can handle it.
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
2015-11-11 07:56:31 -07:00
|
|
|
|
item = parent.GetParents().OfType<T>().FirstOrDefault();
|
2014-12-14 22:16:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item != null;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the additional location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
|
|
|
|
public void AddAdditionalLocation(string path)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
2014-12-14 22:16:23 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
if (AdditionalLocations == null)
|
|
|
|
|
{
|
|
|
|
|
AdditionalLocations = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AdditionalLocations.Add(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the physical locations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The physical locations.</value>
|
|
|
|
|
public IEnumerable<string> PhysicalLocations
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-12-14 22:16:23 -07:00
|
|
|
|
var paths = string.IsNullOrWhiteSpace(Path) ? new string[] { } : new[] { Path };
|
2013-02-20 18:33:05 -07:00
|
|
|
|
return AdditionalLocations == null ? paths : paths.Concat(AdditionalLocations);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name of the file system entry by.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
2013-04-27 22:29:27 -07:00
|
|
|
|
/// <returns>FileSystemInfo.</returns>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
public FileSystemMetadata GetFileSystemEntryByName(string name)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
2014-12-14 22:16:23 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
return GetFileSystemEntryByPath(System.IO.Path.Combine(Path, name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the file system entry by path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">The path.</param>
|
2013-04-27 22:29:27 -07:00
|
|
|
|
/// <returns>FileSystemInfo.</returns>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
2015-10-03 20:38:46 -07:00
|
|
|
|
public FileSystemMetadata GetFileSystemEntryByPath(string path)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
2014-12-14 22:16:23 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
if (FileSystemDictionary != null)
|
|
|
|
|
{
|
2015-10-03 20:38:46 -07:00
|
|
|
|
FileSystemMetadata entry;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
if (FileSystemDictionary.TryGetValue(path, out entry))
|
|
|
|
|
{
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2014-10-22 21:26:01 -07:00
|
|
|
|
/// Determines whether [contains meta file by name] [the specified name].
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
2014-10-22 21:26:01 -07:00
|
|
|
|
/// <returns><c>true</c> if [contains meta file by name] [the specified name]; otherwise, <c>false</c>.</returns>
|
|
|
|
|
public bool ContainsMetaFileByName(string name)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 21:26:01 -07:00
|
|
|
|
return GetFileSystemEntryByName(name) != null;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether [contains file system entry by name] [the specified name].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <returns><c>true</c> if [contains file system entry by name] [the specified name]; otherwise, <c>false</c>.</returns>
|
|
|
|
|
public bool ContainsFileSystemEntryByName(string name)
|
|
|
|
|
{
|
2013-04-27 22:29:27 -07:00
|
|
|
|
return GetFileSystemEntryByName(name) != null;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 10:07:35 -07:00
|
|
|
|
public string GetCollectionType()
|
|
|
|
|
{
|
2014-10-22 21:26:01 -07:00
|
|
|
|
return CollectionType;
|
2013-09-04 10:07:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 21:26:01 -07:00
|
|
|
|
public string CollectionType { get; set; }
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
#region Equality Overrides
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">The object to compare with the current object.</param>
|
|
|
|
|
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2016-03-27 14:11:27 -07:00
|
|
|
|
return Equals(obj as ItemResolveArgs);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a hash code for this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return Path.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Equalses the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected bool Equals(ItemResolveArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args != null)
|
|
|
|
|
{
|
|
|
|
|
if (args.Path == null && Path == null) return true;
|
|
|
|
|
return args.Path != null && args.Path.Equals(Path, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|