BaseApplicationPaths.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. private string _dataPath;
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
  15. /// </summary>
  16. /// <param name="programDataPath">The program data path.</param>
  17. /// <param name="logDirectoryPath">The log directory path.</param>
  18. /// <param name="configurationDirectoryPath">The configuration directory path.</param>
  19. /// <param name="cacheDirectoryPath">The cache directory path.</param>
  20. /// <param name="webDirectoryPath">The web directory path.</param>
  21. protected BaseApplicationPaths(
  22. string programDataPath,
  23. string logDirectoryPath,
  24. string configurationDirectoryPath,
  25. string cacheDirectoryPath,
  26. string webDirectoryPath)
  27. {
  28. ProgramDataPath = programDataPath;
  29. LogDirectoryPath = logDirectoryPath;
  30. ConfigurationDirectoryPath = configurationDirectoryPath;
  31. CachePath = cacheDirectoryPath;
  32. WebPath = webDirectoryPath;
  33. _dataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName;
  34. }
  35. /// <summary>
  36. /// Gets the path to the program data folder.
  37. /// </summary>
  38. /// <value>The program data path.</value>
  39. public string ProgramDataPath { get; }
  40. /// <inheritdoc/>
  41. public string WebPath { get; }
  42. /// <summary>
  43. /// Gets the path to the system folder.
  44. /// </summary>
  45. /// <value>The path to the system folder.</value>
  46. public string ProgramSystemPath { get; } = AppContext.BaseDirectory;
  47. /// <summary>
  48. /// Gets the folder path to the data directory.
  49. /// </summary>
  50. /// <value>The data directory.</value>
  51. public string DataPath => _dataPath;
  52. /// <inheritdoc />
  53. public string VirtualDataPath => "%AppDataPath%";
  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 the log directory.
  71. /// </summary>
  72. /// <value>The log directory path.</value>
  73. public string LogDirectoryPath { get; }
  74. /// <summary>
  75. /// Gets the path to the application configuration root directory.
  76. /// </summary>
  77. /// <value>The configuration directory path.</value>
  78. public string ConfigurationDirectoryPath { get; }
  79. /// <summary>
  80. /// Gets the path to the system configuration file.
  81. /// </summary>
  82. /// <value>The system configuration file path.</value>
  83. public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
  84. /// <summary>
  85. /// Gets or sets the folder path to the cache directory.
  86. /// </summary>
  87. /// <value>The cache directory.</value>
  88. public string CachePath { get; set; }
  89. /// <summary>
  90. /// Gets the folder path to the temp directory within the cache folder.
  91. /// </summary>
  92. /// <value>The temp directory.</value>
  93. public string TempDirectory => Path.Combine(CachePath, "temp");
  94. }
  95. }