ServerApplicationPaths.cs 7.0 KB

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