BaseApplicationPaths.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Controller.Extensions;
  5. using Microsoft.Extensions.Configuration;
  6. namespace Emby.Server.Implementations.AppBase
  7. {
  8. /// <summary>
  9. /// Provides a base class to hold common application paths used by both the UI and Server.
  10. /// This can be subclassed to add application-specific paths.
  11. /// </summary>
  12. public abstract class BaseApplicationPaths : IApplicationPaths
  13. {
  14. private string _dataPath;
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
  17. /// </summary>
  18. protected BaseApplicationPaths(
  19. string programDataPath,
  20. string logDirectoryPath,
  21. string configurationDirectoryPath,
  22. string cacheDirectoryPath,
  23. string webDirectoryPath)
  24. {
  25. ProgramDataPath = programDataPath;
  26. LogDirectoryPath = logDirectoryPath;
  27. ConfigurationDirectoryPath = configurationDirectoryPath;
  28. CachePath = cacheDirectoryPath;
  29. WebPath = webDirectoryPath;
  30. DataPath = Path.Combine(ProgramDataPath, "data");
  31. }
  32. /// <summary>
  33. /// Gets the path to the program data folder.
  34. /// </summary>
  35. /// <value>The program data path.</value>
  36. public string ProgramDataPath { get; }
  37. /// <summary>
  38. /// Gets the path to the web UI resources folder.
  39. /// </summary>
  40. /// <value>The web UI resources path.</value>
  41. /// <remarks>
  42. /// This value is not relevant if <see cref="ConfigurationExtensions.IsNoWebContent(IConfiguration)"/> is true.
  43. /// </remarks>
  44. public string WebPath { get; }
  45. /// <summary>
  46. /// Gets the path to the system folder.
  47. /// </summary>
  48. /// <value>The path to the system folder.</value>
  49. public string ProgramSystemPath { get; } = AppContext.BaseDirectory;
  50. /// <summary>
  51. /// Gets the folder path to the data directory.
  52. /// </summary>
  53. /// <value>The data directory.</value>
  54. public string DataPath
  55. {
  56. get => _dataPath;
  57. private set => _dataPath = Directory.CreateDirectory(value).FullName;
  58. }
  59. /// <inheritdoc />
  60. public string VirtualDataPath { get; } = "%AppDataPath%";
  61. /// <summary>
  62. /// Gets the image cache path.
  63. /// </summary>
  64. /// <value>The image cache path.</value>
  65. public string ImageCachePath => Path.Combine(CachePath, "images");
  66. /// <summary>
  67. /// Gets the path to the plugin directory.
  68. /// </summary>
  69. /// <value>The plugins path.</value>
  70. public string PluginsPath => Path.Combine(ProgramDataPath, "plugins");
  71. /// <summary>
  72. /// Gets the path to the plugin configurations directory.
  73. /// </summary>
  74. /// <value>The plugin configurations path.</value>
  75. public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
  76. /// <summary>
  77. /// Gets the path to the log directory.
  78. /// </summary>
  79. /// <value>The log directory path.</value>
  80. public string LogDirectoryPath { get; }
  81. /// <summary>
  82. /// Gets the path to the application configuration root directory.
  83. /// </summary>
  84. /// <value>The configuration directory path.</value>
  85. public string ConfigurationDirectoryPath { get; }
  86. /// <summary>
  87. /// Gets the path to the system configuration file.
  88. /// </summary>
  89. /// <value>The system configuration file path.</value>
  90. public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
  91. /// <summary>
  92. /// Gets or sets the folder path to the cache directory.
  93. /// </summary>
  94. /// <value>The cache directory.</value>
  95. public string CachePath { get; set; }
  96. /// <summary>
  97. /// Gets the folder path to the temp directory within the cache folder.
  98. /// </summary>
  99. /// <value>The temp directory.</value>
  100. public string TempDirectory => Path.Combine(CachePath, "temp");
  101. }
  102. }