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