BaseApplicationPaths.cs 5.2 KB

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