GameGenre.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.Serialization;
  4. using MediaBrowser.Controller.Extensions;
  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
  31. {
  32. get
  33. {
  34. return Path;
  35. }
  36. }
  37. [IgnoreDataMember]
  38. public override bool SupportsAncestors
  39. {
  40. get
  41. {
  42. return false;
  43. }
  44. }
  45. public override bool IsSaveLocalMetadataEnabled()
  46. {
  47. return true;
  48. }
  49. public override bool CanDelete()
  50. {
  51. return false;
  52. }
  53. public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
  54. {
  55. query.GenreIds = new[] { Id };
  56. query.IncludeItemTypes = new[] { typeof(Game).Name };
  57. return LibraryManager.GetItemList(query);
  58. }
  59. [IgnoreDataMember]
  60. public override bool SupportsPeople
  61. {
  62. get
  63. {
  64. return false;
  65. }
  66. }
  67. public static string GetPath(string name)
  68. {
  69. return GetPath(name, true);
  70. }
  71. public static string GetPath(string name, bool normalizeName)
  72. {
  73. // Trim the period at the end because windows will have a hard time with that
  74. var validName = normalizeName ?
  75. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  76. name;
  77. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.GameGenrePath, validName);
  78. }
  79. private string GetRebasedPath()
  80. {
  81. return GetPath(System.IO.Path.GetFileName(Path), false);
  82. }
  83. public override bool RequiresRefresh()
  84. {
  85. var newPath = GetRebasedPath();
  86. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  87. {
  88. Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  89. return true;
  90. }
  91. return base.RequiresRefresh();
  92. }
  93. /// <summary>
  94. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  95. /// </summary>
  96. public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
  97. {
  98. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
  99. var newPath = GetRebasedPath();
  100. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  101. {
  102. Path = newPath;
  103. hasChanges = true;
  104. }
  105. return hasChanges;
  106. }
  107. }
  108. }