ItemResolveEventArgs.cs 2.7 KB

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