UserRootFolder.cs 2.4 KB

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