ItemResolveEventArgs.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Controller.IO;
  4. using MediaBrowser.Model.Entities;
  5. namespace MediaBrowser.Controller.Library
  6. {
  7. /// <summary>
  8. /// This is an EventArgs object used when resolving a Path into a BaseItem
  9. /// </summary>
  10. public class ItemResolveEventArgs : PreBeginResolveEventArgs
  11. {
  12. public WIN32_FIND_DATA[] FileSystemChildren { get; set; }
  13. public WIN32_FIND_DATA? GetFileSystemEntry(string path)
  14. {
  15. for (int i = 0; i < FileSystemChildren.Length; i++)
  16. {
  17. WIN32_FIND_DATA entry = FileSystemChildren[i];
  18. if (entry.Path.Equals(path, StringComparison.OrdinalIgnoreCase))
  19. {
  20. return entry;
  21. }
  22. }
  23. return null;
  24. }
  25. public bool ContainsFile(string name)
  26. {
  27. for (int i = 0; i < FileSystemChildren.Length; i++)
  28. {
  29. if (System.IO.Path.GetFileName(FileSystemChildren[i].Path).Equals(name, StringComparison.OrdinalIgnoreCase))
  30. {
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. public bool ContainsFolder(string name)
  37. {
  38. for (int i = 0; i < FileSystemChildren.Length; i++)
  39. {
  40. if (System.IO.Path.GetFileName(FileSystemChildren[i].Path).Equals(name, StringComparison.OrdinalIgnoreCase))
  41. {
  42. return true;
  43. }
  44. }
  45. return false;
  46. }
  47. }
  48. /// <summary>
  49. /// This is an EventArgs object used before we begin resolving a Path into a BaseItem
  50. /// File system children have not been collected yet, but consuming events will
  51. /// have a chance to cancel resolution based on the Path, Parent and FileAttributes
  52. /// </summary>
  53. public class PreBeginResolveEventArgs : EventArgs
  54. {
  55. public Folder Parent { get; set; }
  56. public bool Cancel { get; set; }
  57. public WIN32_FIND_DATA FileInfo { get; set; }
  58. public string Path { get; set; }
  59. public bool IsDirectory
  60. {
  61. get
  62. {
  63. return FileInfo.dwFileAttributes.HasFlag(FileAttributes.Directory);
  64. }
  65. }
  66. public VirtualFolder VirtualFolder
  67. {
  68. get
  69. {
  70. if (Parent != null)
  71. {
  72. return Parent.VirtualFolder;
  73. }
  74. return null;
  75. }
  76. }
  77. public string VirtualFolderCollectionType
  78. {
  79. get
  80. {
  81. VirtualFolder vf = VirtualFolder;
  82. if (vf == null)
  83. {
  84. return null;
  85. }
  86. return vf.CollectionType;
  87. }
  88. }
  89. public bool IsHidden
  90. {
  91. get
  92. {
  93. return FileInfo.IsHidden;
  94. }
  95. }
  96. public bool IsSystemFile
  97. {
  98. get
  99. {
  100. return FileInfo.IsSystemFile;
  101. }
  102. }
  103. }
  104. }