ServerApplicationPaths.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.IO;
  3. using Emby.Server.Implementations.AppBase;
  4. using MediaBrowser.Controller;
  5. namespace Emby.Server.Implementations
  6. {
  7. /// <summary>
  8. /// Extends BaseApplicationPaths to add paths that are only applicable on the server
  9. /// </summary>
  10. public class ServerApplicationPaths : BaseApplicationPaths, IServerApplicationPaths
  11. {
  12. private string _defaultTranscodingTempPath;
  13. private string _transcodingTempPath;
  14. private string _internalMetadataPath;
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="ServerApplicationPaths" /> class.
  17. /// </summary>
  18. public ServerApplicationPaths(
  19. string programDataPath,
  20. string logDirectoryPath,
  21. string configurationDirectoryPath,
  22. string cacheDirectoryPath,
  23. string webDirectoryPath)
  24. : base(programDataPath,
  25. logDirectoryPath,
  26. configurationDirectoryPath,
  27. cacheDirectoryPath,
  28. webDirectoryPath)
  29. {
  30. }
  31. public string ApplicationResourcesPath { get; } = AppContext.BaseDirectory;
  32. /// <summary>
  33. /// Gets the path to the base root media directory.
  34. /// </summary>
  35. /// <value>The root folder path.</value>
  36. public string RootFolderPath => Path.Combine(ProgramDataPath, "root");
  37. /// <summary>
  38. /// Gets the path to the default user view directory. Used if no specific user view is defined.
  39. /// </summary>
  40. /// <value>The default user views path.</value>
  41. public string DefaultUserViewsPath => Path.Combine(RootFolderPath, "default");
  42. /// <summary>
  43. /// Gets the path to localization data.
  44. /// </summary>
  45. /// <value>The localization path.</value>
  46. public string LocalizationPath => Path.Combine(ProgramDataPath, "localization");
  47. /// <summary>
  48. /// Gets the path to the People directory.
  49. /// </summary>
  50. /// <value>The people path.</value>
  51. public string PeoplePath => Path.Combine(InternalMetadataPath, "People");
  52. public string ArtistsPath => Path.Combine(InternalMetadataPath, "artists");
  53. /// <summary>
  54. /// Gets the path to the Genre directory.
  55. /// </summary>
  56. /// <value>The genre path.</value>
  57. public string GenrePath => Path.Combine(InternalMetadataPath, "Genre");
  58. /// <summary>
  59. /// Gets the path to the Genre directory.
  60. /// </summary>
  61. /// <value>The genre path.</value>
  62. public string MusicGenrePath => Path.Combine(InternalMetadataPath, "MusicGenre");
  63. /// <summary>
  64. /// Gets the path to the Studio directory.
  65. /// </summary>
  66. /// <value>The studio path.</value>
  67. public string StudioPath => Path.Combine(InternalMetadataPath, "Studio");
  68. /// <summary>
  69. /// Gets the path to the Year directory.
  70. /// </summary>
  71. /// <value>The year path.</value>
  72. public string YearPath => Path.Combine(InternalMetadataPath, "Year");
  73. /// <summary>
  74. /// Gets the path to the General IBN directory.
  75. /// </summary>
  76. /// <value>The general path.</value>
  77. public string GeneralPath => Path.Combine(InternalMetadataPath, "general");
  78. /// <summary>
  79. /// Gets the path to the Ratings IBN directory.
  80. /// </summary>
  81. /// <value>The ratings path.</value>
  82. public string RatingsPath => Path.Combine(InternalMetadataPath, "ratings");
  83. /// <summary>
  84. /// Gets the media info images path.
  85. /// </summary>
  86. /// <value>The media info images path.</value>
  87. public string MediaInfoImagesPath => Path.Combine(InternalMetadataPath, "mediainfo");
  88. /// <summary>
  89. /// Gets the path to the user configuration directory.
  90. /// </summary>
  91. /// <value>The user configuration directory path.</value>
  92. public string UserConfigurationDirectoryPath => Path.Combine(ConfigurationDirectoryPath, "users");
  93. public string DefaultTranscodingTempPath => _defaultTranscodingTempPath ?? (_defaultTranscodingTempPath = Path.Combine(ProgramDataPath, "transcoding-temp"));
  94. public string TranscodingTempPath
  95. {
  96. get => _transcodingTempPath ?? (_transcodingTempPath = DefaultTranscodingTempPath);
  97. set => _transcodingTempPath = value;
  98. }
  99. public string GetTranscodingTempPath()
  100. {
  101. var path = TranscodingTempPath;
  102. if (!string.Equals(path, DefaultTranscodingTempPath, StringComparison.OrdinalIgnoreCase))
  103. {
  104. try
  105. {
  106. Directory.CreateDirectory(path);
  107. var testPath = Path.Combine(path, Guid.NewGuid().ToString());
  108. Directory.CreateDirectory(testPath);
  109. Directory.Delete(testPath);
  110. return path;
  111. }
  112. catch
  113. {
  114. }
  115. }
  116. path = DefaultTranscodingTempPath;
  117. Directory.CreateDirectory(path);
  118. return path;
  119. }
  120. public string InternalMetadataPath
  121. {
  122. get => _internalMetadataPath ?? (_internalMetadataPath = Path.Combine(DataPath, "metadata"));
  123. set => _internalMetadataPath = value;
  124. }
  125. public string VirtualInternalMetadataPath { get; } = "%MetadataPath%";
  126. }
  127. }