mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Plugin system] Move archives to dependency injection.
This commit is contained in:
@@ -89,9 +89,11 @@ public interface IPluginRegister
|
|||||||
/// <returns>List of writable media image plugins</returns>
|
/// <returns>List of writable media image plugins</returns>
|
||||||
List<Type> GetAllWritableImagePlugins();
|
List<Type> GetAllWritableImagePlugins();
|
||||||
|
|
||||||
/// <summary>Gets all archive plugins</summary>
|
/// <summary>
|
||||||
/// <returns>List of archive plugins</returns>
|
/// Registers all archive plugins in the provided service collection
|
||||||
List<Type> GetAllArchivePlugins();
|
/// </summary>
|
||||||
|
/// <param name="services">Service collection</param>
|
||||||
|
void RegisterArchivePlugins(IServiceCollection services);
|
||||||
|
|
||||||
/// <summary>Gets all byte addressable plugins</summary>
|
/// <summary>Gets all byte addressable plugins</summary>
|
||||||
/// <returns>List of byte addressable plugins</returns>
|
/// <returns>List of byte addressable plugins</returns>
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ namespace Aaru.CommonTypes;
|
|||||||
public class PluginRegister
|
public class PluginRegister
|
||||||
{
|
{
|
||||||
static PluginRegister _instance;
|
static PluginRegister _instance;
|
||||||
/// <summary>List of all archive formats</summary>
|
|
||||||
public readonly SortedDictionary<string, Type> Archives;
|
|
||||||
/// <summary>List of byte addressable image plugins</summary>
|
/// <summary>List of byte addressable image plugins</summary>
|
||||||
public readonly SortedDictionary<string, Type> ByteAddressableImages;
|
public readonly SortedDictionary<string, Type> ByteAddressableImages;
|
||||||
/// <summary>List of all filesystem plugins</summary>
|
/// <summary>List of all filesystem plugins</summary>
|
||||||
@@ -72,10 +71,22 @@ public class PluginRegister
|
|||||||
WritableImages = new SortedDictionary<string, Type>();
|
WritableImages = new SortedDictionary<string, Type>();
|
||||||
FloppyImages = new SortedDictionary<string, Type>();
|
FloppyImages = new SortedDictionary<string, Type>();
|
||||||
WritableFloppyImages = new SortedDictionary<string, Type>();
|
WritableFloppyImages = new SortedDictionary<string, Type>();
|
||||||
Archives = new SortedDictionary<string, Type>();
|
|
||||||
ByteAddressableImages = new SortedDictionary<string, Type>();
|
ByteAddressableImages = new SortedDictionary<string, Type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>List of all archive formats</summary>
|
||||||
|
public SortedDictionary<string, IArchive> Archives
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
SortedDictionary<string, IArchive> archives = new();
|
||||||
|
foreach(IArchive plugin in _serviceProvider.GetServices<IArchive>())
|
||||||
|
archives.Add(plugin.Name.ToLower(), plugin);
|
||||||
|
|
||||||
|
return archives;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>List of all partition plugins</summary>
|
/// <summary>List of all partition plugins</summary>
|
||||||
public SortedDictionary<string, IPartition> Partitions
|
public SortedDictionary<string, IPartition> Partitions
|
||||||
{
|
{
|
||||||
@@ -199,11 +210,7 @@ public class PluginRegister
|
|||||||
WritableImages.Add(plugin.Name.ToLower(), type);
|
WritableImages.Add(plugin.Name.ToLower(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(Type type in pluginRegister.GetAllArchivePlugins() ?? Enumerable.Empty<Type>())
|
pluginRegister.RegisterArchivePlugins(_services);
|
||||||
{
|
|
||||||
if(Activator.CreateInstance(type) is IArchive plugin && !Archives.ContainsKey(plugin.Name.ToLower()))
|
|
||||||
Archives.Add(plugin.Name.ToLower(), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(Type type in pluginRegister.GetAllByteAddressablePlugins() ?? Enumerable.Empty<Type>())
|
foreach(Type type in pluginRegister.GetAllByteAddressablePlugins() ?? Enumerable.Empty<Type>())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user