diff --git a/Interfaces/IPluginRegister.cs b/Interfaces/IPluginRegister.cs index 8c415aa..67c12d1 100644 --- a/Interfaces/IPluginRegister.cs +++ b/Interfaces/IPluginRegister.cs @@ -53,9 +53,11 @@ public interface IPluginRegister /// Service collection void RegisterChecksumPlugins(IServiceCollection services); - /// Gets all filesystem plugins - /// List of filesystem plugins - List GetAllFilesystemPlugins(); + /// + /// Registers all filesystem plugins in the provided service collection + /// + /// Service collection + void RegisterFilesystemPlugins(IServiceCollection services); /// /// Registers all filter plugins in the provided service collection diff --git a/PluginRegister.cs b/PluginRegister.cs index d5bc755..7c899de 100644 --- a/PluginRegister.cs +++ b/PluginRegister.cs @@ -46,8 +46,6 @@ public class PluginRegister /// List of byte addressable image plugins public readonly SortedDictionary ByteAddressableImages; - /// List of all filesystem plugins - public readonly SortedDictionary Filesystems; /// List of floppy image plugins public readonly SortedDictionary FloppyImages; @@ -65,7 +63,6 @@ public class PluginRegister PluginRegister() { - Filesystems = new SortedDictionary(); ReadOnlyFilesystems = new SortedDictionary(); MediaImages = new SortedDictionary(); WritableImages = new SortedDictionary(); @@ -74,6 +71,19 @@ public class PluginRegister ByteAddressableImages = new SortedDictionary(); } + /// List of all filesystem plugins + public SortedDictionary Filesystems + { + get + { + SortedDictionary filesystems = new(); + foreach(IFilesystem plugin in _serviceProvider.GetServices()) + filesystems[plugin.Name.ToLower()] = plugin; + + return filesystems; + } + } + /// List of all archive formats public SortedDictionary Archives { @@ -81,7 +91,7 @@ public class PluginRegister { SortedDictionary archives = new(); foreach(IArchive plugin in _serviceProvider.GetServices()) - archives.Add(plugin.Name.ToLower(), plugin); + archives[plugin.Name.ToLower()] = plugin; return archives; } @@ -94,7 +104,7 @@ public class PluginRegister { SortedDictionary partitions = new(); foreach(IPartition plugin in _serviceProvider.GetServices()) - partitions.Add(plugin.Name.ToLower(), plugin); + partitions[plugin.Name.ToLower()] = plugin; return partitions; } @@ -107,7 +117,7 @@ public class PluginRegister { SortedDictionary filters = new(); foreach(IFilter plugin in _serviceProvider.GetServices()) - filters.Add(plugin.Name.ToLower(), plugin); + filters[plugin.Name.ToLower()] = plugin; return filters; } @@ -120,7 +130,7 @@ public class PluginRegister { SortedDictionary checksums = new(); foreach(IChecksum plugin in _serviceProvider.GetServices()) - checksums.Add(plugin.Name.ToLower(), plugin); + checksums[plugin.Name.ToLower()] = plugin; return checksums; } @@ -165,13 +175,7 @@ public class PluginRegister void AddPlugins(IPluginRegister pluginRegister) { pluginRegister.RegisterChecksumPlugins(_services); - - foreach(Type type in pluginRegister.GetAllFilesystemPlugins() ?? Enumerable.Empty()) - { - if(Activator.CreateInstance(type) is IFilesystem plugin && !Filesystems.ContainsKey(plugin.Name.ToLower())) - Filesystems.Add(plugin.Name.ToLower(), type); - } - + pluginRegister.RegisterFilesystemPlugins(_services); pluginRegister.RegisterFilterPlugins(_services); foreach(Type type in pluginRegister.GetAllFloppyImagePlugins() ?? Enumerable.Empty())