BaseApplicationPaths.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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(string programDataPath, string appFolderPath, string logDirectoryPath)
  15. {
  16. ProgramDataPath = programDataPath;
  17. ProgramSystemPath = appFolderPath;
  18. LogDirectoryPath = logDirectoryPath;
  19. }
  20. public string ProgramDataPath { get; private set; }
  21. /// <summary>
  22. /// Gets the path to the system folder
  23. /// </summary>
  24. public string ProgramSystemPath { get; private set; }
  25. /// <summary>
  26. /// The _data directory
  27. /// </summary>
  28. private string _dataDirectory;
  29. /// <summary>
  30. /// Gets the folder path to the data directory
  31. /// </summary>
  32. /// <value>The data directory.</value>
  33. public string DataPath
  34. {
  35. get
  36. {
  37. if (_dataDirectory == null)
  38. {
  39. _dataDirectory = Path.Combine(ProgramDataPath, "data");
  40. Directory.CreateDirectory(_dataDirectory);
  41. }
  42. return _dataDirectory;
  43. }
  44. }
  45. private const string _virtualDataPath = "%AppDataPath%";
  46. public string VirtualDataPath
  47. {
  48. get
  49. {
  50. return _virtualDataPath;
  51. }
  52. }
  53. /// <summary>
  54. /// Gets the image cache path.
  55. /// </summary>
  56. /// <value>The image cache path.</value>
  57. public string ImageCachePath
  58. {
  59. get
  60. {
  61. return Path.Combine(CachePath, "images");
  62. }
  63. }
  64. /// <summary>
  65. /// Gets the path to the plugin directory
  66. /// </summary>
  67. /// <value>The plugins path.</value>
  68. public string PluginsPath
  69. {
  70. get
  71. {
  72. return Path.Combine(ProgramDataPath, "plugins");
  73. }
  74. }
  75. /// <summary>
  76. /// Gets the path to the plugin configurations directory
  77. /// </summary>
  78. /// <value>The plugin configurations path.</value>
  79. public string PluginConfigurationsPath
  80. {
  81. get
  82. {
  83. return Path.Combine(PluginsPath, "configurations");
  84. }
  85. }
  86. /// <summary>
  87. /// Gets the path to where temporary update files will be stored
  88. /// </summary>
  89. /// <value>The plugin configurations path.</value>
  90. public string TempUpdatePath
  91. {
  92. get
  93. {
  94. return Path.Combine(ProgramDataPath, "updates");
  95. }
  96. }
  97. /// <summary>
  98. /// The _log directory
  99. /// </summary>
  100. private string _logDirectoryPath;
  101. /// <summary>
  102. /// Gets the path to the log directory
  103. /// </summary>
  104. /// <value>The log directory path.</value>
  105. public string LogDirectoryPath
  106. {
  107. get
  108. {
  109. if (string.IsNullOrEmpty(_logDirectoryPath))
  110. {
  111. _logDirectoryPath = Path.Combine(ProgramDataPath, "logs");
  112. Directory.CreateDirectory(_logDirectoryPath);
  113. }
  114. return _logDirectoryPath;
  115. }
  116. set
  117. {
  118. _logDirectoryPath = value;
  119. }
  120. }
  121. /// <summary>
  122. /// Gets the path to the application configuration root directory
  123. /// </summary>
  124. /// <value>The configuration directory path.</value>
  125. public string ConfigurationDirectoryPath
  126. {
  127. get
  128. {
  129. return Path.Combine(ProgramDataPath, "config");
  130. }
  131. }
  132. /// <summary>
  133. /// Gets the path to the system configuration file
  134. /// </summary>
  135. /// <value>The system configuration file path.</value>
  136. public string SystemConfigurationFilePath
  137. {
  138. get
  139. {
  140. return Path.Combine(ConfigurationDirectoryPath, "system.xml");
  141. }
  142. }
  143. /// <summary>
  144. /// The _cache directory
  145. /// </summary>
  146. private string _cachePath;
  147. /// <summary>
  148. /// Gets the folder path to the cache directory
  149. /// </summary>
  150. /// <value>The cache directory.</value>
  151. public string CachePath
  152. {
  153. get
  154. {
  155. if (string.IsNullOrEmpty(_cachePath))
  156. {
  157. _cachePath = Path.Combine(ProgramDataPath, "cache");
  158. Directory.CreateDirectory(_cachePath);
  159. }
  160. return _cachePath;
  161. }
  162. set
  163. {
  164. _cachePath = value;
  165. }
  166. }
  167. /// <summary>
  168. /// Gets the folder path to the temp directory within the cache folder
  169. /// </summary>
  170. /// <value>The temp directory.</value>
  171. public string TempDirectory
  172. {
  173. get
  174. {
  175. return Path.Combine(CachePath, "temp");
  176. }
  177. }
  178. }
  179. }