BaseApplicationPaths.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System.IO;
  2. using MediaBrowser.Common.Configuration;
  3. namespace Emby.Server.Implementations.AppBase
  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(
  15. string programDataPath,
  16. string appFolderPath,
  17. string logDirectoryPath = null,
  18. string configurationDirectoryPath = null,
  19. string cacheDirectoryPath = null)
  20. {
  21. ProgramDataPath = programDataPath;
  22. ProgramSystemPath = appFolderPath;
  23. LogDirectoryPath = logDirectoryPath;
  24. ConfigurationDirectoryPath = configurationDirectoryPath;
  25. CachePath = cacheDirectoryPath;
  26. }
  27. public string ProgramDataPath { get; private set; }
  28. /// <summary>
  29. /// Gets the path to the system folder
  30. /// </summary>
  31. public string ProgramSystemPath { get; private set; }
  32. /// <summary>
  33. /// The _data directory
  34. /// </summary>
  35. private string _dataDirectory;
  36. /// <summary>
  37. /// Gets the folder path to the data directory
  38. /// </summary>
  39. /// <value>The data directory.</value>
  40. public string DataPath
  41. {
  42. get
  43. {
  44. if (_dataDirectory == null)
  45. {
  46. _dataDirectory = Path.Combine(ProgramDataPath, "data");
  47. Directory.CreateDirectory(_dataDirectory);
  48. }
  49. return _dataDirectory;
  50. }
  51. }
  52. private const string _virtualDataPath = "%AppDataPath%";
  53. public string VirtualDataPath => _virtualDataPath;
  54. /// <summary>
  55. /// Gets the image cache path.
  56. /// </summary>
  57. /// <value>The image cache path.</value>
  58. public string ImageCachePath => Path.Combine(CachePath, "images");
  59. /// <summary>
  60. /// Gets the path to the plugin directory
  61. /// </summary>
  62. /// <value>The plugins path.</value>
  63. public string PluginsPath => Path.Combine(ProgramDataPath, "plugins");
  64. /// <summary>
  65. /// Gets the path to the plugin configurations directory
  66. /// </summary>
  67. /// <value>The plugin configurations path.</value>
  68. public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
  69. /// <summary>
  70. /// Gets the path to where temporary update files will be stored
  71. /// </summary>
  72. /// <value>The plugin configurations path.</value>
  73. public string TempUpdatePath => Path.Combine(ProgramDataPath, "updates");
  74. /// <summary>
  75. /// The _log directory
  76. /// </summary>
  77. private string _logDirectoryPath;
  78. /// <summary>
  79. /// Gets the path to the log directory
  80. /// </summary>
  81. /// <value>The log directory path.</value>
  82. public string LogDirectoryPath
  83. {
  84. get
  85. {
  86. if (string.IsNullOrEmpty(_logDirectoryPath))
  87. {
  88. _logDirectoryPath = Path.Combine(ProgramDataPath, "logs");
  89. Directory.CreateDirectory(_logDirectoryPath);
  90. }
  91. return _logDirectoryPath;
  92. }
  93. set => _logDirectoryPath = value;
  94. }
  95. /// <summary>
  96. /// The _config directory
  97. /// </summary>
  98. private string _configurationDirectoryPath;
  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. if (string.IsNullOrEmpty(_configurationDirectoryPath))
  108. {
  109. _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config");
  110. Directory.CreateDirectory(_configurationDirectoryPath);
  111. }
  112. return _configurationDirectoryPath;
  113. }
  114. set => _configurationDirectoryPath = value;
  115. }
  116. /// <summary>
  117. /// Gets the path to the system configuration file
  118. /// </summary>
  119. /// <value>The system configuration file path.</value>
  120. public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
  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 => _cachePath = value;
  141. }
  142. /// <summary>
  143. /// Gets the folder path to the temp directory within the cache folder
  144. /// </summary>
  145. /// <value>The temp directory.</value>
  146. public string TempDirectory => Path.Combine(CachePath, "temp");
  147. }
  148. }