LinkedChild.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Text.Json.Serialization;
  7. using MediaBrowser.Model.IO;
  8. namespace MediaBrowser.Controller.Entities
  9. {
  10. public class LinkedChild
  11. {
  12. public string Path { get; set; }
  13. public LinkedChildType Type { get; set; }
  14. public string LibraryItemId { get; set; }
  15. [JsonIgnore]
  16. public string Id { get; set; }
  17. /// <summary>
  18. /// Serves as a cache.
  19. /// </summary>
  20. public Guid? ItemId { get; set; }
  21. public static LinkedChild Create(BaseItem item)
  22. {
  23. var child = new LinkedChild
  24. {
  25. Path = item.Path,
  26. Type = LinkedChildType.Manual
  27. };
  28. if (string.IsNullOrEmpty(child.Path))
  29. {
  30. child.LibraryItemId = item.Id.ToString("N", CultureInfo.InvariantCulture);
  31. }
  32. return child;
  33. }
  34. public LinkedChild()
  35. {
  36. Id = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
  37. }
  38. }
  39. public enum LinkedChildType
  40. {
  41. Manual = 0,
  42. Shortcut = 1
  43. }
  44. public class LinkedChildComparer : IEqualityComparer<LinkedChild>
  45. {
  46. private readonly IFileSystem _fileSystem;
  47. public LinkedChildComparer(IFileSystem fileSystem)
  48. {
  49. _fileSystem = fileSystem;
  50. }
  51. public bool Equals(LinkedChild x, LinkedChild y)
  52. {
  53. if (x.Type == y.Type)
  54. {
  55. return _fileSystem.AreEqual(x.Path, y.Path);
  56. }
  57. return false;
  58. }
  59. public int GetHashCode(LinkedChild obj)
  60. {
  61. return ((obj.Path ?? string.Empty) + (obj.LibraryItemId ?? string.Empty) + obj.Type).GetHashCode();
  62. }
  63. }
  64. }