|  |  | 1 |  | #nullable disable | 
|  |  | 2 |  |  | 
|  |  | 3 |  | #pragma warning disable CS1591 | 
|  |  | 4 |  |  | 
|  |  | 5 |  | using System; | 
|  |  | 6 |  | using System.IO; | 
|  |  | 7 |  | using System.Linq; | 
|  |  | 8 |  | using Jellyfin.Data.Enums; | 
|  |  | 9 |  | using MediaBrowser.Controller; | 
|  |  | 10 |  | using MediaBrowser.Controller.Entities; | 
|  |  | 11 |  | using MediaBrowser.Controller.Library; | 
|  |  | 12 |  | using MediaBrowser.Controller.Resolvers; | 
|  |  | 13 |  | using MediaBrowser.Model.IO; | 
|  |  | 14 |  |  | 
|  |  | 15 |  | namespace Emby.Server.Implementations.Library.Resolvers | 
|  |  | 16 |  | { | 
|  |  | 17 |  |     public class SpecialFolderResolver : GenericFolderResolver<Folder> | 
|  |  | 18 |  |     { | 
|  |  | 19 |  |         private readonly IFileSystem _fileSystem; | 
|  |  | 20 |  |         private readonly IServerApplicationPaths _appPaths; | 
|  |  | 21 |  |  | 
|  | 21 | 22 |  |         public SpecialFolderResolver(IFileSystem fileSystem, IServerApplicationPaths appPaths) | 
|  |  | 23 |  |         { | 
|  | 21 | 24 |  |             _fileSystem = fileSystem; | 
|  | 21 | 25 |  |             _appPaths = appPaths; | 
|  | 21 | 26 |  |         } | 
|  |  | 27 |  |  | 
|  |  | 28 |  |         /// <summary> | 
|  |  | 29 |  |         /// Gets the priority. | 
|  |  | 30 |  |         /// </summary> | 
|  |  | 31 |  |         /// <value>The priority.</value> | 
|  | 21 | 32 |  |         public override ResolverPriority Priority => ResolverPriority.First; | 
|  |  | 33 |  |  | 
|  |  | 34 |  |         /// <summary> | 
|  |  | 35 |  |         /// Resolves the specified args. | 
|  |  | 36 |  |         /// </summary> | 
|  |  | 37 |  |         /// <param name="args">The args.</param> | 
|  |  | 38 |  |         /// <returns>Folder.</returns> | 
|  |  | 39 |  |         protected override Folder Resolve(ItemResolveArgs args) | 
|  |  | 40 |  |         { | 
|  | 60 | 41 |  |             if (args.IsDirectory) | 
|  |  | 42 |  |             { | 
|  | 50 | 43 |  |                 if (args.IsPhysicalRoot) | 
|  |  | 44 |  |                 { | 
|  | 21 | 45 |  |                     return new AggregateFolder(); | 
|  |  | 46 |  |                 } | 
|  |  | 47 |  |  | 
|  | 29 | 48 |  |                 if (string.Equals(args.Path, _appPaths.DefaultUserViewsPath, StringComparison.OrdinalIgnoreCase)) | 
|  |  | 49 |  |                 { | 
|  | 21 | 50 |  |                     return new UserRootFolder();  // if we got here and still a root - must be user root | 
|  |  | 51 |  |                 } | 
|  |  | 52 |  |  | 
|  | 8 | 53 |  |                 if (args.IsVf) | 
|  |  | 54 |  |                 { | 
|  | 8 | 55 |  |                     return new CollectionFolder | 
|  | 8 | 56 |  |                     { | 
|  | 8 | 57 |  |                         CollectionType = GetCollectionType(args), | 
|  | 8 | 58 |  |                         PhysicalLocationsList = args.PhysicalLocations | 
|  | 8 | 59 |  |                     }; | 
|  |  | 60 |  |                 } | 
|  |  | 61 |  |             } | 
|  |  | 62 |  |  | 
|  | 10 | 63 |  |             return null; | 
|  |  | 64 |  |         } | 
|  |  | 65 |  |  | 
|  |  | 66 |  |         private CollectionType? GetCollectionType(ItemResolveArgs args) | 
|  |  | 67 |  |         { | 
|  | 8 | 68 |  |             return args.FileSystemChildren | 
|  | 8 | 69 |  |                 .Where(i => | 
|  | 8 | 70 |  |                 { | 
|  | 8 | 71 |  |                     try | 
|  | 8 | 72 |  |                     { | 
|  | 8 | 73 |  |                         return !i.IsDirectory && | 
|  | 8 | 74 |  |                                string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase); | 
|  | 8 | 75 |  |                     } | 
|  | 8 | 76 |  |                     catch (IOException) | 
|  | 8 | 77 |  |                     { | 
|  | 8 | 78 |  |                         return false; | 
|  | 8 | 79 |  |                     } | 
|  | 8 | 80 |  |                 }) | 
|  | 8 | 81 |  |                 .Select(i => _fileSystem.GetFileNameWithoutExtension(i)) | 
|  | 8 | 82 |  |                 .Select(i => Enum.TryParse<CollectionType>(i, out var collectionType) ? collectionType : (CollectionType | 
|  | 8 | 83 |  |                 .FirstOrDefault(i => i is not null); | 
|  |  | 84 |  |         } | 
|  |  | 85 |  |     } | 
|  |  | 86 |  | } |