UserRootFolder.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using MediaBrowser.Controller.Providers;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace MediaBrowser.Controller.Entities
  8. {
  9. /// <summary>
  10. /// Special class used for User Roots. Children contain actual ones defined for this user
  11. /// PLUS the virtual folders from the physical root (added by plug-ins).
  12. /// </summary>
  13. public class UserRootFolder : Folder
  14. {
  15. /// <summary>
  16. /// Get the children of this folder from the actual file system
  17. /// </summary>
  18. /// <returns>IEnumerable{BaseItem}.</returns>
  19. protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
  20. {
  21. return base.GetNonCachedChildren(directoryService).Concat(LibraryManager.RootFolder.VirtualChildren);
  22. }
  23. public override bool BeforeMetadataRefresh()
  24. {
  25. var hasChanges = base.BeforeMetadataRefresh();
  26. if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
  27. {
  28. Name = "Media Folders";
  29. hasChanges = true;
  30. }
  31. return hasChanges;
  32. }
  33. protected override async Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
  34. {
  35. await base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService)
  36. .ConfigureAwait(false);
  37. // Not the best way to handle this, but it solves an issue
  38. // CollectionFolders aren't always getting saved after changes
  39. // This means that grabbing the item by Id may end up returning the old one
  40. // Fix is in two places - make sure the folder gets saved
  41. // And here to remedy it for affected users.
  42. // In theory this can be removed eventually.
  43. foreach (var item in Children)
  44. {
  45. LibraryManager.RegisterItem(item);
  46. }
  47. }
  48. }
  49. }