2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Collections.Generic;
|
2019-02-28 22:22:57 +00:00
|
|
|
using System.Globalization;
|
2019-10-15 15:49:49 +00:00
|
|
|
using System.Text.Json.Serialization;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
{
|
|
|
|
public class LinkedChild
|
|
|
|
{
|
|
|
|
public string Path { get; set; }
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public LinkedChildType Type { get; set; }
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public string LibraryItemId { get; set; }
|
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Serves as a cache.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </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))
|
|
|
|
{
|
2019-02-28 22:22:57 +00:00
|
|
|
child.LibraryItemId = item.Id.ToString("N", CultureInfo.InvariantCulture);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LinkedChild()
|
|
|
|
{
|
2019-02-28 22:22:57 +00:00
|
|
|
Id = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetHashCode(LinkedChild obj)
|
|
|
|
{
|
|
|
|
return ((obj.Path ?? string.Empty) + (obj.LibraryItemId ?? string.Empty) + obj.Type).GetHashCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|