2019-02-13 15:35:14 +00:00
|
|
|
using System;
|
2025-04-26 18:30:25 +03:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 20:54:44 +01:00
|
|
|
using System.IO;
|
2025-04-26 18:30:25 +03:00
|
|
|
using System.Linq;
|
2025-05-04 16:40:34 +02:00
|
|
|
using Jellyfin.Extensions;
|
2016-10-29 01:40:15 -04:00
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
|
|
2017-02-20 15:50:58 -05:00
|
|
|
namespace Emby.Server.Implementations.AppBase
|
2016-10-29 01:40:15 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-03-15 12:59:34 +01:00
|
|
|
/// Provides a base class to hold common application paths used by both the UI and Server.
|
2016-10-29 01:40:15 -04:00
|
|
|
/// This can be subclassed to add application-specific paths.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class BaseApplicationPaths : IApplicationPaths
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
|
|
|
|
|
/// </summary>
|
2020-04-14 15:08:20 -04:00
|
|
|
/// <param name="programDataPath">The program data path.</param>
|
|
|
|
|
/// <param name="logDirectoryPath">The log directory path.</param>
|
|
|
|
|
/// <param name="configurationDirectoryPath">The configuration directory path.</param>
|
|
|
|
|
/// <param name="cacheDirectoryPath">The cache directory path.</param>
|
|
|
|
|
/// <param name="webDirectoryPath">The web directory path.</param>
|
2019-01-05 19:12:05 +01:00
|
|
|
protected BaseApplicationPaths(
|
|
|
|
|
string programDataPath,
|
2019-02-13 15:35:14 +00:00
|
|
|
string logDirectoryPath,
|
|
|
|
|
string configurationDirectoryPath,
|
2019-03-10 16:17:48 -04:00
|
|
|
string cacheDirectoryPath,
|
|
|
|
|
string webDirectoryPath)
|
2016-10-29 01:40:15 -04:00
|
|
|
{
|
|
|
|
|
ProgramDataPath = programDataPath;
|
2019-01-01 21:34:12 +01:00
|
|
|
LogDirectoryPath = logDirectoryPath;
|
2019-01-05 19:12:05 +01:00
|
|
|
ConfigurationDirectoryPath = configurationDirectoryPath;
|
2019-01-28 17:52:56 +01:00
|
|
|
CachePath = cacheDirectoryPath;
|
2019-03-10 16:17:48 -04:00
|
|
|
WebPath = webDirectoryPath;
|
2023-10-08 00:40:58 +02:00
|
|
|
DataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName;
|
2016-10-29 01:40:15 -04:00
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-08-09 23:50:40 +02:00
|
|
|
public string ProgramDataPath { get; }
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2020-03-15 17:42:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-08-09 23:50:40 +02:00
|
|
|
public string WebPath { get; }
|
2019-03-10 17:04:18 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-02-13 15:35:14 +00:00
|
|
|
public string ProgramSystemPath { get; } = AppContext.BaseDirectory;
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2023-10-08 00:40:58 +02:00
|
|
|
public string DataPath { get; }
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2019-10-09 17:10:16 +02:00
|
|
|
/// <inheritdoc />
|
2020-10-17 16:01:36 +02:00
|
|
|
public string VirtualDataPath => "%AppDataPath%";
|
2018-09-12 19:26:21 +02:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-01-06 21:50:43 +01:00
|
|
|
public string ImageCachePath => Path.Combine(CachePath, "images");
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-01-06 21:50:43 +01:00
|
|
|
public string PluginsPath => Path.Combine(ProgramDataPath, "plugins");
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-01-06 21:50:43 +01:00
|
|
|
public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-08-09 23:50:40 +02:00
|
|
|
public string LogDirectoryPath { get; }
|
2019-01-05 19:12:05 +01:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-08-09 23:50:40 +02:00
|
|
|
public string ConfigurationDirectoryPath { get; }
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-01-06 21:50:43 +01:00
|
|
|
public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2019-02-13 15:35:14 +00:00
|
|
|
public string CachePath { get; set; }
|
2016-10-29 01:40:15 -04:00
|
|
|
|
2025-01-22 18:20:57 +01:00
|
|
|
/// <inheritdoc/>
|
2024-07-15 14:44:14 +02:00
|
|
|
public string TempDirectory => Path.Join(Path.GetTempPath(), "jellyfin");
|
2025-01-22 18:20:57 +01:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string TrickplayPath => Path.Combine(DataPath, "trickplay");
|
2025-04-26 18:30:25 +03:00
|
|
|
|
2025-05-19 03:39:04 +03:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string BackupPath => Path.Combine(DataPath, "backups");
|
|
|
|
|
|
2025-04-26 18:30:25 +03:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public virtual void MakeSanityCheckOrThrow()
|
|
|
|
|
{
|
|
|
|
|
CreateAndCheckMarker(ConfigurationDirectoryPath, "config");
|
|
|
|
|
CreateAndCheckMarker(LogDirectoryPath, "log");
|
|
|
|
|
CreateAndCheckMarker(PluginsPath, "plugin");
|
|
|
|
|
CreateAndCheckMarker(ProgramDataPath, "data");
|
|
|
|
|
CreateAndCheckMarker(CachePath, "cache");
|
|
|
|
|
CreateAndCheckMarker(DataPath, "data");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void CreateAndCheckMarker(string path, string markerName, bool recursive = false)
|
|
|
|
|
{
|
2025-05-04 16:40:34 +02:00
|
|
|
Directory.CreateDirectory(path);
|
2025-04-26 18:30:25 +03:00
|
|
|
|
|
|
|
|
CheckOrCreateMarker(path, $".jellyfin-{markerName}", recursive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetMarkers(string path, bool recursive = false)
|
|
|
|
|
{
|
|
|
|
|
return Directory.EnumerateFiles(path, ".jellyfin-*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckOrCreateMarker(string path, string markerName, bool recursive = false)
|
|
|
|
|
{
|
|
|
|
|
var otherMarkers = GetMarkers(path, recursive).FirstOrDefault(e => Path.GetFileName(e) != markerName);
|
|
|
|
|
if (otherMarkers != null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException($"Exepected to find only {markerName} but found marker for {otherMarkers}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var markerPath = Path.Combine(path, markerName);
|
|
|
|
|
if (!File.Exists(markerPath))
|
|
|
|
|
{
|
2025-05-04 16:40:34 +02:00
|
|
|
FileHelper.CreateEmpty(markerPath);
|
2025-04-26 18:30:25 +03:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-29 01:40:15 -04:00
|
|
|
}
|
|
|
|
|
}
|