using System;
using System.IO;
using Emby.Server.Implementations.AppBase;
using MediaBrowser.Controller;
namespace Emby.Server.Implementations
{
///
/// Extends BaseApplicationPaths to add paths that are only applicable on the server.
///
public class ServerApplicationPaths : BaseApplicationPaths, IServerApplicationPaths
{
private string _defaultTranscodePath;
private string _transcodePath;
private string _internalMetadataPath;
///
/// Initializes a new instance of the class.
///
public ServerApplicationPaths(
string programDataPath,
string logDirectoryPath,
string configurationDirectoryPath,
string cacheDirectoryPath,
string webDirectoryPath)
: base(programDataPath,
logDirectoryPath,
configurationDirectoryPath,
cacheDirectoryPath,
webDirectoryPath)
{
}
public string ApplicationResourcesPath { get; } = AppContext.BaseDirectory;
///
/// Gets the path to the base root media directory.
///
/// The root folder path.
public string RootFolderPath => Path.Combine(ProgramDataPath, "root");
///
/// Gets the path to the default user view directory. Used if no specific user view is defined.
///
/// The default user views path.
public string DefaultUserViewsPath => Path.Combine(RootFolderPath, "default");
///
/// Gets the path to localization data.
///
/// The localization path.
public string LocalizationPath => Path.Combine(ProgramDataPath, "localization");
///
/// Gets the path to the People directory.
///
/// The people path.
public string PeoplePath => Path.Combine(InternalMetadataPath, "People");
public string ArtistsPath => Path.Combine(InternalMetadataPath, "artists");
///
/// Gets the path to the Genre directory.
///
/// The genre path.
public string GenrePath => Path.Combine(InternalMetadataPath, "Genre");
///
/// Gets the path to the Genre directory.
///
/// The genre path.
public string MusicGenrePath => Path.Combine(InternalMetadataPath, "MusicGenre");
///
/// Gets the path to the Studio directory.
///
/// The studio path.
public string StudioPath => Path.Combine(InternalMetadataPath, "Studio");
///
/// Gets the path to the Year directory.
///
/// The year path.
public string YearPath => Path.Combine(InternalMetadataPath, "Year");
///
/// Gets the path to the General IBN directory.
///
/// The general path.
public string GeneralPath => Path.Combine(InternalMetadataPath, "general");
///
/// Gets the path to the Ratings IBN directory.
///
/// The ratings path.
public string RatingsPath => Path.Combine(InternalMetadataPath, "ratings");
///
/// Gets the media info images path.
///
/// The media info images path.
public string MediaInfoImagesPath => Path.Combine(InternalMetadataPath, "mediainfo");
///
/// Gets the path to the user configuration directory.
///
/// The user configuration directory path.
public string UserConfigurationDirectoryPath => Path.Combine(ConfigurationDirectoryPath, "users");
public string DefaultTranscodePath => _defaultTranscodePath ?? (_defaultTranscodePath = Path.Combine(ProgramDataPath, "transcodes"));
public string TranscodePath
{
get => _transcodePath ?? (_transcodePath = DefaultTranscodePath);
set => _transcodePath = value;
}
public string GetTranscodePath()
{
var path = TranscodePath;
if (!string.Equals(path, DefaultTranscodePath, StringComparison.OrdinalIgnoreCase))
{
try
{
Directory.CreateDirectory(path);
var testPath = Path.Combine(path, Guid.NewGuid().ToString());
Directory.CreateDirectory(testPath);
Directory.Delete(testPath);
return path;
}
catch
{
}
}
path = DefaultTranscodePath;
Directory.CreateDirectory(path);
return path;
}
public string InternalMetadataPath
{
get => _internalMetadataPath ?? (_internalMetadataPath = Path.Combine(DataPath, "metadata"));
set => _internalMetadataPath = value;
}
public string VirtualInternalMetadataPath { get; } = "%MetadataPath%";
}
}