BaseApplicationPaths.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /// <summary>
  46. /// Gets the image cache path.
  47. /// </summary>
  48. /// <value>The image cache path.</value>
  49. public string ImageCachePath
  50. {
  51. get
  52. {
  53. return Path.Combine(CachePath, "images");
  54. }
  55. }
  56. /// <summary>
  57. /// Gets the path to the plugin directory
  58. /// </summary>
  59. /// <value>The plugins path.</value>
  60. public string PluginsPath
  61. {
  62. get
  63. {
  64. return Path.Combine(ProgramDataPath, "plugins");
  65. }
  66. }
  67. /// <summary>
  68. /// Gets the path to the plugin configurations directory
  69. /// </summary>
  70. /// <value>The plugin configurations path.</value>
  71. public string PluginConfigurationsPath
  72. {
  73. get
  74. {
  75. return Path.Combine(PluginsPath, "configurations");
  76. }
  77. }
  78. /// <summary>
  79. /// Gets the path to where temporary update files will be stored
  80. /// </summary>
  81. /// <value>The plugin configurations path.</value>
  82. public string TempUpdatePath
  83. {
  84. get
  85. {
  86. return Path.Combine(ProgramDataPath, "updates");
  87. }
  88. }
  89. /// <summary>
  90. /// Gets the path to the log directory
  91. /// </summary>
  92. /// <value>The log directory path.</value>
  93. public string LogDirectoryPath
  94. {
  95. get
  96. {
  97. return Path.Combine(ProgramDataPath, "logs");
  98. }
  99. }
  100. /// <summary>
  101. /// Gets the path to the application configuration root directory
  102. /// </summary>
  103. /// <value>The configuration directory path.</value>
  104. public string ConfigurationDirectoryPath
  105. {
  106. get
  107. {
  108. return Path.Combine(ProgramDataPath, "config");
  109. }
  110. }
  111. /// <summary>
  112. /// Gets the path to the system configuration file
  113. /// </summary>
  114. /// <value>The system configuration file path.</value>
  115. public string SystemConfigurationFilePath
  116. {
  117. get
  118. {
  119. return Path.Combine(ConfigurationDirectoryPath, "system.xml");
  120. }
  121. }
  122. /// <summary>
  123. /// The _cache directory
  124. /// </summary>
  125. private string _cachePath;
  126. /// <summary>
  127. /// Gets the folder path to the cache directory
  128. /// </summary>
  129. /// <value>The cache directory.</value>
  130. public string CachePath
  131. {
  132. get
  133. {
  134. if (string.IsNullOrEmpty(_cachePath))
  135. {
  136. _cachePath = Path.Combine(ProgramDataPath, "cache");
  137. Directory.CreateDirectory(_cachePath);
  138. }
  139. return _cachePath;
  140. }
  141. set
  142. {
  143. _cachePath = value;
  144. }
  145. }
  146. /// <summary>
  147. /// Gets the folder path to the temp directory within the cache folder
  148. /// </summary>
  149. /// <value>The temp directory.</value>
  150. public string TempDirectory
  151. {
  152. get
  153. {
  154. return Path.Combine(CachePath, "temp");
  155. }
  156. }
  157. }
  158. }