2
0

EntityResolutionHelper.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. namespace MediaBrowser.Server.Implementations.Library
  8. {
  9. /// <summary>
  10. /// Class EntityResolutionHelper
  11. /// </summary>
  12. public static class EntityResolutionHelper
  13. {
  14. /// <summary>
  15. /// Any folder named in this list will be ignored - can be added to at runtime for extensibility
  16. /// </summary>
  17. public static readonly List<string> IgnoreFolders = new List<string>
  18. {
  19. "metadata",
  20. "ps3_update",
  21. "ps3_vprm",
  22. "extrafanart",
  23. "extrathumbs",
  24. ".actors",
  25. ".wd_tv"
  26. };
  27. /// <summary>
  28. /// Ensures DateCreated and DateModified have values
  29. /// </summary>
  30. /// <param name="fileSystem">The file system.</param>
  31. /// <param name="item">The item.</param>
  32. /// <param name="args">The args.</param>
  33. /// <param name="includeCreationTime">if set to <c>true</c> [include creation time].</param>
  34. public static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime)
  35. {
  36. if (fileSystem == null)
  37. {
  38. throw new ArgumentNullException("fileSystem");
  39. }
  40. if (item == null)
  41. {
  42. throw new ArgumentNullException("item");
  43. }
  44. if (args == null)
  45. {
  46. throw new ArgumentNullException("args");
  47. }
  48. // See if a different path came out of the resolver than what went in
  49. if (!string.Equals(args.Path, item.Path, StringComparison.OrdinalIgnoreCase))
  50. {
  51. var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
  52. if (childData != null)
  53. {
  54. if (includeCreationTime)
  55. {
  56. SetDateCreated(item, fileSystem, childData);
  57. }
  58. item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
  59. }
  60. else
  61. {
  62. var fileData = fileSystem.GetFileSystemInfo(item.Path);
  63. if (fileData.Exists)
  64. {
  65. if (includeCreationTime)
  66. {
  67. SetDateCreated(item, fileSystem, fileData);
  68. }
  69. item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
  70. }
  71. }
  72. }
  73. else
  74. {
  75. if (includeCreationTime)
  76. {
  77. SetDateCreated(item, fileSystem, args.FileInfo);
  78. }
  79. item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
  80. }
  81. }
  82. private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemInfo info)
  83. {
  84. var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();
  85. if (config.UseFileCreationTimeForDateAdded)
  86. {
  87. item.DateCreated = fileSystem.GetCreationTimeUtc(info);
  88. }
  89. else
  90. {
  91. item.DateCreated = DateTime.UtcNow;
  92. }
  93. }
  94. }
  95. }