2019-11-01 10:38:54 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2019-01-13 12:21:32 -07:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Controller;
|
2014-12-19 23:06:27 -07:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2016-10-25 12:02:04 -07:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-12-19 23:06:27 -07:00
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers
|
2014-12-19 23:06:27 -07:00
|
|
|
{
|
2019-02-15 15:05:14 -07:00
|
|
|
public class SpecialFolderResolver : FolderResolver<Folder>
|
2014-12-19 23:06:27 -07:00
|
|
|
{
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2015-01-27 15:45:59 -07:00
|
|
|
private readonly IServerApplicationPaths _appPaths;
|
2014-12-19 23:06:27 -07:00
|
|
|
|
2015-01-27 15:45:59 -07:00
|
|
|
public SpecialFolderResolver(IFileSystem fileSystem, IServerApplicationPaths appPaths)
|
2014-12-19 23:06:27 -07:00
|
|
|
{
|
|
|
|
_fileSystem = fileSystem;
|
2015-01-27 15:45:59 -07:00
|
|
|
_appPaths = appPaths;
|
2014-12-19 23:06:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the priority.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The priority.</value>
|
2019-01-06 13:50:43 -07:00
|
|
|
public override ResolverPriority Priority => ResolverPriority.First;
|
2014-12-19 23:06:27 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Resolves the specified args.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
/// <returns>Folder.</returns>
|
|
|
|
protected override Folder Resolve(ItemResolveArgs args)
|
|
|
|
{
|
|
|
|
if (args.IsDirectory)
|
|
|
|
{
|
|
|
|
if (args.IsPhysicalRoot)
|
|
|
|
{
|
|
|
|
return new AggregateFolder();
|
|
|
|
}
|
2015-01-27 15:45:59 -07:00
|
|
|
if (string.Equals(args.Path, _appPaths.DefaultUserViewsPath, StringComparison.OrdinalIgnoreCase))
|
2014-12-19 23:06:27 -07:00
|
|
|
{
|
2020-06-14 02:11:11 -07:00
|
|
|
return new UserRootFolder(); // if we got here and still a root - must be user root
|
2014-12-19 23:06:27 -07:00
|
|
|
}
|
|
|
|
if (args.IsVf)
|
|
|
|
{
|
|
|
|
return new CollectionFolder
|
|
|
|
{
|
2016-08-18 08:13:18 -07:00
|
|
|
CollectionType = GetCollectionType(args),
|
2017-08-24 12:52:19 -07:00
|
|
|
PhysicalLocationsList = args.PhysicalLocations
|
2014-12-19 23:06:27 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string GetCollectionType(ItemResolveArgs args)
|
|
|
|
{
|
|
|
|
return args.FileSystemChildren
|
|
|
|
.Where(i =>
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2016-10-25 12:02:04 -07:00
|
|
|
return !i.IsDirectory &&
|
2014-12-19 23:06:27 -07:00
|
|
|
string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
catch (IOException)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.Select(i => _fileSystem.GetFileNameWithoutExtension(i))
|
|
|
|
.FirstOrDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|