ServerApplicationPaths.cs 5.4 KB

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