ItemResolveEventArgs.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.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 IEnumerable<KeyValuePair<string, FileAttributes>> FileSystemChildren { get; set; }
  13. public KeyValuePair<string, FileAttributes>? GetFolderByName(string name)
  14. {
  15. foreach (KeyValuePair<string, FileAttributes> entry in FileSystemChildren)
  16. {
  17. if (!entry.Value.HasFlag(FileAttributes.Directory))
  18. {
  19. continue;
  20. }
  21. if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
  22. {
  23. return entry;
  24. }
  25. }
  26. return null;
  27. }
  28. public KeyValuePair<string, FileAttributes>? GetFileByName(string name)
  29. {
  30. foreach (KeyValuePair<string, FileAttributes> entry in FileSystemChildren)
  31. {
  32. if (entry.Value.HasFlag(FileAttributes.Directory))
  33. {
  34. continue;
  35. }
  36. if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
  37. {
  38. return entry;
  39. }
  40. }
  41. return null;
  42. }
  43. public bool ContainsFile(string name)
  44. {
  45. return GetFileByName(name) != null;
  46. }
  47. public bool ContainsFolder(string name)
  48. {
  49. return GetFolderByName(name) != null;
  50. }
  51. }
  52. /// <summary>
  53. /// This is an EventArgs object used before we begin resolving a Path into a BaseItem
  54. /// File system children have not been collected yet, but consuming events will
  55. /// have a chance to cancel resolution based on the Path, Parent and FileAttributes
  56. /// </summary>
  57. public class PreBeginResolveEventArgs : EventArgs
  58. {
  59. public string Path { get; set; }
  60. public Folder Parent { get; set; }
  61. public bool Cancel { get; set; }
  62. public FileAttributes FileAttributes { get; set; }
  63. public bool IsFolder
  64. {
  65. get
  66. {
  67. return FileAttributes.HasFlag(FileAttributes.Directory);
  68. }
  69. }
  70. public bool IsHidden
  71. {
  72. get
  73. {
  74. return FileAttributes.HasFlag(FileAttributes.Hidden);
  75. }
  76. }
  77. public bool IsSystemFile
  78. {
  79. get
  80. {
  81. return FileAttributes.HasFlag(FileAttributes.System);
  82. }
  83. }
  84. public VirtualFolder VirtualFolder
  85. {
  86. get
  87. {
  88. if (Parent != null)
  89. {
  90. return Parent.VirtualFolder;
  91. }
  92. return null;
  93. }
  94. }
  95. public string VirtualFolderCollectionType
  96. {
  97. get
  98. {
  99. VirtualFolder vf = VirtualFolder;
  100. if (vf == null)
  101. {
  102. return null;
  103. }
  104. return vf.CollectionType;
  105. }
  106. }
  107. }
  108. }