ItemResolveEventArgs.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.Entities;
  4. using System.IO;
  5. using System.Linq;
  6. namespace MediaBrowser.Controller.Events
  7. {
  8. public class ItemResolveEventArgs : PreBeginResolveEventArgs
  9. {
  10. public IEnumerable<KeyValuePair<string, FileAttributes>> FileSystemChildren { get; set; }
  11. public KeyValuePair<string, FileAttributes>? GetFolderByName(string name)
  12. {
  13. foreach (KeyValuePair<string, FileAttributes> entry in FileSystemChildren)
  14. {
  15. if (!entry.Value.HasFlag(FileAttributes.Directory))
  16. {
  17. continue;
  18. }
  19. if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
  20. {
  21. return entry;
  22. }
  23. }
  24. return null;
  25. }
  26. public KeyValuePair<string, FileAttributes>? GetFileByName(string name)
  27. {
  28. foreach (KeyValuePair<string, FileAttributes> entry in FileSystemChildren)
  29. {
  30. if (entry.Value.HasFlag(FileAttributes.Directory))
  31. {
  32. continue;
  33. }
  34. if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
  35. {
  36. return entry;
  37. }
  38. }
  39. return null;
  40. }
  41. public bool ContainsFile(string name)
  42. {
  43. return GetFileByName(name) != null;
  44. }
  45. public bool ContainsFolder(string name)
  46. {
  47. return GetFolderByName(name) != null;
  48. }
  49. }
  50. public class PreBeginResolveEventArgs : EventArgs
  51. {
  52. public string Path { get; set; }
  53. public Folder Parent { get; set; }
  54. public bool Cancel { get; set; }
  55. public FileAttributes FileAttributes { get; set; }
  56. public bool IsFolder
  57. {
  58. get
  59. {
  60. return FileAttributes.HasFlag(FileAttributes.Directory);
  61. }
  62. }
  63. public bool IsHidden
  64. {
  65. get
  66. {
  67. return FileAttributes.HasFlag(FileAttributes.Hidden);
  68. }
  69. }
  70. public bool IsSystemFile
  71. {
  72. get
  73. {
  74. return FileAttributes.HasFlag(FileAttributes.System);
  75. }
  76. }
  77. }
  78. }