GameGenre.cs 3.8 KB

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