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