ServerApplicationPaths.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 _FFMpegDirectory = null;
  142. /// <summary>
  143. /// Gets the folder path to ffmpeg
  144. /// </summary>
  145. public string FFMpegDirectory
  146. {
  147. get
  148. {
  149. if (_FFMpegDirectory == null)
  150. {
  151. _FFMpegDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.ProgramDataPath, "FFMpeg");
  152. if (!Directory.Exists(_FFMpegDirectory))
  153. {
  154. Directory.CreateDirectory(_FFMpegDirectory);
  155. }
  156. }
  157. return _FFMpegDirectory;
  158. }
  159. }
  160. private string _FFMpegPath = null;
  161. /// <summary>
  162. /// Gets the path to ffmpeg.exe
  163. /// </summary>
  164. public string FFMpegPath
  165. {
  166. get
  167. {
  168. if (_FFMpegPath == null)
  169. {
  170. string filename = "ffmpeg.exe";
  171. _FFMpegPath = Path.Combine(FFMpegDirectory, filename);
  172. // Always re-extract the first time to handle new versions
  173. if (File.Exists(_FFMpegPath))
  174. {
  175. File.Delete(_FFMpegPath);
  176. }
  177. // Extract exe
  178. using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + filename))
  179. {
  180. using (FileStream fileStream = new FileStream(_FFMpegPath, FileMode.Create))
  181. {
  182. stream.CopyTo(fileStream);
  183. }
  184. }
  185. }
  186. return _FFMpegPath;
  187. }
  188. }
  189. private string _FFProbePath = null;
  190. /// <summary>
  191. /// Gets the path to ffprobe.exe
  192. /// </summary>
  193. public string FFProbePath
  194. {
  195. get
  196. {
  197. if (_FFProbePath == null)
  198. {
  199. string filename = "ffprobe.exe";
  200. _FFProbePath = Path.Combine(FFMpegDirectory, filename);
  201. // Always re-extract the first time to handle new versions
  202. if (File.Exists(_FFProbePath))
  203. {
  204. File.Delete(_FFProbePath);
  205. }
  206. // Extract exe
  207. using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + filename))
  208. {
  209. using (FileStream fileStream = new FileStream(_FFProbePath, FileMode.Create))
  210. {
  211. stream.CopyTo(fileStream);
  212. }
  213. }
  214. }
  215. return _FFProbePath;
  216. }
  217. }
  218. }
  219. }