BaseApplicationPaths.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. protected BaseApplicationPaths(
  17. string programDataPath,
  18. string logDirectoryPath,
  19. string configurationDirectoryPath,
  20. string cacheDirectoryPath,
  21. string webDirectoryPath)
  22. {
  23. ProgramDataPath = programDataPath;
  24. LogDirectoryPath = logDirectoryPath;
  25. ConfigurationDirectoryPath = configurationDirectoryPath;
  26. CachePath = cacheDirectoryPath;
  27. WebPath = webDirectoryPath;
  28. DataPath = Path.Combine(ProgramDataPath, "data");
  29. }
  30. /// <summary>
  31. /// Gets the path to the program data folder.
  32. /// </summary>
  33. /// <value>The program data path.</value>
  34. public string ProgramDataPath { get; }
  35. /// <summary>
  36. /// Gets the path to the web UI resources folder.
  37. /// </summary>
  38. /// <value>The web UI resources path.</value>
  39. public string WebPath { get; }
  40. /// <summary>
  41. /// Gets the path to the system folder.
  42. /// </summary>
  43. /// <value>The path to the system folder.</value>
  44. public string ProgramSystemPath { get; } = AppContext.BaseDirectory;
  45. /// <summary>
  46. /// Gets the folder path to the data directory.
  47. /// </summary>
  48. /// <value>The data directory.</value>
  49. public string DataPath
  50. {
  51. get => _dataPath;
  52. private set => _dataPath = Directory.CreateDirectory(value).FullName;
  53. }
  54. /// <inheritdoc />
  55. public string VirtualDataPath { get; } = "%AppDataPath%";
  56. /// <summary>
  57. /// Gets the image cache path.
  58. /// </summary>
  59. /// <value>The image cache path.</value>
  60. public string ImageCachePath => Path.Combine(CachePath, "images");
  61. /// <summary>
  62. /// Gets the path to the plugin directory.
  63. /// </summary>
  64. /// <value>The plugins path.</value>
  65. public string PluginsPath => Path.Combine(ProgramDataPath, "plugins");
  66. /// <summary>
  67. /// Gets the path to the plugin configurations directory.
  68. /// </summary>
  69. /// <value>The plugin configurations path.</value>
  70. public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
  71. /// <summary>
  72. /// Gets the path to the log directory.
  73. /// </summary>
  74. /// <value>The log directory path.</value>
  75. public string LogDirectoryPath { get; }
  76. /// <summary>
  77. /// Gets the path to the application configuration root directory.
  78. /// </summary>
  79. /// <value>The configuration directory path.</value>
  80. public string ConfigurationDirectoryPath { get; }
  81. /// <summary>
  82. /// Gets the path to the system configuration file.
  83. /// </summary>
  84. /// <value>The system configuration file path.</value>
  85. public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
  86. /// <summary>
  87. /// Gets or sets the folder path to the cache directory.
  88. /// </summary>
  89. /// <value>The cache directory.</value>
  90. public string CachePath { get; set; }
  91. /// <summary>
  92. /// Gets the folder path to the temp directory within the cache folder.
  93. /// </summary>
  94. /// <value>The temp directory.</value>
  95. public string TempDirectory => Path.Combine(CachePath, "temp");
  96. }
  97. }