GameGenre.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Controller.Extensions;
  4. using MediaBrowser.Model.Serialization;
  5. using Microsoft.Extensions.Logging;
  6. namespace MediaBrowser.Controller.Entities
  7. {
  8. public class GameGenre : BaseItem, IItemByName
  9. {
  10. public override List<string> GetUserDataKeys()
  11. {
  12. var list = base.GetUserDataKeys();
  13. list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
  14. return list;
  15. }
  16. public override string CreatePresentationUniqueKey()
  17. {
  18. return GetUserDataKeys()[0];
  19. }
  20. public override double GetDefaultPrimaryImageAspectRatio()
  21. {
  22. return 1;
  23. }
  24. /// <summary>
  25. /// Returns the folder containing the item.
  26. /// If the item is a folder, it returns the folder itself
  27. /// </summary>
  28. /// <value>The containing folder path.</value>
  29. [IgnoreDataMember]
  30. public override string ContainingFolderPath => Path;
  31. [IgnoreDataMember]
  32. public override bool SupportsAncestors => false;
  33. public override bool IsSaveLocalMetadataEnabled()
  34. {
  35. return true;
  36. }
  37. public override bool CanDelete()
  38. {
  39. return false;
  40. }
  41. public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
  42. {
  43. query.GenreIds = new[] { Id };
  44. query.IncludeItemTypes = new[] { typeof(Game).Name };
  45. return LibraryManager.GetItemList(query);
  46. }
  47. [IgnoreDataMember]
  48. public override bool SupportsPeople => false;
  49. public static string GetPath(string name)
  50. {
  51. return GetPath(name, true);
  52. }
  53. public static string GetPath(string name, bool normalizeName)
  54. {
  55. // Trim the period at the end because windows will have a hard time with that
  56. var validName = normalizeName ?
  57. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  58. name;
  59. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.GameGenrePath, validName);
  60. }
  61. private string GetRebasedPath()
  62. {
  63. return GetPath(System.IO.Path.GetFileName(Path), false);
  64. }
  65. public override bool RequiresRefresh()
  66. {
  67. var newPath = GetRebasedPath();
  68. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  69. {
  70. Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  71. return true;
  72. }
  73. return base.RequiresRefresh();
  74. }
  75. /// <summary>
  76. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  77. /// </summary>
  78. public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
  79. {
  80. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
  81. var newPath = GetRebasedPath();
  82. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  83. {
  84. Path = newPath;
  85. hasChanges = true;
  86. }
  87. return hasChanges;
  88. }
  89. }
  90. }