diff options
| author | Andrew Rabert <ar@nullsum.net> | 2018-12-27 18:27:57 -0500 |
|---|---|---|
| committer | Andrew Rabert <ar@nullsum.net> | 2018-12-27 18:27:57 -0500 |
| commit | a86b71899ec52c44ddc6c3018e8cc5e9d7ff4d62 (patch) | |
| tree | a74f6ea4a8abfa1664a605d31d48bc38245ccf58 /MediaBrowser.Controller/Entities/LinkedChild.cs | |
| parent | 9bac3ac616b01f67db98381feb09d34ebe821f9a (diff) | |
Add GPL modules
Diffstat (limited to 'MediaBrowser.Controller/Entities/LinkedChild.cs')
| -rw-r--r-- | MediaBrowser.Controller/Entities/LinkedChild.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/Entities/LinkedChild.cs b/MediaBrowser.Controller/Entities/LinkedChild.cs new file mode 100644 index 000000000..363a3d6fd --- /dev/null +++ b/MediaBrowser.Controller/Entities/LinkedChild.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Controller.Entities +{ + public class LinkedChild + { + public string Path { get; set; } + public LinkedChildType Type { get; set; } + public string LibraryItemId { get; set; } + + [IgnoreDataMember] + public string Id { get; set; } + + /// <summary> + /// Serves as a cache + /// </summary> + public Guid? ItemId { get; set; } + + public static LinkedChild Create(BaseItem item) + { + var child = new LinkedChild + { + Path = item.Path, + Type = LinkedChildType.Manual + }; + + if (string.IsNullOrEmpty(child.Path)) + { + child.LibraryItemId = item.Id.ToString("N"); + } + + return child; + } + + public LinkedChild() + { + Id = Guid.NewGuid().ToString("N"); + } + } + + public enum LinkedChildType + { + Manual = 0, + Shortcut = 1 + } + + public class LinkedChildComparer : IEqualityComparer<LinkedChild> + { + private readonly IFileSystem _fileSystem; + + public LinkedChildComparer(IFileSystem fileSystem) + { + _fileSystem = fileSystem; + } + + public bool Equals(LinkedChild x, LinkedChild y) + { + if (x.Type == y.Type) + { + return _fileSystem.AreEqual(x.Path, y.Path); + } + return false; + } + + public int GetHashCode(LinkedChild obj) + { + return ((obj.Path ?? string.Empty) + (obj.LibraryItemId ?? string.Empty) + obj.Type).GetHashCode(); + } + } +} |
