GameGenre.cs 3.9 KB

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