CoreResolutionIgnoreRule.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Resolvers;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. namespace MediaBrowser.Server.Implementations.Library
  9. {
  10. /// <summary>
  11. /// Provides the core resolver ignore rules
  12. /// </summary>
  13. public class CoreResolutionIgnoreRule : IResolverIgnoreRule
  14. {
  15. /// <summary>
  16. /// Any folder named in this list will be ignored - can be added to at runtime for extensibility
  17. /// </summary>
  18. private static readonly List<string> IgnoreFolders = new List<string>
  19. {
  20. "metadata",
  21. "certificate",
  22. "backup",
  23. "ps3_update",
  24. "ps3_vprm",
  25. "adv_obj",
  26. "extrafanart"
  27. };
  28. /// <summary>
  29. /// Shoulds the ignore.
  30. /// </summary>
  31. /// <param name="args">The args.</param>
  32. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  33. public bool ShouldIgnore(ItemResolveArgs args)
  34. {
  35. // Ignore hidden files and folders
  36. if (args.IsHidden)
  37. {
  38. var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
  39. if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase) || string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  40. {
  41. return false;
  42. }
  43. // Drives will sometimes be hidden
  44. if (args.Path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
  45. {
  46. if (new DriveInfo(args.Path).IsReady)
  47. {
  48. return false;
  49. }
  50. }
  51. return true;
  52. }
  53. if (args.IsDirectory)
  54. {
  55. var filename = args.FileInfo.Name;
  56. // Ignore any folders in our list
  57. if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
  58. {
  59. return true;
  60. }
  61. // Ignore trailer folders but allow it at the collection level
  62. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) && !(args.Parent is AggregateFolder) && !(args.Parent is UserRootFolder))
  63. {
  64. return true;
  65. }
  66. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  67. {
  68. return true;
  69. }
  70. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  71. {
  72. return true;
  73. }
  74. }
  75. return false;
  76. }
  77. }
  78. }