mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Cleaning the plugin manager
This commit is contained in:
parent
2f5b59afed
commit
81797948df
@ -50,16 +50,12 @@ namespace Kyoo.Controllers
|
||||
|
||||
public T GetPlugin<T>(string name)
|
||||
{
|
||||
if (_plugins == null)
|
||||
return default;
|
||||
return (T)(from plugin in _plugins where plugin.Name == name && plugin is T select plugin).FirstOrDefault();
|
||||
return (T)_plugins?.FirstOrDefault(x => x.Name == name && x is T);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetPlugins<T>()
|
||||
{
|
||||
if (_plugins == null)
|
||||
return new List<T>();
|
||||
return from plugin in _plugins where plugin is T select (T)plugin;
|
||||
return _plugins?.OfType<T>() ?? new List<T>();
|
||||
}
|
||||
|
||||
public IEnumerable<IPlugin> GetAllPlugins()
|
||||
@ -70,20 +66,20 @@ namespace Kyoo.Controllers
|
||||
public void ReloadPlugins()
|
||||
{
|
||||
string pluginFolder = _config.GetValue<string>("plugins");
|
||||
|
||||
if (!Directory.Exists(pluginFolder))
|
||||
return;
|
||||
string[] pluginsPaths = Directory.GetFiles(pluginFolder);
|
||||
|
||||
_plugins = pluginsPaths.Select(path =>
|
||||
string[] pluginsPaths = Directory.GetFiles(pluginFolder);
|
||||
_plugins = pluginsPaths.SelectMany(path =>
|
||||
{
|
||||
path = Path.GetFullPath(path);
|
||||
try
|
||||
{
|
||||
PluginDependencyLoader loader = new PluginDependencyLoader(Path.GetFullPath(path));
|
||||
Assembly ass = loader.LoadFromAssemblyPath(Path.GetFullPath(path));
|
||||
return (from type in ass.GetTypes()
|
||||
where typeof(IPlugin).IsAssignableFrom(type)
|
||||
select (IPlugin) ActivatorUtilities.CreateInstance(_provider, type)).FirstOrDefault();
|
||||
PluginDependencyLoader loader = new PluginDependencyLoader(path);
|
||||
Assembly ass = loader.LoadFromAssemblyPath(path);
|
||||
return ass.GetTypes()
|
||||
.Where(x => typeof(IPlugin).IsAssignableFrom(x))
|
||||
.Select(x => (IPlugin)ActivatorUtilities.CreateInstance(_provider, x));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -91,6 +87,7 @@ namespace Kyoo.Controllers
|
||||
return null;
|
||||
}
|
||||
}).Where(x => x != null).ToList();
|
||||
|
||||
if (!_plugins.Any())
|
||||
{
|
||||
Console.WriteLine("No plugin enabled.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user