BaseApplicationPaths.cs 4.8 KB

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