| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.IO; |
| | 4 | | using System.Linq; |
| | 5 | | using Jellyfin.Extensions; |
| | 6 | | using MediaBrowser.Common.Configuration; |
| | 7 | |
|
| | 8 | | namespace Emby.Server.Implementations.AppBase |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Provides a base class to hold common application paths used by both the UI and Server. |
| | 12 | | /// This can be subclassed to add application-specific paths. |
| | 13 | | /// </summary> |
| | 14 | | public abstract class BaseApplicationPaths : IApplicationPaths |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="programDataPath">The program data path.</param> |
| | 20 | | /// <param name="logDirectoryPath">The log directory path.</param> |
| | 21 | | /// <param name="configurationDirectoryPath">The configuration directory path.</param> |
| | 22 | | /// <param name="cacheDirectoryPath">The cache directory path.</param> |
| | 23 | | /// <param name="webDirectoryPath">The web directory path.</param> |
| | 24 | | protected BaseApplicationPaths( |
| | 25 | | string programDataPath, |
| | 26 | | string logDirectoryPath, |
| | 27 | | string configurationDirectoryPath, |
| | 28 | | string cacheDirectoryPath, |
| | 29 | | string webDirectoryPath) |
| | 30 | | { |
| | 31 | | ProgramDataPath = programDataPath; |
| | 32 | | LogDirectoryPath = logDirectoryPath; |
| | 33 | | ConfigurationDirectoryPath = configurationDirectoryPath; |
| 21 | 34 | | CachePath = cacheDirectoryPath; |
| | 35 | | WebPath = webDirectoryPath; |
| 21 | 36 | | DataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName; |
| 21 | 37 | | } |
| | 38 | |
|
| | 39 | | /// <inheritdoc/> |
| | 40 | | public string ProgramDataPath { get; } |
| | 41 | |
|
| | 42 | | /// <inheritdoc/> |
| | 43 | | public string WebPath { get; } |
| | 44 | |
|
| | 45 | | /// <inheritdoc/> |
| | 46 | | public string ProgramSystemPath { get; } = AppContext.BaseDirectory; |
| | 47 | |
|
| | 48 | | /// <inheritdoc/> |
| | 49 | | public string DataPath { get; } |
| | 50 | |
|
| | 51 | | /// <inheritdoc /> |
| 177 | 52 | | public string VirtualDataPath => "%AppDataPath%"; |
| | 53 | |
|
| | 54 | | /// <inheritdoc/> |
| 0 | 55 | | public string ImageCachePath => Path.Combine(CachePath, "images"); |
| | 56 | |
|
| | 57 | | /// <inheritdoc/> |
| 294 | 58 | | public string PluginsPath => Path.Combine(ProgramDataPath, "plugins"); |
| | 59 | |
|
| | 60 | | /// <inheritdoc/> |
| 126 | 61 | | public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations"); |
| | 62 | |
|
| | 63 | | /// <inheritdoc/> |
| | 64 | | public string LogDirectoryPath { get; } |
| | 65 | |
|
| | 66 | | /// <inheritdoc/> |
| | 67 | | public string ConfigurationDirectoryPath { get; } |
| | 68 | |
|
| | 69 | | /// <inheritdoc/> |
| 185 | 70 | | public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml"); |
| | 71 | |
|
| | 72 | | /// <inheritdoc/> |
| | 73 | | public string CachePath { get; set; } |
| | 74 | |
|
| | 75 | | /// <inheritdoc/> |
| 72 | 76 | | public string TempDirectory => Path.Join(Path.GetTempPath(), "jellyfin"); |
| | 77 | |
|
| | 78 | | /// <inheritdoc /> |
| 0 | 79 | | public string TrickplayPath => Path.Combine(DataPath, "trickplay"); |
| | 80 | |
|
| | 81 | | /// <inheritdoc /> |
| 0 | 82 | | public string BackupPath => Path.Combine(DataPath, "backups"); |
| | 83 | |
|
| | 84 | | /// <inheritdoc /> |
| | 85 | | public virtual void MakeSanityCheckOrThrow() |
| | 86 | | { |
| 0 | 87 | | CreateAndCheckMarker(ConfigurationDirectoryPath, "config"); |
| 0 | 88 | | CreateAndCheckMarker(LogDirectoryPath, "log"); |
| 0 | 89 | | CreateAndCheckMarker(PluginsPath, "plugin"); |
| 0 | 90 | | CreateAndCheckMarker(ProgramDataPath, "data"); |
| 0 | 91 | | CreateAndCheckMarker(CachePath, "cache"); |
| 0 | 92 | | CreateAndCheckMarker(DataPath, "data"); |
| 0 | 93 | | } |
| | 94 | |
|
| | 95 | | /// <inheritdoc /> |
| | 96 | | public void CreateAndCheckMarker(string path, string markerName, bool recursive = false) |
| | 97 | | { |
| 166 | 98 | | Directory.CreateDirectory(path); |
| | 99 | |
|
| 166 | 100 | | CheckOrCreateMarker(path, $".jellyfin-{markerName}", recursive); |
| 166 | 101 | | } |
| | 102 | |
|
| | 103 | | private IEnumerable<string> GetMarkers(string path, bool recursive = false) |
| | 104 | | { |
| 166 | 105 | | return Directory.EnumerateFiles(path, ".jellyfin-*", recursive ? SearchOption.AllDirectories : SearchOption. |
| | 106 | | } |
| | 107 | |
|
| | 108 | | private void CheckOrCreateMarker(string path, string markerName, bool recursive = false) |
| | 109 | | { |
| 166 | 110 | | var otherMarkers = GetMarkers(path, recursive).FirstOrDefault(e => Path.GetFileName(e) != markerName); |
| 166 | 111 | | if (otherMarkers != null) |
| | 112 | | { |
| 0 | 113 | | throw new InvalidOperationException($"Exepected to find only {markerName} but found marker for {otherMar |
| | 114 | | } |
| | 115 | |
|
| 166 | 116 | | var markerPath = Path.Combine(path, markerName); |
| 166 | 117 | | if (!File.Exists(markerPath)) |
| | 118 | | { |
| 44 | 119 | | FileHelper.CreateEmpty(markerPath); |
| | 120 | | } |
| 166 | 121 | | } |
| | 122 | | } |
| | 123 | | } |