2
0

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