|
|
@ -24,6 +24,8 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class Folder : BaseItem
|
|
|
|
public class Folder : BaseItem
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
public static IUserManager UserManager { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public Folder()
|
|
|
|
public Folder()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LinkedChildren = new List<LinkedChild>();
|
|
|
|
LinkedChildren = new List<LinkedChild>();
|
|
|
@ -89,6 +91,11 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
item.Id = item.Path.GetMBId(item.GetType());
|
|
|
|
item.Id = item.Path.GetMBId(item.GetType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_children.Any(i => i.Id == item.Id))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentException(string.Format("A child with the Id {0} already exists.", item.Id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.DateCreated == DateTime.MinValue)
|
|
|
|
if (item.DateCreated == DateTime.MinValue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.DateCreated = DateTime.UtcNow;
|
|
|
|
item.DateCreated = DateTime.UtcNow;
|
|
|
@ -718,17 +725,17 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in itemsRemoved)
|
|
|
|
foreach (var item in itemsRemoved)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (IsRootPathAvailable(item.Path))
|
|
|
|
if (IsPathOffline(item.Path))
|
|
|
|
{
|
|
|
|
|
|
|
|
item.IsOffline = false;
|
|
|
|
|
|
|
|
actualRemovals.Add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.IsOffline = true;
|
|
|
|
item.IsOffline = true;
|
|
|
|
|
|
|
|
|
|
|
|
validChildren.Add(new Tuple<BaseItem, bool>(item, false));
|
|
|
|
validChildren.Add(new Tuple<BaseItem, bool>(item, false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.IsOffline = false;
|
|
|
|
|
|
|
|
actualRemovals.Add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (actualRemovals.Count > 0)
|
|
|
|
if (actualRemovals.Count > 0)
|
|
|
@ -855,29 +862,52 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Determines if a path's root is available or not
|
|
|
|
/// Determines whether the specified path is offline.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path"></param>
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
|
|
|
|
private bool IsRootPathAvailable(string path)
|
|
|
|
private bool IsPathOffline(string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (File.Exists(path))
|
|
|
|
if (File.Exists(path))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var originalPath = path;
|
|
|
|
|
|
|
|
|
|
|
|
// Depending on whether the path is local or unc, it may return either null or '\' at the top
|
|
|
|
// Depending on whether the path is local or unc, it may return either null or '\' at the top
|
|
|
|
while (!string.IsNullOrEmpty(path) && path.Length > 1)
|
|
|
|
while (!string.IsNullOrEmpty(path) && path.Length > 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
path = System.IO.Path.GetDirectoryName(path);
|
|
|
|
path = System.IO.Path.GetDirectoryName(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
if (ContainsPath(LibraryManager.GetDefaultVirtualFolders(), originalPath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return UserManager.Users.Any(user => ContainsPath(LibraryManager.GetVirtualFolders(user), originalPath));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Determines whether the specified folders contains path.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="folders">The folders.</param>
|
|
|
|
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
|
|
|
|
/// <returns><c>true</c> if the specified folders contains path; otherwise, <c>false</c>.</returns>
|
|
|
|
|
|
|
|
private bool ContainsPath(IEnumerable<VirtualFolderInfo> folders, string path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return folders.SelectMany(i => i.Locations).Any(i => ContainsPath(i, path));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool ContainsPath(string parent, string path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return string.Equals(parent, path, StringComparison.OrdinalIgnoreCase) || path.IndexOf(parent.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) != -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|