ItemResolveEventArgs.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. public bool IsMetadataFolder
  38. {
  39. get
  40. {
  41. return this.FileInfo.cFileName.Equals("metadata", StringComparison.OrdinalIgnoreCase);
  42. }
  43. }
  44. public WIN32_FIND_DATA? GetFileSystemEntry(string path)
  45. {
  46. WIN32_FIND_DATA entry = FileSystemChildren.FirstOrDefault(f => f.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
  47. return entry.cFileName != null ? (WIN32_FIND_DATA?)entry : null;
  48. }
  49. public bool ContainsFile(string name)
  50. {
  51. return FileSystemChildren.FirstOrDefault(f => f.cFileName.Equals(name, StringComparison.OrdinalIgnoreCase)).cFileName != null;
  52. }
  53. public bool ContainsFolder(string name)
  54. {
  55. return ContainsFile(name);
  56. }
  57. }
  58. /// <summary>
  59. /// This is an EventArgs object used before we begin resolving a Path into a BaseItem
  60. /// File system children have not been collected yet, but consuming events will
  61. /// have a chance to cancel resolution based on the Path, Parent and FileAttributes
  62. /// </summary>
  63. public class PreBeginResolveEventArgs : EventArgs
  64. {
  65. public Folder Parent { get; set; }
  66. public bool Cancel { get; set; }
  67. public WIN32_FIND_DATA FileInfo { get; set; }
  68. public string Path { get; set; }
  69. public bool IsDirectory
  70. {
  71. get
  72. {
  73. return FileInfo.dwFileAttributes.HasFlag(FileAttributes.Directory);
  74. }
  75. }
  76. public bool IsHidden
  77. {
  78. get
  79. {
  80. return FileInfo.IsHidden;
  81. }
  82. }
  83. public bool IsSystemFile
  84. {
  85. get
  86. {
  87. return FileInfo.IsSystemFile;
  88. }
  89. }
  90. }
  91. }