mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
🎨Converted all plugin types to interfaces.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using DiscImageChef.Console;
|
||||
@@ -49,86 +50,75 @@ namespace DiscImageChef.Core
|
||||
/// <summary>
|
||||
/// List of all media image plugins
|
||||
/// </summary>
|
||||
public SortedDictionary<string, ImagePlugin> ImagePluginsList;
|
||||
public SortedDictionary<string, IMediaImage> ImagePluginsList;
|
||||
/// <summary>
|
||||
/// List of all partition plugins
|
||||
/// </summary>
|
||||
public SortedDictionary<string, PartitionPlugin> PartPluginsList;
|
||||
public SortedDictionary<string, IPartition> PartPluginsList;
|
||||
/// <summary>
|
||||
/// List of all filesystem plugins
|
||||
/// </summary>
|
||||
public SortedDictionary<string, Filesystem> PluginsList;
|
||||
public SortedDictionary<string, IFilesystem> PluginsList;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the plugins lists
|
||||
/// </summary>
|
||||
public PluginBase()
|
||||
{
|
||||
PluginsList = new SortedDictionary<string, Filesystem>();
|
||||
PartPluginsList = new SortedDictionary<string, PartitionPlugin>();
|
||||
ImagePluginsList = new SortedDictionary<string, ImagePlugin>();
|
||||
PluginsList = new SortedDictionary<string, IFilesystem>();
|
||||
PartPluginsList = new SortedDictionary<string, IPartition>();
|
||||
ImagePluginsList = new SortedDictionary<string, IMediaImage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills the plugins lists
|
||||
/// </summary>
|
||||
/// <param name="encoding">Which encoding to pass to plugins</param>
|
||||
public void RegisterAllPlugins(Encoding encoding = null)
|
||||
public void RegisterAllPlugins()
|
||||
{
|
||||
Assembly assembly = Assembly.GetAssembly(typeof(ImagePlugin));
|
||||
Assembly assembly = Assembly.GetAssembly(typeof(IMediaImage));
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IMediaImage))))
|
||||
try
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(ImagePlugin))) continue;
|
||||
|
||||
ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IMediaImage plugin = (IMediaImage)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterImagePlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(PartitionPlugin));
|
||||
assembly = Assembly.GetAssembly(typeof(IPartition));
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IPartition))))
|
||||
try
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(PartitionPlugin))) continue;
|
||||
|
||||
PartitionPlugin plugin =
|
||||
(PartitionPlugin)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IPartition plugin =
|
||||
(IPartition)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterPartPlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
|
||||
assembly = Assembly.GetAssembly(typeof(Filesystem));
|
||||
assembly = Assembly.GetAssembly(typeof(IFilesystem));
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilesystem))))
|
||||
try
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(Filesystem))) continue;
|
||||
|
||||
Filesystem plugin;
|
||||
if(encoding != null)
|
||||
plugin = (Filesystem)type.GetConstructor(new[] {encoding.GetType()})
|
||||
?.Invoke(new object[] {encoding});
|
||||
else plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IFilesystem plugin = (IFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
RegisterPlugin(plugin);
|
||||
}
|
||||
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
||||
}
|
||||
|
||||
void RegisterImagePlugin(ImagePlugin plugin)
|
||||
void RegisterImagePlugin(IMediaImage plugin)
|
||||
{
|
||||
if(!ImagePluginsList.ContainsKey(plugin.Name.ToLower()))
|
||||
ImagePluginsList.Add(plugin.Name.ToLower(), plugin);
|
||||
}
|
||||
|
||||
void RegisterPlugin(Filesystem plugin)
|
||||
void RegisterPlugin(IFilesystem plugin)
|
||||
{
|
||||
if(!PluginsList.ContainsKey(plugin.Name.ToLower())) PluginsList.Add(plugin.Name.ToLower(), plugin);
|
||||
}
|
||||
|
||||
void RegisterPartPlugin(PartitionPlugin partplugin)
|
||||
void RegisterPartPlugin(IPartition partplugin)
|
||||
{
|
||||
if(!PartPluginsList.ContainsKey(partplugin.Name.ToLower()))
|
||||
PartPluginsList.Add(partplugin.Name.ToLower(), partplugin);
|
||||
|
||||
Reference in New Issue
Block a user