BaseApplicationPaths.cs 4.1 KB

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