BaseApplicationPaths.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Common.Configuration;
  4. namespace Emby.Server.Implementations.AppBase
  5. {
  6. /// <summary>
  7. /// Provides a base class to hold common application paths used by both the Ui and Server.
  8. /// This can be subclassed to add application-specific paths.
  9. /// </summary>
  10. public abstract class BaseApplicationPaths : IApplicationPaths
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
  14. /// </summary>
  15. protected BaseApplicationPaths(string programDataPath, string appFolderPath)
  16. {
  17. ProgramDataPath = programDataPath;
  18. ProgramSystemPath = appFolderPath;
  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. /// Gets the path to the log directory
  99. /// </summary>
  100. /// <value>The log directory path.</value>
  101. public string LogDirectoryPath
  102. {
  103. get
  104. {
  105. return Path.Combine(ProgramDataPath, "logs");
  106. }
  107. }
  108. /// <summary>
  109. /// Gets the path to the application configuration root directory
  110. /// </summary>
  111. /// <value>The configuration directory path.</value>
  112. public string ConfigurationDirectoryPath
  113. {
  114. get
  115. {
  116. return Path.Combine(ProgramDataPath, "config");
  117. }
  118. }
  119. /// <summary>
  120. /// Gets the path to the system configuration file
  121. /// </summary>
  122. /// <value>The system configuration file path.</value>
  123. public string SystemConfigurationFilePath
  124. {
  125. get
  126. {
  127. return Path.Combine(ConfigurationDirectoryPath, "system.xml");
  128. }
  129. }
  130. /// <summary>
  131. /// The _cache directory
  132. /// </summary>
  133. private string _cachePath;
  134. /// <summary>
  135. /// Gets the folder path to the cache directory
  136. /// </summary>
  137. /// <value>The cache directory.</value>
  138. public string CachePath
  139. {
  140. get
  141. {
  142. if (string.IsNullOrEmpty(_cachePath))
  143. {
  144. _cachePath = Path.Combine(ProgramDataPath, "cache");
  145. Directory.CreateDirectory(_cachePath);
  146. }
  147. return _cachePath;
  148. }
  149. set
  150. {
  151. _cachePath = value;
  152. }
  153. }
  154. /// <summary>
  155. /// Gets the folder path to the temp directory within the cache folder
  156. /// </summary>
  157. /// <value>The temp directory.</value>
  158. public string TempDirectory
  159. {
  160. get
  161. {
  162. return Path.Combine(CachePath, "temp");
  163. }
  164. }
  165. }
  166. }