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 DiscImageChef.Console;
|
||||
|
||||
@@ -39,22 +40,20 @@ namespace DiscImageChef.Filters
|
||||
{
|
||||
public class FiltersList
|
||||
{
|
||||
public SortedDictionary<string, Filter> Filters;
|
||||
public SortedDictionary<string, IFilter> Filters;
|
||||
|
||||
/// <summary>
|
||||
/// Fills the list of all known filters
|
||||
/// </summary>
|
||||
public FiltersList()
|
||||
{
|
||||
Assembly assembly = Assembly.GetAssembly(typeof(Filter));
|
||||
Filters = new SortedDictionary<string, Filter>();
|
||||
Assembly assembly = Assembly.GetAssembly(typeof(IFilter));
|
||||
Filters = new SortedDictionary<string, IFilter>();
|
||||
|
||||
foreach(Type type in assembly.GetTypes())
|
||||
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilter))))
|
||||
try
|
||||
{
|
||||
if(!type.IsSubclassOf(typeof(Filter))) continue;
|
||||
|
||||
Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IFilter filter = (IFilter)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
if(filter != null && !Filters.ContainsKey(filter.Name.ToLower()))
|
||||
Filters.Add(filter.Name.ToLower(), filter);
|
||||
}
|
||||
@@ -66,17 +65,17 @@ namespace DiscImageChef.Filters
|
||||
/// </summary>
|
||||
/// <param name="path">Path</param>
|
||||
/// <returns>The filter that allows reading the specified path</returns>
|
||||
public Filter GetFilter(string path)
|
||||
public IFilter GetFilter(string path)
|
||||
{
|
||||
Filter noFilter = null;
|
||||
IFilter noFilter = null;
|
||||
|
||||
foreach(Filter filter in Filters.Values)
|
||||
if(filter.UUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||
foreach(IFilter filter in Filters.Values)
|
||||
if(filter.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||
{
|
||||
if(!filter.Identify(path)) continue;
|
||||
|
||||
Filter foundFilter =
|
||||
(Filter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
IFilter foundFilter =
|
||||
(IFilter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
||||
|
||||
foundFilter?.Open(path);
|
||||
|
||||
@@ -95,7 +94,7 @@ namespace DiscImageChef.Filters
|
||||
/// Gets all known filters
|
||||
/// </summary>
|
||||
/// <returns>Known filters</returns>
|
||||
public SortedDictionary<string, Filter> GetFiltersList()
|
||||
public SortedDictionary<string, IFilter> GetFiltersList()
|
||||
{
|
||||
return Filters;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user