[Plugin system] Move floppy images to dependency injection.

This commit is contained in:
2023-10-06 00:14:30 +01:00
parent 3275fa8db0
commit c6506f7b89
2 changed files with 19 additions and 14 deletions

View File

@@ -65,9 +65,11 @@ public interface IPluginRegister
/// <param name="services">Service collection</param>
void RegisterFilterPlugins(IServiceCollection services);
/// <summary>Gets all floppy image plugins</summary>
/// <returns>List of floppy image plugins</returns>
List<Type> GetAllFloppyImagePlugins();
/// <summary>
/// Registers all floppy image plugins in the provided service collection
/// </summary>
/// <param name="services">Service collection</param>
void RegisterFloppyImagePlugins(IServiceCollection services);
/// <summary>
/// Registers all media image plugins in the provided service collection

View File

@@ -47,8 +47,6 @@ public class PluginRegister
/// <summary>List of byte addressable image plugins</summary>
public readonly SortedDictionary<string, Type> ByteAddressableImages;
/// <summary>List of floppy image plugins</summary>
public readonly SortedDictionary<string, Type> FloppyImages;
/// <summary>List of writable floppy image plugins</summary>
public readonly SortedDictionary<string, Type> WritableFloppyImages;
/// <summary>List of writable media image plugins</summary>
@@ -59,11 +57,23 @@ public class PluginRegister
PluginRegister()
{
WritableImages = new SortedDictionary<string, Type>();
FloppyImages = new SortedDictionary<string, Type>();
WritableFloppyImages = new SortedDictionary<string, Type>();
ByteAddressableImages = new SortedDictionary<string, Type>();
}
/// <summary>List of floppy image plugins</summary>
public SortedDictionary<string, IFloppyImage> FloppyImages
{
get
{
SortedDictionary<string, IFloppyImage> floppyImages = new();
foreach(IFloppyImage plugin in _serviceProvider.GetServices<IFloppyImage>())
floppyImages[plugin.Name.ToLower()] = plugin;
return floppyImages;
}
}
/// <summary>List of all media image plugins</summary>
public SortedDictionary<string, IMediaImage> MediaImages
{
@@ -197,14 +207,7 @@ public class PluginRegister
pluginRegister.RegisterFilesystemPlugins(_services);
pluginRegister.RegisterFilterPlugins(_services);
pluginRegister.RegisterReadOnlyFilesystemPlugins(_services);
foreach(Type type in pluginRegister.GetAllFloppyImagePlugins() ?? Enumerable.Empty<Type>())
{
if(Activator.CreateInstance(type) is IFloppyImage plugin &&
!FloppyImages.ContainsKey(plugin.Name.ToLower()))
FloppyImages.Add(plugin.Name.ToLower(), type);
}
pluginRegister.RegisterFloppyImagePlugins(_services);
pluginRegister.RegisterMediaImagePlugins(_services);
pluginRegister.RegisterPartitionPlugins(_services);