BaseApplicationPaths.cs 4.9 KB

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