BaseApplicationPaths.cs 4.9 KB

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