[Plugin system] Move archives to dependency injection.

This commit is contained in:
2023-10-05 16:19:54 +01:00
parent 5fe2717e28
commit 7e16f47f86
2 changed files with 20 additions and 11 deletions

View File

@@ -89,9 +89,11 @@ public interface IPluginRegister
/// <returns>List of writable media image plugins</returns>
List<Type> GetAllWritableImagePlugins();
/// <summary>Gets all archive plugins</summary>
/// <returns>List of archive plugins</returns>
List<Type> GetAllArchivePlugins();
/// <summary>
/// Registers all archive plugins in the provided service collection
/// </summary>
/// <param name="services">Service collection</param>
void RegisterArchivePlugins(IServiceCollection services);
/// <summary>Gets all byte addressable plugins</summary>
/// <returns>List of byte addressable plugins</returns>

View File

@@ -43,8 +43,7 @@ namespace Aaru.CommonTypes;
public class PluginRegister
{
static PluginRegister _instance;
/// <summary>List of all archive formats</summary>
public readonly SortedDictionary<string, Type> Archives;
/// <summary>List of byte addressable image plugins</summary>
public readonly SortedDictionary<string, Type> ByteAddressableImages;
/// <summary>List of all filesystem plugins</summary>
@@ -72,10 +71,22 @@ public class PluginRegister
WritableImages = new SortedDictionary<string, Type>();
FloppyImages = new SortedDictionary<string, Type>();
WritableFloppyImages = new SortedDictionary<string, Type>();
Archives = 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>
public SortedDictionary<string, IPartition> Partitions
{
@@ -199,11 +210,7 @@ public class PluginRegister
WritableImages.Add(plugin.Name.ToLower(), type);
}
foreach(Type type in pluginRegister.GetAllArchivePlugins() ?? Enumerable.Empty<Type>())
{
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<Type>())
{