GameGenre.cs 3.5 KB

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