You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Common/Plugins/BasePlugin.cs

50 lines
1.2 KiB

using System.IO;
using MediaBrowser.Common.Json;
namespace MediaBrowser.Common.Plugins
{
public abstract class BasePlugin<TConfigurationType> : IPlugin
where TConfigurationType : BasePluginConfiguration, new()
{
public string Path { get; set; }
public TConfigurationType Configuration { get; private set; }
private string ConfigurationPath
{
get
{
return System.IO.Path.Combine(Path, "config.js");
}
}
public void Init()
{
Configuration = GetConfiguration();
if (Configuration.Enabled)
{
InitInternal();
}
}
protected abstract void InitInternal();
private TConfigurationType GetConfiguration()
{
if (!File.Exists(ConfigurationPath))
{
return new TConfigurationType();
}
return JsonSerializer.DeserializeFromFile<TConfigurationType>(ConfigurationPath);
}
}
public interface IPlugin
{
string Path { get; set; }
void Init();
}
}