BaseApplicationPaths.cs 5.4 KB

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