ServerApplicationPaths.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System.IO;
  2. using System.Reflection;
  3. using MediaBrowser.Common.Configuration;
  4. namespace MediaBrowser.Controller.Configuration
  5. {
  6. public class ServerApplicationPaths : BaseApplicationPaths
  7. {
  8. private string _rootFolderPath;
  9. /// <summary>
  10. /// Gets the path to the root media directory
  11. /// </summary>
  12. public string RootFolderPath
  13. {
  14. get
  15. {
  16. if (_rootFolderPath == null)
  17. {
  18. _rootFolderPath = Path.Combine(ProgramDataPath, "root");
  19. if (!Directory.Exists(_rootFolderPath))
  20. {
  21. Directory.CreateDirectory(_rootFolderPath);
  22. }
  23. }
  24. return _rootFolderPath;
  25. }
  26. }
  27. private string _ibnPath;
  28. /// <summary>
  29. /// Gets the path to the Images By Name directory
  30. /// </summary>
  31. public string ImagesByNamePath
  32. {
  33. get
  34. {
  35. if (_ibnPath == null)
  36. {
  37. _ibnPath = Path.Combine(ProgramDataPath, "ImagesByName");
  38. if (!Directory.Exists(_ibnPath))
  39. {
  40. Directory.CreateDirectory(_ibnPath);
  41. }
  42. }
  43. return _ibnPath;
  44. }
  45. }
  46. private string _PeoplePath;
  47. /// <summary>
  48. /// Gets the path to the People directory
  49. /// </summary>
  50. public string PeoplePath
  51. {
  52. get
  53. {
  54. if (_PeoplePath == null)
  55. {
  56. _PeoplePath = Path.Combine(ImagesByNamePath, "People");
  57. if (!Directory.Exists(_PeoplePath))
  58. {
  59. Directory.CreateDirectory(_PeoplePath);
  60. }
  61. }
  62. return _PeoplePath;
  63. }
  64. }
  65. private string _GenrePath;
  66. /// <summary>
  67. /// Gets the path to the Genre directory
  68. /// </summary>
  69. public string GenrePath
  70. {
  71. get
  72. {
  73. if (_GenrePath == null)
  74. {
  75. _GenrePath = Path.Combine(ImagesByNamePath, "Genre");
  76. if (!Directory.Exists(_GenrePath))
  77. {
  78. Directory.CreateDirectory(_GenrePath);
  79. }
  80. }
  81. return _GenrePath;
  82. }
  83. }
  84. private string _StudioPath;
  85. /// <summary>
  86. /// Gets the path to the Studio directory
  87. /// </summary>
  88. public string StudioPath
  89. {
  90. get
  91. {
  92. if (_StudioPath == null)
  93. {
  94. _StudioPath = Path.Combine(ImagesByNamePath, "Studio");
  95. if (!Directory.Exists(_StudioPath))
  96. {
  97. Directory.CreateDirectory(_StudioPath);
  98. }
  99. }
  100. return _StudioPath;
  101. }
  102. }
  103. private string _yearPath;
  104. /// <summary>
  105. /// Gets the path to the Year directory
  106. /// </summary>
  107. public string YearPath
  108. {
  109. get
  110. {
  111. if (_yearPath == null)
  112. {
  113. _yearPath = Path.Combine(ImagesByNamePath, "Year");
  114. if (!Directory.Exists(_yearPath))
  115. {
  116. Directory.CreateDirectory(_yearPath);
  117. }
  118. }
  119. return _yearPath;
  120. }
  121. }
  122. private string _userConfigurationDirectoryPath;
  123. /// <summary>
  124. /// Gets the path to the user configuration directory
  125. /// </summary>
  126. public string UserConfigurationDirectoryPath
  127. {
  128. get
  129. {
  130. if (_userConfigurationDirectoryPath == null)
  131. {
  132. _userConfigurationDirectoryPath = Path.Combine(ConfigurationDirectoryPath, "user");
  133. if (!Directory.Exists(_userConfigurationDirectoryPath))
  134. {
  135. Directory.CreateDirectory(_userConfigurationDirectoryPath);
  136. }
  137. }
  138. return _userConfigurationDirectoryPath;
  139. }
  140. }
  141. private string _CacheDirectory = null;
  142. /// <summary>
  143. /// Gets the folder path to the cache directory
  144. /// </summary>
  145. public string CacheDirectory
  146. {
  147. get
  148. {
  149. if (_CacheDirectory == null)
  150. {
  151. _CacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "cache");
  152. if (!Directory.Exists(_CacheDirectory))
  153. {
  154. Directory.CreateDirectory(_CacheDirectory);
  155. }
  156. }
  157. return _CacheDirectory;
  158. }
  159. }
  160. private string _FFProbeAudioCacheDirectory = null;
  161. /// <summary>
  162. /// Gets the folder path to the ffprobe audio cache directory
  163. /// </summary>
  164. public string FFProbeAudioCacheDirectory
  165. {
  166. get
  167. {
  168. if (_FFProbeAudioCacheDirectory == null)
  169. {
  170. _FFProbeAudioCacheDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.CacheDirectory, "ffprobe-audio");
  171. if (!Directory.Exists(_FFProbeAudioCacheDirectory))
  172. {
  173. Directory.CreateDirectory(_FFProbeAudioCacheDirectory);
  174. }
  175. }
  176. return _FFProbeAudioCacheDirectory;
  177. }
  178. }
  179. private string _FFMpegDirectory = null;
  180. /// <summary>
  181. /// Gets the folder path to ffmpeg
  182. /// </summary>
  183. public string FFMpegDirectory
  184. {
  185. get
  186. {
  187. if (_FFMpegDirectory == null)
  188. {
  189. _FFMpegDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "FFMpeg");
  190. if (!Directory.Exists(_FFMpegDirectory))
  191. {
  192. Directory.CreateDirectory(_FFMpegDirectory);
  193. }
  194. }
  195. return _FFMpegDirectory;
  196. }
  197. }
  198. private string _FFMpegPath = null;
  199. /// <summary>
  200. /// Gets the path to ffmpeg.exe
  201. /// </summary>
  202. public string FFMpegPath
  203. {
  204. get
  205. {
  206. if (_FFMpegPath == null)
  207. {
  208. string filename = "ffmpeg.exe";
  209. _FFMpegPath = Path.Combine(FFMpegDirectory, filename);
  210. // Always re-extract the first time to handle new versions
  211. if (File.Exists(_FFMpegPath))
  212. {
  213. File.Delete(_FFMpegPath);
  214. }
  215. // Extract exe
  216. using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + filename))
  217. {
  218. using (FileStream fileStream = new FileStream(_FFMpegPath, FileMode.Create))
  219. {
  220. stream.CopyTo(fileStream);
  221. }
  222. }
  223. }
  224. return _FFMpegPath;
  225. }
  226. }
  227. private string _FFProbePath = null;
  228. /// <summary>
  229. /// Gets the path to ffprobe.exe
  230. /// </summary>
  231. public string FFProbePath
  232. {
  233. get
  234. {
  235. if (_FFProbePath == null)
  236. {
  237. string filename = "ffprobe.exe";
  238. _FFProbePath = Path.Combine(FFMpegDirectory, filename);
  239. /*// Always re-extract the first time to handle new versions
  240. if (File.Exists(_FFProbePath))
  241. {
  242. File.Delete(_FFProbePath);
  243. }
  244. // Extract exe
  245. using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + filename))
  246. {
  247. using (FileStream fileStream = new FileStream(_FFProbePath, FileMode.Create))
  248. {
  249. stream.CopyTo(fileStream);
  250. }
  251. }*/
  252. }
  253. return _FFProbePath;
  254. }
  255. }
  256. }
  257. }