2012-07-20 02:22:44 +00:00
|
|
|
|
using System.IO;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using MediaBrowser.Common.Json;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Common.Plugins
|
|
|
|
|
{
|
2012-07-13 03:50:50 +00:00
|
|
|
|
public abstract class BasePlugin<TConfigurationType> : IPlugin
|
2012-07-12 06:55:27 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-15 20:27:07 +00:00
|
|
|
|
return JsonSerializer.DeserializeFromFile<TConfigurationType>(ConfigurationPath);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IPlugin
|
|
|
|
|
{
|
|
|
|
|
string Path { get; set; }
|
|
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
}
|
|
|
|
|
}
|