Register byte addressable plugins.

This commit is contained in:
2021-11-13 18:02:20 +00:00
parent b42c75b261
commit 533131a8fb
2 changed files with 137 additions and 126 deletions

View File

@@ -39,11 +39,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Aaru.CommonTypes.Interfaces namespace Aaru.CommonTypes.Interfaces;
/// <summary>Defines a register of all known plugins</summary>
public interface IPluginRegister
{ {
/// <summary>Defines a register of all known plugins</summary>
public interface IPluginRegister
{
/// <summary>Gets all checksum plugins</summary> /// <summary>Gets all checksum plugins</summary>
/// <returns>List of checksum plugins</returns> /// <returns>List of checksum plugins</returns>
List<Type> GetAllChecksumPlugins(); List<Type> GetAllChecksumPlugins();
@@ -83,5 +83,8 @@ namespace Aaru.CommonTypes.Interfaces
/// <summary>Gets all archive plugins</summary> /// <summary>Gets all archive plugins</summary>
/// <returns>List of archive plugins</returns> /// <returns>List of archive plugins</returns>
List<Type> GetAllArchivePlugins(); List<Type> GetAllArchivePlugins();
}
/// <summary>Gets all byte addressable plugins</summary>
/// <returns>List of byte addressable plugins</returns>
List<Type> GetAllByteAddressablePlugins();
} }

View File

@@ -41,13 +41,15 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
namespace Aaru.CommonTypes namespace Aaru.CommonTypes;
/// <summary>Contain all plugins (filesystem, partition and image)</summary>
public class PluginBase
{ {
/// <summary>Contain all plugins (filesystem, partition and image)</summary>
public class PluginBase
{
/// <summary>List of all archive formats</summary> /// <summary>List of all archive formats</summary>
public readonly SortedDictionary<string, IArchive> Archives; public readonly SortedDictionary<string, IArchive> Archives;
/// <summary>List of byte addressable image plugins</summary>
public readonly SortedDictionary<string, IByteAddressableImage> ByteAddressableImages;
/// <summary>List of checksum plugins</summary> /// <summary>List of checksum plugins</summary>
public readonly List<IChecksum> Checksums; public readonly List<IChecksum> Checksums;
/// <summary>List of filter plugins</summary> /// <summary>List of filter plugins</summary>
@@ -80,6 +82,7 @@ namespace Aaru.CommonTypes
FloppyImages = new SortedDictionary<string, IFloppyImage>(); FloppyImages = new SortedDictionary<string, IFloppyImage>();
WritableFloppyImages = new SortedDictionary<string, IWritableFloppyImage>(); WritableFloppyImages = new SortedDictionary<string, IWritableFloppyImage>();
Archives = new SortedDictionary<string, IArchive>(); Archives = new SortedDictionary<string, IArchive>();
ByteAddressableImages = new SortedDictionary<string, IByteAddressableImage>();
} }
/// <summary>Adds plugins to the central plugin register</summary> /// <summary>Adds plugins to the central plugin register</summary>
@@ -144,6 +147,11 @@ namespace Aaru.CommonTypes
{}) is IArchive plugin && {}) is IArchive plugin &&
!Archives.ContainsKey(plugin.Name.ToLower())) !Archives.ContainsKey(plugin.Name.ToLower()))
Archives.Add(plugin.Name.ToLower(), plugin); Archives.Add(plugin.Name.ToLower(), plugin);
}
foreach(Type type in pluginRegister.GetAllArchivePlugins() ?? Enumerable.Empty<Type>())
if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[]
{}) is IByteAddressableImage plugin &&
!ByteAddressableImages.ContainsKey(plugin.Name.ToLower()))
ByteAddressableImages.Add(plugin.Name.ToLower(), plugin);
} }
} }