mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Plugin system] Move read-only filesystems to dependency injection.
This commit is contained in:
Submodule Aaru.CommonTypes updated: 76b70b1c75...f5de3435e5
@@ -204,16 +204,14 @@ public class PluginRegisterGenerator : ISourceGenerator
|
|||||||
|
|
||||||
if(readOnlyFileSystems?.Count > 0)
|
if(readOnlyFileSystems?.Count > 0)
|
||||||
{
|
{
|
||||||
sb.AppendLine(" public List<Type> GetAllReadOnlyFilesystemPlugins() => new()");
|
sb.AppendLine(" public void RegisterReadOnlyFilesystemPlugins(IServiceCollection services)");
|
||||||
sb.AppendLine(" {");
|
sb.AppendLine(" {");
|
||||||
|
|
||||||
foreach(string plugin in readOnlyFileSystems)
|
foreach(string plugin in readOnlyFileSystems)
|
||||||
sb.AppendLine($" typeof({plugin}),");
|
sb.AppendLine($" services.AddTransient<IReadOnlyFilesystem, {plugin}>();");
|
||||||
|
sb.AppendLine(" }");
|
||||||
sb.AppendLine(" };");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sb.AppendLine(" public List<Type> GetAllReadOnlyFilesystemPlugins() => null;");
|
sb.AppendLine(" public void RegisterReadOnlyFilesystemPlugins(IServiceCollection services) {}");
|
||||||
|
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
|
|||||||
@@ -132,16 +132,16 @@ public sealed class PluginsViewModel : ViewModelBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(Type readOnlyFilesystem in PluginRegister.Singleton.ReadOnlyFilesystems.Values)
|
foreach(IReadOnlyFilesystem fs in PluginRegister.Singleton.ReadOnlyFilesystems.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(readOnlyFilesystem) is not IReadOnlyFilesystem fs)
|
if(fs is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ReadOnlyFilesystems.Add(new PluginModel
|
ReadOnlyFilesystems.Add(new PluginModel
|
||||||
{
|
{
|
||||||
Name = fs.Name,
|
Name = fs.Name,
|
||||||
Uuid = fs.Id,
|
Uuid = fs.Id,
|
||||||
Version = Assembly.GetAssembly(readOnlyFilesystem)?.GetName().Version?.ToString(),
|
Version = Assembly.GetAssembly(fs.GetType())?.GetName().Version?.ToString(),
|
||||||
Author = fs.Author
|
Author = fs.Author
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,13 +282,9 @@ public abstract class BlockMediaImageTest : BaseMediaImageTest
|
|||||||
{
|
{
|
||||||
string pluginName = idPlugins[j];
|
string pluginName = idPlugins[j];
|
||||||
|
|
||||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out Type pluginType))
|
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem fs))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Assert.IsNotNull(pluginType, Localization.Could_not_instantiate_filesystem_plugin);
|
|
||||||
|
|
||||||
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
|
|
||||||
|
|
||||||
Assert.IsNotNull(fs, $"Could not instantiate filesystem {pluginName} in {testFile}");
|
Assert.IsNotNull(fs, $"Could not instantiate filesystem {pluginName} in {testFile}");
|
||||||
|
|
||||||
ErrorNumber error = fs.Mount(image, partitions[i], null, null, null);
|
ErrorNumber error = fs.Mount(image, partitions[i], null, null, null);
|
||||||
|
|||||||
@@ -202,15 +202,13 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
|||||||
for(var i = 0; i < track.FileSystems.Length; i++)
|
for(var i = 0; i < track.FileSystems.Length; i++)
|
||||||
{
|
{
|
||||||
PluginRegister plugins = PluginRegister.Singleton;
|
PluginRegister plugins = PluginRegister.Singleton;
|
||||||
bool found = plugins.Filesystems.TryGetValue(idPlugins[i], out Type pluginType);
|
bool found = plugins.Filesystems.TryGetValue(idPlugins[i], out IFilesystem fs);
|
||||||
|
|
||||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
// It is not the case, it changes
|
// It is not the case, it changes
|
||||||
if(!found)
|
if(!found)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var fs = Activator.CreateInstance(pluginType) as IFilesystem;
|
|
||||||
|
|
||||||
Assert.NotNull(fs,
|
Assert.NotNull(fs,
|
||||||
string.Format(Localization.Could_not_instantiate_filesystem_for_0,
|
string.Format(Localization.Could_not_instantiate_filesystem_for_0,
|
||||||
testFile));
|
testFile));
|
||||||
@@ -248,7 +246,7 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
|||||||
Assert.AreEqual(track.FileSystems[i].VolumeSerial, fsMetadata.VolumeSerial,
|
Assert.AreEqual(track.FileSystems[i].VolumeSerial, fsMetadata.VolumeSerial,
|
||||||
string.Format(Localization.Volume_serial_0, testFile));
|
string.Format(Localization.Volume_serial_0, testFile));
|
||||||
|
|
||||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem rofs)
|
if(fs is not IReadOnlyFilesystem rofs)
|
||||||
{
|
{
|
||||||
if(track.FileSystems[i].Contents != null ||
|
if(track.FileSystems[i].Contents != null ||
|
||||||
track.FileSystems[i].ContentsJson != null ||
|
track.FileSystems[i].ContentsJson != null ||
|
||||||
|
|||||||
@@ -124,13 +124,9 @@ public abstract class FsExtractHashIssueTest
|
|||||||
{
|
{
|
||||||
string pluginName = idPlugins[j];
|
string pluginName = idPlugins[j];
|
||||||
|
|
||||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out Type pluginType))
|
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem fs))
|
||||||
continue;
|
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));
|
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, pluginName));
|
||||||
|
|
||||||
filesystemFound = true;
|
filesystemFound = true;
|
||||||
|
|||||||
@@ -83,13 +83,9 @@ public abstract class FsExtractIssueTest
|
|||||||
{
|
{
|
||||||
foreach(string pluginName in idPlugins)
|
foreach(string pluginName in idPlugins)
|
||||||
{
|
{
|
||||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem fs))
|
||||||
continue;
|
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));
|
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, pluginName));
|
||||||
|
|
||||||
filesystemFound = true;
|
filesystemFound = true;
|
||||||
@@ -104,12 +100,7 @@ public abstract class FsExtractIssueTest
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out IReadOnlyFilesystem fs);
|
||||||
|
|
||||||
if(pluginType is null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
|
|
||||||
|
|
||||||
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, fs?.Name));
|
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, fs?.Name));
|
||||||
|
|
||||||
|
|||||||
@@ -321,15 +321,15 @@ sealed class ExtractFilesCommand : Command
|
|||||||
|
|
||||||
foreach(string pluginName in idPlugins)
|
foreach(string pluginName in idPlugins)
|
||||||
{
|
{
|
||||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem fs))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, pluginType.Name)
|
if(fs is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, fs.Name)
|
||||||
}[/]");
|
}[/]");
|
||||||
|
|
||||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||||
{
|
{
|
||||||
ctx.AddTask(UI.Mounting_filesystem).IsIndeterminate();
|
ctx.AddTask(UI.Mounting_filesystem).IsIndeterminate();
|
||||||
@@ -353,12 +353,12 @@ sealed class ExtractFilesCommand : Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out IReadOnlyFilesystem fs);
|
||||||
|
|
||||||
if(pluginType == null || Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
if(fs is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, pluginType.Name)}[/]");
|
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, fs.Name)}[/]");
|
||||||
|
|
||||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -294,9 +294,9 @@ sealed class LsCommand : Command
|
|||||||
|
|
||||||
foreach(string pluginName in idPlugins)
|
foreach(string pluginName in idPlugins)
|
||||||
{
|
{
|
||||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem fs))
|
||||||
continue;
|
continue;
|
||||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem 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)}[/]");
|
||||||
@@ -320,9 +320,9 @@ sealed class LsCommand : Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out IReadOnlyFilesystem fs);
|
||||||
|
|
||||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem 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)}[/]");
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.CommandLine;
|
using System.CommandLine;
|
||||||
using System.CommandLine.NamingConventionBinder;
|
using System.CommandLine.NamingConventionBinder;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -92,9 +91,9 @@ sealed class ListOptionsCommand : Command
|
|||||||
|
|
||||||
AaruConsole.WriteLine(UI.Read_only_filesystems_options);
|
AaruConsole.WriteLine(UI.Read_only_filesystems_options);
|
||||||
|
|
||||||
foreach(KeyValuePair<string, Type> kvp in plugins.ReadOnlyFilesystems)
|
foreach(IReadOnlyFilesystem fs in plugins.ReadOnlyFilesystems.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(kvp.Value) is not IReadOnlyFilesystem fs)
|
if(fs is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var options = fs.SupportedOptions.ToList();
|
var options = fs.SupportedOptions.ToList();
|
||||||
|
|||||||
@@ -181,7 +181,6 @@ sealed class FormatsCommand : Command
|
|||||||
|
|
||||||
table.AddColumn(UI.Title_Filesystem);
|
table.AddColumn(UI.Title_Filesystem);
|
||||||
|
|
||||||
|
|
||||||
foreach(IFilesystem fs in idOnlyFilesystems)
|
foreach(IFilesystem fs in idOnlyFilesystems)
|
||||||
{
|
{
|
||||||
if(verbose)
|
if(verbose)
|
||||||
@@ -205,9 +204,9 @@ sealed class FormatsCommand : Command
|
|||||||
|
|
||||||
table.AddColumn(UI.Title_Filesystem);
|
table.AddColumn(UI.Title_Filesystem);
|
||||||
|
|
||||||
foreach(KeyValuePair<string, Type> kvp in plugins.ReadOnlyFilesystems)
|
foreach(IReadOnlyFilesystem fs in plugins.ReadOnlyFilesystems.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(kvp.Value) is not IReadOnlyFilesystem fs)
|
if(fs is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
|
|||||||
@@ -944,7 +944,7 @@ sealed class ConvertImageCommand : Command
|
|||||||
|
|
||||||
if(plugins.ReadOnlyFilesystems.
|
if(plugins.ReadOnlyFilesystems.
|
||||||
TryGetValue("iso9660 filesystem",
|
TryGetValue("iso9660 filesystem",
|
||||||
out Type pluginType))
|
out IReadOnlyFilesystem rofs))
|
||||||
{
|
{
|
||||||
AaruConsole.DebugWriteLine(MODULE_NAME,
|
AaruConsole.DebugWriteLine(MODULE_NAME,
|
||||||
UI.Generating_decryption_keys);
|
UI.Generating_decryption_keys);
|
||||||
@@ -952,7 +952,7 @@ sealed class ConvertImageCommand : Command
|
|||||||
generatedTitleKeys =
|
generatedTitleKeys =
|
||||||
CSS.GenerateTitleKeys(inputOptical, partitions,
|
CSS.GenerateTitleKeys(inputOptical, partitions,
|
||||||
trackSectors,
|
trackSectors,
|
||||||
pluginType);
|
rofs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,7 +999,7 @@ sealed class ConvertImageCommand : Command
|
|||||||
|
|
||||||
if(plugins.ReadOnlyFilesystems.
|
if(plugins.ReadOnlyFilesystems.
|
||||||
TryGetValue("iso9660 filesystem",
|
TryGetValue("iso9660 filesystem",
|
||||||
out Type pluginType))
|
out IReadOnlyFilesystem rofs))
|
||||||
{
|
{
|
||||||
AaruConsole.DebugWriteLine(MODULE_NAME,
|
AaruConsole.DebugWriteLine(MODULE_NAME,
|
||||||
UI.Generating_decryption_keys);
|
UI.Generating_decryption_keys);
|
||||||
@@ -1007,7 +1007,7 @@ sealed class ConvertImageCommand : Command
|
|||||||
generatedTitleKeys =
|
generatedTitleKeys =
|
||||||
CSS.GenerateTitleKeys(inputOptical, partitions,
|
CSS.GenerateTitleKeys(inputOptical, partitions,
|
||||||
trackSectors,
|
trackSectors,
|
||||||
pluginType);
|
rofs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,12 +89,9 @@ sealed class ListNamespacesCommand : Command
|
|||||||
|
|
||||||
PluginRegister plugins = PluginRegister.Singleton;
|
PluginRegister plugins = PluginRegister.Singleton;
|
||||||
|
|
||||||
foreach(KeyValuePair<string, Type> kvp in plugins.ReadOnlyFilesystems)
|
foreach(IReadOnlyFilesystem fs in plugins.ReadOnlyFilesystems.Values)
|
||||||
{
|
{
|
||||||
if(Activator.CreateInstance(kvp.Value) is not IReadOnlyFilesystem fs)
|
if(fs?.Namespaces is null)
|
||||||
continue;
|
|
||||||
|
|
||||||
if(fs.Namespaces is null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Table table = new()
|
Table table = new()
|
||||||
|
|||||||
Reference in New Issue
Block a user