ServerApplicationPaths.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. : base(programDataPath, appFolderPath, logDirectoryPath, configurationDirectoryPath)
  22. {
  23. ApplicationResourcesPath = applicationResourcesPath;
  24. }
  25. public string ApplicationResourcesPath { get; private set; }
  26. /// <summary>
  27. /// Gets the path to the base root media directory
  28. /// </summary>
  29. /// <value>The root folder path.</value>
  30. public string RootFolderPath
  31. {
  32. get
  33. {
  34. return Path.Combine(ProgramDataPath, "root");
  35. }
  36. }
  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
  42. {
  43. get
  44. {
  45. return Path.Combine(RootFolderPath, "default");
  46. }
  47. }
  48. /// <summary>
  49. /// Gets the path to localization data.
  50. /// </summary>
  51. /// <value>The localization path.</value>
  52. public string LocalizationPath
  53. {
  54. get
  55. {
  56. return Path.Combine(ProgramDataPath, "localization");
  57. }
  58. }
  59. /// <summary>
  60. /// Gets the path to the People directory
  61. /// </summary>
  62. /// <value>The people path.</value>
  63. public string PeoplePath
  64. {
  65. get
  66. {
  67. return Path.Combine(InternalMetadataPath, "People");
  68. }
  69. }
  70. public string ArtistsPath
  71. {
  72. get
  73. {
  74. return Path.Combine(InternalMetadataPath, "artists");
  75. }
  76. }
  77. /// <summary>
  78. /// Gets the path to the Genre directory
  79. /// </summary>
  80. /// <value>The genre path.</value>
  81. public string GenrePath
  82. {
  83. get
  84. {
  85. return Path.Combine(InternalMetadataPath, "Genre");
  86. }
  87. }
  88. /// <summary>
  89. /// Gets the path to the Genre directory
  90. /// </summary>
  91. /// <value>The genre path.</value>
  92. public string MusicGenrePath
  93. {
  94. get
  95. {
  96. return Path.Combine(InternalMetadataPath, "MusicGenre");
  97. }
  98. }
  99. /// <summary>
  100. /// Gets the path to the Studio directory
  101. /// </summary>
  102. /// <value>The studio path.</value>
  103. public string StudioPath
  104. {
  105. get
  106. {
  107. return Path.Combine(InternalMetadataPath, "Studio");
  108. }
  109. }
  110. /// <summary>
  111. /// Gets the path to the Year directory
  112. /// </summary>
  113. /// <value>The year path.</value>
  114. public string YearPath
  115. {
  116. get
  117. {
  118. return Path.Combine(InternalMetadataPath, "Year");
  119. }
  120. }
  121. /// <summary>
  122. /// Gets the path to the General IBN directory
  123. /// </summary>
  124. /// <value>The general path.</value>
  125. public string GeneralPath
  126. {
  127. get
  128. {
  129. return Path.Combine(InternalMetadataPath, "general");
  130. }
  131. }
  132. /// <summary>
  133. /// Gets the path to the Ratings IBN directory
  134. /// </summary>
  135. /// <value>The ratings path.</value>
  136. public string RatingsPath
  137. {
  138. get
  139. {
  140. return Path.Combine(InternalMetadataPath, "ratings");
  141. }
  142. }
  143. /// <summary>
  144. /// Gets the media info images path.
  145. /// </summary>
  146. /// <value>The media info images path.</value>
  147. public string MediaInfoImagesPath
  148. {
  149. get
  150. {
  151. return Path.Combine(InternalMetadataPath, "mediainfo");
  152. }
  153. }
  154. /// <summary>
  155. /// Gets the path to the user configuration directory
  156. /// </summary>
  157. /// <value>The user configuration directory path.</value>
  158. public string UserConfigurationDirectoryPath
  159. {
  160. get
  161. {
  162. return Path.Combine(ConfigurationDirectoryPath, "users");
  163. }
  164. }
  165. private string _defaultTranscodingTempPath;
  166. public string DefaultTranscodingTempPath
  167. {
  168. get
  169. {
  170. return _defaultTranscodingTempPath ?? (_defaultTranscodingTempPath = Path.Combine(ProgramDataPath, "transcoding-temp"));
  171. }
  172. }
  173. private string _transcodingTempPath;
  174. public string TranscodingTempPath
  175. {
  176. get
  177. {
  178. return _transcodingTempPath ?? (_transcodingTempPath = DefaultTranscodingTempPath);
  179. }
  180. set
  181. {
  182. _transcodingTempPath = value;
  183. }
  184. }
  185. public string GetTranscodingTempPath()
  186. {
  187. var path = TranscodingTempPath;
  188. if (!string.Equals(path, DefaultTranscodingTempPath, StringComparison.OrdinalIgnoreCase))
  189. {
  190. try
  191. {
  192. Directory.CreateDirectory(path);
  193. var testPath = Path.Combine(path, Guid.NewGuid().ToString());
  194. Directory.CreateDirectory(testPath);
  195. Directory.Delete(testPath);
  196. return path;
  197. }
  198. catch
  199. {
  200. }
  201. }
  202. path = DefaultTranscodingTempPath;
  203. Directory.CreateDirectory(path);
  204. return path;
  205. }
  206. /// <summary>
  207. /// Gets the game genre path.
  208. /// </summary>
  209. /// <value>The game genre path.</value>
  210. public string GameGenrePath
  211. {
  212. get
  213. {
  214. return Path.Combine(InternalMetadataPath, "GameGenre");
  215. }
  216. }
  217. private string _internalMetadataPath;
  218. public string InternalMetadataPath
  219. {
  220. get
  221. {
  222. return _internalMetadataPath ?? (_internalMetadataPath = Path.Combine(DataPath, "metadata"));
  223. }
  224. set
  225. {
  226. _internalMetadataPath = value;
  227. }
  228. }
  229. private const string _virtualInternalMetadataPath = "%MetadataPath%";
  230. public string VirtualInternalMetadataPath
  231. {
  232. get
  233. {
  234. return _virtualInternalMetadataPath;
  235. }
  236. }
  237. }
  238. }