ItemResolveEventArgs.cs 3.9 KB

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