ItemResolveEventArgs.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System;
  6. using System.IO;
  7. namespace MediaBrowser.Controller.Library
  8. {
  9. /// <summary>
  10. /// This is an EventArgs object used when resolving a Path into a BaseItem
  11. /// </summary>
  12. public class ItemResolveEventArgs : PreBeginResolveEventArgs
  13. {
  14. public WIN32_FIND_DATA[] FileSystemChildren { get; set; }
  15. protected List<string> _additionalLocations = new List<string>();
  16. public List<string> AdditionalLocations
  17. {
  18. get
  19. {
  20. return _additionalLocations;
  21. }
  22. set
  23. {
  24. _additionalLocations = value;
  25. }
  26. }
  27. public IEnumerable<string> PhysicalLocations
  28. {
  29. get
  30. {
  31. return (new List<string>() {this.Path}).Concat(AdditionalLocations);
  32. }
  33. }
  34. public bool IsBDFolder { get; set; }
  35. public bool IsDVDFolder { get; set; }
  36. public bool IsHDDVDFolder { get; set; }
  37. /// <summary>
  38. /// Store these to reduce disk access in Resolvers
  39. /// </summary>
  40. public string[] MetadataFiles { get; set; }
  41. public WIN32_FIND_DATA? GetFileSystemEntry(string path)
  42. {
  43. WIN32_FIND_DATA entry = FileSystemChildren.FirstOrDefault(f => f.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
  44. return entry.cFileName != null ? (WIN32_FIND_DATA?)entry : null;
  45. }
  46. public bool ContainsFile(string name)
  47. {
  48. return FileSystemChildren.FirstOrDefault(f => f.cFileName.Equals(name, StringComparison.OrdinalIgnoreCase)).cFileName != null;
  49. }
  50. public bool ContainsFolder(string name)
  51. {
  52. return ContainsFile(name);
  53. }
  54. }
  55. /// <summary>
  56. /// This is an EventArgs object used before we begin resolving a Path into a BaseItem
  57. /// File system children have not been collected yet, but consuming events will
  58. /// have a chance to cancel resolution based on the Path, Parent and FileAttributes
  59. /// </summary>
  60. public class PreBeginResolveEventArgs : EventArgs
  61. {
  62. public Folder Parent { get; set; }
  63. public bool Cancel { get; set; }
  64. public WIN32_FIND_DATA FileInfo { get; set; }
  65. public string Path { get; set; }
  66. public bool IsDirectory
  67. {
  68. get
  69. {
  70. return FileInfo.dwFileAttributes.HasFlag(FileAttributes.Directory);
  71. }
  72. }
  73. public bool IsHidden
  74. {
  75. get
  76. {
  77. return FileInfo.IsHidden;
  78. }
  79. }
  80. public bool IsSystemFile
  81. {
  82. get
  83. {
  84. return FileInfo.IsSystemFile;
  85. }
  86. }
  87. }
  88. }