2
0

BaseApplicationPaths.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System.IO;
  2. using MediaBrowser.Common.Configuration;
  3. namespace Emby.Server.Implementations.AppBase
  4. {
  5. /// <summary>
  6. /// Provides a base class to hold common application paths used by both the Ui and Server.
  7. /// This can be subclassed to add application-specific paths.
  8. /// </summary>
  9. public abstract class BaseApplicationPaths : IApplicationPaths
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
  13. /// </summary>
  14. protected BaseApplicationPaths(
  15. string programDataPath,
  16. string appFolderPath,
  17. string logDirectoryPath = null,
  18. string configurationDirectoryPath = null)
  19. {
  20. ProgramDataPath = programDataPath;
  21. ProgramSystemPath = appFolderPath;
  22. LogDirectoryPath = logDirectoryPath;
  23. ConfigurationDirectoryPath = configurationDirectoryPath;
  24. }
  25. public string ProgramDataPath { get; private set; }
  26. /// <summary>
  27. /// Gets the path to the system folder
  28. /// </summary>
  29. public string ProgramSystemPath { get; private set; }
  30. /// <summary>
  31. /// The _data directory
  32. /// </summary>
  33. private string _dataDirectory;
  34. /// <summary>
  35. /// Gets the folder path to the data directory
  36. /// </summary>
  37. /// <value>The data directory.</value>
  38. public string DataPath
  39. {
  40. get
  41. {
  42. if (_dataDirectory == null)
  43. {
  44. _dataDirectory = Path.Combine(ProgramDataPath, "data");
  45. Directory.CreateDirectory(_dataDirectory);
  46. }
  47. return _dataDirectory;
  48. }
  49. }
  50. private const string _virtualDataPath = "%AppDataPath%";
  51. public string VirtualDataPath
  52. {
  53. get
  54. {
  55. return _virtualDataPath;
  56. }
  57. }
  58. /// <summary>
  59. /// Gets the image cache path.
  60. /// </summary>
  61. /// <value>The image cache path.</value>
  62. public string ImageCachePath
  63. {
  64. get
  65. {
  66. return Path.Combine(CachePath, "images");
  67. }
  68. }
  69. /// <summary>
  70. /// Gets the path to the plugin directory
  71. /// </summary>
  72. /// <value>The plugins path.</value>
  73. public string PluginsPath
  74. {
  75. get
  76. {
  77. return Path.Combine(ProgramDataPath, "plugins");
  78. }
  79. }
  80. /// <summary>
  81. /// Gets the path to the plugin configurations directory
  82. /// </summary>
  83. /// <value>The plugin configurations path.</value>
  84. public string PluginConfigurationsPath
  85. {
  86. get
  87. {
  88. return Path.Combine(PluginsPath, "configurations");
  89. }
  90. }
  91. /// <summary>
  92. /// Gets the path to where temporary update files will be stored
  93. /// </summary>
  94. /// <value>The plugin configurations path.</value>
  95. public string TempUpdatePath
  96. {
  97. get
  98. {
  99. return Path.Combine(ProgramDataPath, "updates");
  100. }
  101. }
  102. /// <summary>
  103. /// The _log directory
  104. /// </summary>
  105. private string _logDirectoryPath;
  106. /// <summary>
  107. /// Gets the path to the log directory
  108. /// </summary>
  109. /// <value>The log directory path.</value>
  110. public string LogDirectoryPath
  111. {
  112. get
  113. {
  114. if (string.IsNullOrEmpty(_logDirectoryPath))
  115. {
  116. _logDirectoryPath = Path.Combine(ProgramDataPath, "logs");
  117. Directory.CreateDirectory(_logDirectoryPath);
  118. }
  119. return _logDirectoryPath;
  120. }
  121. set
  122. {
  123. _logDirectoryPath = value;
  124. }
  125. }
  126. /// <summary>
  127. /// The _config directory
  128. /// </summary>
  129. private string _configurationDirectoryPath;
  130. /// <summary>
  131. /// Gets the path to the application configuration root directory
  132. /// </summary>
  133. /// <value>The configuration directory path.</value>
  134. public string ConfigurationDirectoryPath
  135. {
  136. get
  137. {
  138. if (string.IsNullOrEmpty(_configurationDirectoryPath))
  139. {
  140. _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config");
  141. Directory.CreateDirectory(_configurationDirectoryPath);
  142. }
  143. return _configurationDirectoryPath;
  144. }
  145. set
  146. {
  147. _configurationDirectoryPath = value;
  148. }
  149. }
  150. /// <summary>
  151. /// Gets the path to the system configuration file
  152. /// </summary>
  153. /// <value>The system configuration file path.</value>
  154. public string SystemConfigurationFilePath
  155. {
  156. get
  157. {
  158. return Path.Combine(ConfigurationDirectoryPath, "system.xml");
  159. }
  160. }
  161. /// <summary>
  162. /// The _cache directory
  163. /// </summary>
  164. private string _cachePath;
  165. /// <summary>
  166. /// Gets the folder path to the cache directory
  167. /// </summary>
  168. /// <value>The cache directory.</value>
  169. public string CachePath
  170. {
  171. get
  172. {
  173. if (string.IsNullOrEmpty(_cachePath))
  174. {
  175. _cachePath = Path.Combine(ProgramDataPath, "cache");
  176. Directory.CreateDirectory(_cachePath);
  177. }
  178. return _cachePath;
  179. }
  180. set
  181. {
  182. _cachePath = value;
  183. }
  184. }
  185. /// <summary>
  186. /// Gets the folder path to the temp directory within the cache folder
  187. /// </summary>
  188. /// <value>The temp directory.</value>
  189. public string TempDirectory
  190. {
  191. get
  192. {
  193. return Path.Combine(CachePath, "temp");
  194. }
  195. }
  196. }
  197. }