CoreResolutionIgnoreRule.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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) || string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  46. {
  47. return false;
  48. }
  49. // Drives will sometimes be hidden
  50. if (args.Path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
  51. {
  52. if (new DriveInfo(args.Path).IsReady)
  53. {
  54. return false;
  55. }
  56. _logger.Error("Operating system reports drive is not ready: {0}", args.Path);
  57. }
  58. return true;
  59. }
  60. if (args.IsDirectory)
  61. {
  62. var filename = args.FileInfo.Name;
  63. // Ignore any folders in our list
  64. if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
  65. {
  66. return true;
  67. }
  68. // Ignore trailer folders but allow it at the collection level
  69. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) && !(args.Parent is AggregateFolder) && !(args.Parent is UserRootFolder))
  70. {
  71. return true;
  72. }
  73. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  74. {
  75. return true;
  76. }
  77. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  78. {
  79. return true;
  80. }
  81. }
  82. return false;
  83. }
  84. }
  85. }