mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Plugin system] Move filesystems to dependency injection.
This commit is contained in:
Submodule Aaru.CommonTypes updated: 7e16f47f86...76b70b1c75
@@ -30,8 +30,8 @@
|
||||
// Copyright © 2011-2023 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
|
||||
@@ -53,15 +53,9 @@ public static class Filesystems
|
||||
{
|
||||
PluginRegister plugins = PluginRegister.Singleton;
|
||||
|
||||
idPlugins = new List<string>();
|
||||
|
||||
foreach(Type plugin in plugins.Filesystems.Values)
|
||||
{
|
||||
if(Activator.CreateInstance(plugin) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
if(fs.Identify(imagePlugin, partition))
|
||||
idPlugins.Add(getGuid ? fs.Id.ToString() : fs.Name.ToLower());
|
||||
}
|
||||
idPlugins = (from plugin in plugins.Filesystems.Values
|
||||
where plugin is not null
|
||||
where plugin.Identify(imagePlugin, partition)
|
||||
select getGuid ? plugin.Id.ToString() : plugin.Name.ToLower()).ToList();
|
||||
}
|
||||
}
|
||||
@@ -709,14 +709,14 @@ public sealed partial class Sidecar
|
||||
|
||||
List<FileSystem> lstFs = new();
|
||||
|
||||
foreach(Type pluginType in plugins.Filesystems.Values)
|
||||
foreach(IFilesystem fs in plugins.Filesystems.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_aborted)
|
||||
return;
|
||||
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
if(!fs.Identify(image, partition))
|
||||
@@ -776,14 +776,14 @@ public sealed partial class Sidecar
|
||||
|
||||
List<FileSystem> lstFs = new();
|
||||
|
||||
foreach(Type pluginType in plugins.Filesystems.Values)
|
||||
foreach(IFilesystem fs in plugins.Filesystems.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(_aborted)
|
||||
return;
|
||||
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
if(!fs.Identify(image, wholePart))
|
||||
|
||||
@@ -527,7 +527,7 @@ public sealed partial class Sidecar
|
||||
|
||||
List<FileSystem> lstFs = new();
|
||||
|
||||
foreach(Type pluginType in plugins.Filesystems.Values)
|
||||
foreach(IFilesystem fs in plugins.Filesystems.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -538,7 +538,7 @@ public sealed partial class Sidecar
|
||||
return;
|
||||
}
|
||||
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
if(!fs.Identify(image, partition))
|
||||
@@ -590,7 +590,7 @@ public sealed partial class Sidecar
|
||||
Sequence = xmlTrk.Sequence.Number
|
||||
};
|
||||
|
||||
foreach(Type pluginType in plugins.Filesystems.Values)
|
||||
foreach(IFilesystem fs in plugins.Filesystems.Values)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -601,7 +601,7 @@ public sealed partial class Sidecar
|
||||
return;
|
||||
}
|
||||
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
if(!fs.Identify(image, xmlPart))
|
||||
|
||||
@@ -135,16 +135,14 @@ public class PluginRegisterGenerator : ISourceGenerator
|
||||
|
||||
if(fileSystems?.Count > 0)
|
||||
{
|
||||
sb.AppendLine(" public List<Type> GetAllFilesystemPlugins() => new()");
|
||||
sb.AppendLine(" public void RegisterFilesystemPlugins(IServiceCollection services)");
|
||||
sb.AppendLine(" {");
|
||||
|
||||
foreach(string plugin in fileSystems)
|
||||
sb.AppendLine($" typeof({plugin}),");
|
||||
|
||||
sb.AppendLine(" };");
|
||||
sb.AppendLine($" services.AddTransient<IFilesystem, {plugin}>();");
|
||||
sb.AppendLine(" }");
|
||||
}
|
||||
else
|
||||
sb.AppendLine(" public List<Type> GetAllFilesystemPlugins() => null;");
|
||||
sb.AppendLine(" public void RegisterFilesystemPlugins(IServiceCollection services) {}");
|
||||
|
||||
sb.AppendLine();
|
||||
|
||||
|
||||
@@ -118,17 +118,17 @@ public sealed class PluginsViewModel : ViewModelBase
|
||||
});
|
||||
}
|
||||
|
||||
foreach(Type filesystem in PluginRegister.Singleton.Filesystems.Values)
|
||||
foreach(IFilesystem filesystem in PluginRegister.Singleton.Filesystems.Values)
|
||||
{
|
||||
if(Activator.CreateInstance(filesystem) is not IFilesystem fs)
|
||||
if(filesystem is null)
|
||||
continue;
|
||||
|
||||
Filesystems.Add(new PluginModel
|
||||
{
|
||||
Name = fs.Name,
|
||||
Uuid = fs.Id,
|
||||
Version = Assembly.GetAssembly(filesystem)?.GetName().Version?.ToString(),
|
||||
Author = fs.Author
|
||||
Name = filesystem.Name,
|
||||
Uuid = filesystem.Id,
|
||||
Version = Assembly.GetAssembly(filesystem.GetType())?.GetName().Version?.ToString(),
|
||||
Author = filesystem.Author
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -651,9 +651,9 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
{
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out IFilesystem fs))
|
||||
continue;
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
fs.GetInformation(imageFormat, partition, null, out string information,
|
||||
@@ -726,9 +726,9 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
{
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out IFilesystem fs))
|
||||
continue;
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
fs.GetInformation(imageFormat, wholePart, null, out string information,
|
||||
|
||||
@@ -228,7 +228,7 @@ sealed class FilesystemInfoCommand : Command
|
||||
}
|
||||
|
||||
List<string> idPlugins = null;
|
||||
Type pluginType;
|
||||
IFilesystem fs;
|
||||
string information;
|
||||
|
||||
if(partitions)
|
||||
@@ -309,9 +309,9 @@ sealed class FilesystemInfoCommand : Command
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
{
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out fs))
|
||||
continue;
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, fs.Name)
|
||||
@@ -328,9 +328,9 @@ sealed class FilesystemInfoCommand : Command
|
||||
}
|
||||
default:
|
||||
{
|
||||
plugins.Filesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
plugins.Filesystems.TryGetValue(idPlugins[0], out fs);
|
||||
|
||||
if(pluginType == null || Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, fs.Name)}[/]");
|
||||
@@ -378,9 +378,9 @@ sealed class FilesystemInfoCommand : Command
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
{
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
if(!plugins.Filesystems.TryGetValue(pluginName, out fs))
|
||||
continue;
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, fs.Name)}[/]");
|
||||
@@ -396,9 +396,9 @@ sealed class FilesystemInfoCommand : Command
|
||||
}
|
||||
default:
|
||||
{
|
||||
plugins.Filesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
plugins.Filesystems.TryGetValue(idPlugins[0], out fs);
|
||||
|
||||
if(pluginType == null || Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
if(fs is null)
|
||||
break;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, fs.Name)}[/]");
|
||||
@@ -416,7 +416,7 @@ sealed class FilesystemInfoCommand : Command
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
AaruConsole.ErrorWriteLine(string.Format(UI.Error_reading_file_0, ex.Message));
|
||||
AaruConsole.ErrorWriteLine(Markup.Escape(string.Format(UI.Error_reading_file_0, ex.Message)));
|
||||
AaruConsole.DebugWriteLine(MODULE_NAME, ex.StackTrace);
|
||||
|
||||
return (int)ErrorNumber.UnexpectedException;
|
||||
|
||||
@@ -165,12 +165,15 @@ sealed class FormatsCommand : Command
|
||||
|
||||
AaruConsole.WriteLine();
|
||||
|
||||
var idOnlyFilesystems = plugins.Filesystems.Where(t => !plugins.ReadOnlyFilesystems.ContainsKey(t.Key)).
|
||||
Select(t => t.Value).
|
||||
Where(t => t is not null).
|
||||
ToList();
|
||||
|
||||
table = new Table
|
||||
{
|
||||
Title = new TableTitle(string.Format(UI.Supported_filesystems_for_identification_and_information_only_0,
|
||||
plugins.Filesystems.Count(t => !t.Value.GetInterfaces().
|
||||
Contains(typeof(
|
||||
IReadOnlyFilesystem)))))
|
||||
idOnlyFilesystems.Count))
|
||||
};
|
||||
|
||||
if(verbose)
|
||||
@@ -178,13 +181,9 @@ sealed class FormatsCommand : Command
|
||||
|
||||
table.AddColumn(UI.Title_Filesystem);
|
||||
|
||||
foreach(KeyValuePair<string, Type> kvp in plugins.Filesystems.Where(t => !t.Value.GetInterfaces().
|
||||
Contains(typeof(
|
||||
IReadOnlyFilesystem))))
|
||||
{
|
||||
if(Activator.CreateInstance(kvp.Value) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
foreach(IFilesystem fs in idOnlyFilesystems)
|
||||
{
|
||||
if(verbose)
|
||||
table.AddRow(fs.Id.ToString(), Markup.Escape(fs.Name));
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user