From dab5003d6bba57c27f4111653b36d39862b5b6fd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 12 Jul 2013 15:56:40 -0400 Subject: added collection type --- .../Library/LibraryManager.cs | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs') diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 810f54c26..c9fb95c86 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -487,7 +487,7 @@ namespace MediaBrowser.Server.Implementations.Library // When resolving the root, we need it's grandchildren (children of user views) var flattenFolderDepth = isPhysicalRoot ? 2 : 0; - args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf); + args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf); // Need to remove subpaths that may have been resolved from shortcuts // Example: if \\server\movies exists, then strip out \\server\movies\action @@ -1168,10 +1168,23 @@ namespace MediaBrowser.Server.Implementations.Library .Select(dir => new VirtualFolderInfo { Name = Path.GetFileName(dir), - Locations = Directory.EnumerateFiles(dir, "*.lnk", SearchOption.TopDirectoryOnly).Select(FileSystem.ResolveShortcut).OrderBy(i => i).ToList() + + Locations = Directory.EnumerateFiles(dir, "*.lnk", SearchOption.TopDirectoryOnly) + .Select(FileSystem.ResolveShortcut) + .OrderBy(i => i) + .ToList(), + + CollectionType = GetCollectionType(dir) }); } + private string GetCollectionType(string path) + { + return new DirectoryInfo(path).EnumerateFiles("*.collection", SearchOption.TopDirectoryOnly) + .Select(i => Path.GetFileNameWithoutExtension(i.FullName)) + .FirstOrDefault(); + } + /// /// Gets the item by id. /// @@ -1405,5 +1418,47 @@ namespace MediaBrowser.Server.Implementations.Library } } } + + /// + /// Finds the type of the collection. + /// + /// The item. + /// System.String. + public string FindCollectionType(BaseItem item) + { + while (!(item.Parent is AggregateFolder) && item.Parent != null) + { + item = item.Parent; + } + + if (item == null) + { + return null; + } + + var collectionTypes = _userManager.Users + .Select(i => i.RootFolder) + .Distinct() + .SelectMany(i => i.Children) + .OfType() + .Where(i => + { + try + { + return i.LocationType != LocationType.Remote && i.LocationType != LocationType.Virtual && + i.ResolveArgs.PhysicalLocations.Contains(item.Path); + } + catch (IOException ex) + { + _logger.ErrorException("Error getting resolve args for {0}", ex, i.Path); + return false; + } + }) + .Select(i => i.CollectionType) + .Where(i => !string.IsNullOrEmpty(i)) + .Distinct(); + + return collectionTypes.SingleOrDefault(); + } } } -- cgit v1.2.3