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