mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Plugin system] Move media images to dependency injection.
This commit is contained in:
@@ -54,9 +54,9 @@ public static class ImageFormat
|
|||||||
IBaseImage imageFormat = null;
|
IBaseImage imageFormat = null;
|
||||||
|
|
||||||
// Check all but RAW plugin
|
// Check all but RAW plugin
|
||||||
foreach(Type pluginType in plugins.MediaImages.Values)
|
foreach(IMediaImage imagePlugin in plugins.MediaImages.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(pluginType) is not IMediaImage imagePlugin)
|
if(imagePlugin is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||||
@@ -114,9 +114,9 @@ public static class ImageFormat
|
|||||||
return imageFormat;
|
return imageFormat;
|
||||||
|
|
||||||
// Check only RAW plugin
|
// Check only RAW plugin
|
||||||
foreach(Type pluginType in plugins.MediaImages.Values)
|
foreach(IMediaImage imagePlugin in plugins.MediaImages.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(pluginType) is not IMediaImage imagePlugin)
|
if(imagePlugin is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(imagePlugin.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
if(imagePlugin.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||||
|
|||||||
Submodule Aaru.Decryption updated: 7fd2a0fc73...605e00ed85
@@ -176,16 +176,16 @@ public class PluginRegisterGenerator : ISourceGenerator
|
|||||||
|
|
||||||
if(mediaImagePlugins?.Count > 0)
|
if(mediaImagePlugins?.Count > 0)
|
||||||
{
|
{
|
||||||
sb.AppendLine(" public List<Type> GetAllMediaImagePlugins() => new()");
|
sb.AppendLine(" public void RegisterMediaImagePlugins(IServiceCollection services)");
|
||||||
sb.AppendLine(" {");
|
sb.AppendLine(" {");
|
||||||
|
|
||||||
foreach(string plugin in mediaImagePlugins)
|
foreach(string plugin in mediaImagePlugins)
|
||||||
sb.AppendLine($" typeof({plugin}),");
|
sb.AppendLine($" services.AddTransient<IMediaImage, {plugin}>();");
|
||||||
|
|
||||||
sb.AppendLine(" };");
|
sb.AppendLine(" }");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sb.AppendLine(" public List<Type> GetAllMediaImagePlugins() => null;");
|
sb.AppendLine(" public void RegisterMediaImagePlugins(IServiceCollection services) {}");
|
||||||
|
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
@@ -394,7 +394,7 @@ public class PluginRegisterGenerator : ISourceGenerator
|
|||||||
ByteAddressableImagePlugins.Add(plugin.Identifier.Text);
|
ByteAddressableImagePlugins.Add(plugin.Identifier.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaImagePlugins.AddRange(WritableImagePlugins);
|
MediaImagePlugins.AddRange(WritableImagePlugins.Where(t => !ByteAddressableImagePlugins.Contains(t)));
|
||||||
FileSystems.AddRange(ReadOnlyFileSystems);
|
FileSystems.AddRange(ReadOnlyFileSystems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,16 +62,16 @@ public sealed class PluginsViewModel : ViewModelBase
|
|||||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||||
|
|
||||||
// TODO: Takes too much time
|
// TODO: Takes too much time
|
||||||
foreach(Type filterType in PluginRegister.Singleton.Filters.Values)
|
foreach(IFilter filter in PluginRegister.Singleton.Filters.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(filterType) is not IFilter filter)
|
if(filter is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Filters.Add(new PluginModel
|
Filters.Add(new PluginModel
|
||||||
{
|
{
|
||||||
Name = filter.Name,
|
Name = filter.Name,
|
||||||
Uuid = filter.Id,
|
Uuid = filter.Id,
|
||||||
Version = Assembly.GetAssembly(filterType)?.GetName().Version?.ToString(),
|
Version = Assembly.GetAssembly(filter.GetType())?.GetName().Version?.ToString(),
|
||||||
Author = filter.Author
|
Author = filter.Author
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -90,30 +90,30 @@ public sealed class PluginsViewModel : ViewModelBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(Type imageType in PluginRegister.Singleton.MediaImages.Values)
|
foreach(IMediaImage mediaImage in PluginRegister.Singleton.MediaImages.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(imageType) is not IMediaImage mediaImage)
|
if(mediaImage is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Images.Add(new PluginModel
|
Images.Add(new PluginModel
|
||||||
{
|
{
|
||||||
Name = mediaImage.Name,
|
Name = mediaImage.Name,
|
||||||
Uuid = mediaImage.Id,
|
Uuid = mediaImage.Id,
|
||||||
Version = Assembly.GetAssembly(imageType)?.GetName().Version?.ToString(),
|
Version = Assembly.GetAssembly(mediaImage.GetType())?.GetName().Version?.ToString(),
|
||||||
Author = mediaImage.Author
|
Author = mediaImage.Author
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(Type partitionType in PluginRegister.Singleton.Partitions.Values)
|
foreach(IPartition partition in PluginRegister.Singleton.Partitions.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(partitionType) is not IPartition partition)
|
if(partition is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PartitionSchemes.Add(new PluginModel
|
PartitionSchemes.Add(new PluginModel
|
||||||
{
|
{
|
||||||
Name = partition.Name,
|
Name = partition.Name,
|
||||||
Uuid = partition.Id,
|
Uuid = partition.Id,
|
||||||
Version = Assembly.GetAssembly(partitionType)?.GetName().Version?.ToString(),
|
Version = Assembly.GetAssembly(partition.GetType())?.GetName().Version?.ToString(),
|
||||||
Author = partition.Author
|
Author = partition.Author
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,8 @@ sealed class FormatsCommand : Command
|
|||||||
table = new Table
|
table = new Table
|
||||||
{
|
{
|
||||||
Title = new TableTitle(string.Format(UI.Read_only_media_image_formats_0,
|
Title = new TableTitle(string.Format(UI.Read_only_media_image_formats_0,
|
||||||
plugins.MediaImages.Count(t => !t.Value.GetInterfaces().
|
plugins.MediaImages.Count(t => !t.Value.GetType().
|
||||||
|
GetInterfaces().
|
||||||
Contains(typeof(IWritableImage)))))
|
Contains(typeof(IWritableImage)))))
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,12 +125,12 @@ sealed class FormatsCommand : Command
|
|||||||
|
|
||||||
table.AddColumn(UI.Title_Media_image_format);
|
table.AddColumn(UI.Title_Media_image_format);
|
||||||
|
|
||||||
foreach(KeyValuePair<string, Type> kvp in plugins.MediaImages.Where(t => !t.Value.GetInterfaces().
|
foreach(IMediaImage imagePlugin in plugins.MediaImages.Values.
|
||||||
Contains(typeof(IWritableImage))))
|
Where(t => !t.GetType().
|
||||||
|
GetInterfaces().
|
||||||
|
Contains(typeof(IWritableImage))).
|
||||||
|
Where(t => t is not null))
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(kvp.Value) is not IMediaImage imagePlugin)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
table.AddRow(imagePlugin.Id.ToString(), Markup.Escape(imagePlugin.Name));
|
table.AddRow(imagePlugin.Id.ToString(), Markup.Escape(imagePlugin.Name));
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user