From 7e16f47f860ec4ca3316e5ed803ec7ea79c312a3 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 5 Oct 2023 16:19:54 +0100 Subject: [PATCH] [Plugin system] Move archives to dependency injection. --- Interfaces/IPluginRegister.cs | 8 +++++--- PluginRegister.cs | 23 +++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Interfaces/IPluginRegister.cs b/Interfaces/IPluginRegister.cs index 73f2430..8c415aa 100644 --- a/Interfaces/IPluginRegister.cs +++ b/Interfaces/IPluginRegister.cs @@ -89,9 +89,11 @@ public interface IPluginRegister /// List of writable media image plugins List GetAllWritableImagePlugins(); - /// Gets all archive plugins - /// List of archive plugins - List GetAllArchivePlugins(); + /// + /// Registers all archive plugins in the provided service collection + /// + /// Service collection + void RegisterArchivePlugins(IServiceCollection services); /// Gets all byte addressable plugins /// List of byte addressable plugins diff --git a/PluginRegister.cs b/PluginRegister.cs index 4b90bd7..d5bc755 100644 --- a/PluginRegister.cs +++ b/PluginRegister.cs @@ -43,8 +43,7 @@ namespace Aaru.CommonTypes; public class PluginRegister { static PluginRegister _instance; - /// List of all archive formats - public readonly SortedDictionary Archives; + /// List of byte addressable image plugins public readonly SortedDictionary ByteAddressableImages; /// List of all filesystem plugins @@ -72,10 +71,22 @@ public class PluginRegister WritableImages = new SortedDictionary(); FloppyImages = new SortedDictionary(); WritableFloppyImages = new SortedDictionary(); - Archives = new SortedDictionary(); ByteAddressableImages = new SortedDictionary(); } + /// List of all archive formats + public SortedDictionary Archives + { + get + { + SortedDictionary archives = new(); + foreach(IArchive plugin in _serviceProvider.GetServices()) + archives.Add(plugin.Name.ToLower(), plugin); + + return archives; + } + } + /// List of all partition plugins public SortedDictionary Partitions { @@ -199,11 +210,7 @@ public class PluginRegister WritableImages.Add(plugin.Name.ToLower(), type); } - foreach(Type type in pluginRegister.GetAllArchivePlugins() ?? Enumerable.Empty()) - { - if(Activator.CreateInstance(type) is IArchive plugin && !Archives.ContainsKey(plugin.Name.ToLower())) - Archives.Add(plugin.Name.ToLower(), type); - } + pluginRegister.RegisterArchivePlugins(_services); foreach(Type type in pluginRegister.GetAllByteAddressablePlugins() ?? Enumerable.Empty()) {