using System.IO;
using MediaBrowser.Common.Configuration;
namespace Emby.Server.Implementations.AppBase
{
///
/// Provides a base class to hold common application paths used by both the Ui and Server.
/// This can be subclassed to add application-specific paths.
///
public abstract class BaseApplicationPaths : IApplicationPaths
{
///
/// Initializes a new instance of the class.
///
protected BaseApplicationPaths(
string programDataPath,
string appFolderPath,
string logDirectoryPath = null,
string configurationDirectoryPath = null,
string cacheDirectoryPath = null)
{
ProgramDataPath = programDataPath;
ProgramSystemPath = appFolderPath;
LogDirectoryPath = logDirectoryPath;
ConfigurationDirectoryPath = configurationDirectoryPath;
CachePath = cacheDirectoryPath;
}
public string ProgramDataPath { get; private set; }
///
/// Gets the path to the system folder
///
public string ProgramSystemPath { get; private set; }
///
/// The _data directory
///
private string _dataDirectory;
///
/// Gets the folder path to the data directory
///
/// The data directory.
public string DataPath
{
get
{
if (_dataDirectory == null)
{
_dataDirectory = Path.Combine(ProgramDataPath, "data");
Directory.CreateDirectory(_dataDirectory);
}
return _dataDirectory;
}
}
private const string _virtualDataPath = "%AppDataPath%";
public string VirtualDataPath => _virtualDataPath;
///
/// Gets the image cache path.
///
/// The image cache path.
public string ImageCachePath => Path.Combine(CachePath, "images");
///
/// Gets the path to the plugin directory
///
/// The plugins path.
public string PluginsPath => Path.Combine(ProgramDataPath, "plugins");
///
/// Gets the path to the plugin configurations directory
///
/// The plugin configurations path.
public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
///
/// Gets the path to where temporary update files will be stored
///
/// The plugin configurations path.
public string TempUpdatePath => Path.Combine(ProgramDataPath, "updates");
///
/// The _log directory
///
private string _logDirectoryPath;
///
/// Gets the path to the log directory
///
/// The log directory path.
public string LogDirectoryPath
{
get
{
if (string.IsNullOrEmpty(_logDirectoryPath))
{
_logDirectoryPath = Path.Combine(ProgramDataPath, "logs");
Directory.CreateDirectory(_logDirectoryPath);
}
return _logDirectoryPath;
}
set => _logDirectoryPath = value;
}
///
/// The _config directory
///
private string _configurationDirectoryPath;
///
/// Gets the path to the application configuration root directory
///
/// The configuration directory path.
public string ConfigurationDirectoryPath
{
get
{
if (string.IsNullOrEmpty(_configurationDirectoryPath))
{
_configurationDirectoryPath = Path.Combine(ProgramDataPath, "config");
Directory.CreateDirectory(_configurationDirectoryPath);
}
return _configurationDirectoryPath;
}
set => _configurationDirectoryPath = value;
}
///
/// Gets the path to the system configuration file
///
/// The system configuration file path.
public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
///
/// The _cache directory
///
private string _cachePath;
///
/// Gets the folder path to the cache directory
///
/// The cache directory.
public string CachePath
{
get
{
if (string.IsNullOrEmpty(_cachePath))
{
_cachePath = Path.Combine(ProgramDataPath, "cache");
Directory.CreateDirectory(_cachePath);
}
return _cachePath;
}
set => _cachePath = value;
}
///
/// Gets the folder path to the temp directory within the cache folder
///
/// The temp directory.
public string TempDirectory => Path.Combine(CachePath, "temp");
}
}