ServerApplicationPaths.cs 5.6 KB

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