| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using MediaBrowser.Model.IO; |
| | | 8 | | |
| | | 9 | | namespace MediaBrowser.Controller.Entities |
| | | 10 | | { |
| | | 11 | | public class LinkedChildComparer : IEqualityComparer<LinkedChild> |
| | | 12 | | { |
| | | 13 | | private readonly IFileSystem _fileSystem; |
| | | 14 | | |
| | | 15 | | public LinkedChildComparer(IFileSystem fileSystem) |
| | | 16 | | { |
| | 35 | 17 | | _fileSystem = fileSystem; |
| | 35 | 18 | | } |
| | | 19 | | |
| | | 20 | | public bool Equals(LinkedChild x, LinkedChild y) |
| | | 21 | | { |
| | 0 | 22 | | if (x.Type != y.Type) |
| | | 23 | | { |
| | 0 | 24 | | return false; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | // Compare by ItemId first (preferred) |
| | 0 | 28 | | if (x.ItemId.HasValue && y.ItemId.HasValue) |
| | | 29 | | { |
| | 0 | 30 | | return x.ItemId.Value.Equals(y.ItemId.Value); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | #pragma warning disable CS0618 // Type or member is obsolete - fallback for shortcut/legacy comparison |
| | | 34 | | // Fall back to Path comparison for shortcuts and legacy data |
| | 0 | 35 | | return _fileSystem.AreEqual(x.Path, y.Path); |
| | | 36 | | #pragma warning restore CS0618 |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public int GetHashCode(LinkedChild obj) |
| | | 40 | | { |
| | | 41 | | // Use ItemId for hash if available, otherwise fall back to legacy fields |
| | 0 | 42 | | if (obj.ItemId.HasValue && !obj.ItemId.Value.Equals(Guid.Empty)) |
| | | 43 | | { |
| | 0 | 44 | | return HashCode.Combine(obj.ItemId.Value, obj.Type); |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | #pragma warning disable CS0618 // Type or member is obsolete - fallback for shortcut/legacy hashing |
| | 0 | 48 | | return ((obj.Path ?? string.Empty) + (obj.LibraryItemId ?? string.Empty) + obj.Type).GetHashCode(StringCompa |
| | | 49 | | #pragma warning restore CS0618 |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |