2
0

ServerApplicationPaths.cs 5.3 KB

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