CoreResolutionIgnoreRule.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Resolvers;
  4. using MediaBrowser.Model.Logging;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. namespace MediaBrowser.Server.Implementations.Library
  10. {
  11. /// <summary>
  12. /// Provides the core resolver ignore rules
  13. /// </summary>
  14. public class CoreResolutionIgnoreRule : IResolverIgnoreRule
  15. {
  16. private readonly ILogger _logger;
  17. /// <summary>
  18. /// Any folder named in this list will be ignored - can be added to at runtime for extensibility
  19. /// </summary>
  20. private static readonly List<string> IgnoreFolders = new List<string>
  21. {
  22. "metadata",
  23. "certificate",
  24. "backup",
  25. "ps3_update",
  26. "ps3_vprm",
  27. "adv_obj",
  28. "extrafanart"
  29. };
  30. public CoreResolutionIgnoreRule(ILogger logger)
  31. {
  32. _logger = logger;
  33. }
  34. /// <summary>
  35. /// Shoulds the ignore.
  36. /// </summary>
  37. /// <param name="args">The args.</param>
  38. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  39. public bool ShouldIgnore(ItemResolveArgs args)
  40. {
  41. // Ignore hidden files and folders
  42. if (args.IsHidden)
  43. {
  44. var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
  45. if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  46. {
  47. return false;
  48. }
  49. if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  50. {
  51. return false;
  52. }
  53. // Drives will sometimes be hidden
  54. if (args.Path.EndsWith(Path.VolumeSeparatorChar + "\\", StringComparison.OrdinalIgnoreCase))
  55. {
  56. return false;
  57. }
  58. // Shares will sometimes be hidden
  59. if (args.Path.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
  60. {
  61. // Look for a share, e.g. \\server\movies
  62. // Is there a better way to detect if a path is a share without using native code?
  63. if (args.Path.Substring(2).Split(Path.DirectorySeparatorChar).Length == 2)
  64. {
  65. return false;
  66. }
  67. }
  68. return true;
  69. }
  70. if (args.IsDirectory)
  71. {
  72. var filename = args.FileInfo.Name;
  73. // Ignore any folders in our list
  74. if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
  75. {
  76. return true;
  77. }
  78. // Ignore trailer folders but allow it at the collection level
  79. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) &&
  80. !(args.Parent is AggregateFolder) && !(args.Parent is UserRootFolder))
  81. {
  82. return true;
  83. }
  84. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  85. {
  86. return true;
  87. }
  88. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  89. {
  90. return true;
  91. }
  92. }
  93. else
  94. {
  95. if (args.Parent != null)
  96. {
  97. var filename = args.FileInfo.Name;
  98. if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && EntityResolutionHelper.IsAudioFile(filename))
  99. {
  100. return true;
  101. }
  102. }
  103. }
  104. return false;
  105. }
  106. }
  107. }