[Plugin system] Move byte addressable media images to dependency injection.

This commit is contained in:
2023-10-06 00:46:36 +01:00
parent 508b78719d
commit 9572abf86d
8 changed files with 8 additions and 16 deletions

View File

@@ -84,11 +84,11 @@ public static class ImageFormat
return imageFormat;
// Check all but RAW plugin
foreach(Type pluginType in plugins.ByteAddressableImages.Values)
foreach(IByteAddressableImage imagePlugin in plugins.ByteAddressableImages.Values)
{
try
{
if(Activator.CreateInstance(pluginType) is not IByteAddressableImage imagePlugin)
if(imagePlugin is null)
continue;
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))

View File

@@ -247,16 +247,16 @@ public class PluginRegisterGenerator : ISourceGenerator
if(byteAddressableImagePlugins?.Count > 0)
{
sb.AppendLine(" public List<Type> GetAllByteAddressablePlugins() => new()");
sb.AppendLine(" public void RegisterByteAddressablePlugins(IServiceCollection services)");
sb.AppendLine(" {");
foreach(string plugin in byteAddressableImagePlugins)
sb.AppendLine($" typeof({plugin}),");
sb.AppendLine($" services.AddTransient<IByteAddressableImage, {plugin}>();");
sb.AppendLine(" };");
sb.AppendLine(" }");
}
else
sb.AppendLine(" public List<Type> GetAllByteAddressablePlugins() => null;");
sb.AppendLine(" public void RegisterByteAddressablePlugins(IServiceCollection services) {}");
sb.AppendLine("}");

View File

@@ -607,7 +607,6 @@ public sealed class MainWindowViewModel : ViewModelBase
var checkRaw = false;
List<string> idPlugins;
Type pluginType;
PluginRegister plugins = PluginRegister.Singleton;
if(partitions.Count == 0)

View File

@@ -243,13 +243,9 @@ public abstract class BlockMediaImageTest : BaseMediaImageTest
string pluginName = idPlugins[j];
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName,
out Type pluginType))
out IReadOnlyFilesystem fs))
continue;
Assert.IsNotNull(pluginType, Localization.Could_not_instantiate_filesystem_plugin);
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, pluginName));
ErrorNumber error = fs.Mount(image, partitions[i], null, null, null);

View File

@@ -76,7 +76,6 @@ public abstract class FsExtractIssueTest
if(idPlugins.Count == 0)
continue;
Type pluginType;
ErrorNumber error;
if(idPlugins.Count > 1)

View File

@@ -311,7 +311,6 @@ sealed class ExtractFilesCommand : Command
AaruConsole.WriteLine(UI.Filesystem_not_identified);
else
{
Type pluginType;
ErrorNumber error = ErrorNumber.InvalidArgument;
if(idPlugins.Count > 1)

View File

@@ -284,7 +284,6 @@ sealed class LsCommand : Command
AaruConsole.WriteLine(UI.Filesystem_not_identified);
else
{
Type pluginType;
ErrorNumber error = ErrorNumber.InvalidArgument;
if(idPlugins.Count > 1)