mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use Type for filesystem plugin list.
This commit is contained in:
@@ -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,7 +53,15 @@ public static class Filesystems
|
||||
{
|
||||
PluginBase plugins = GetPluginBase.Instance;
|
||||
|
||||
idPlugins = (from plugin in plugins.PluginsList.Values where plugin.Identify(imagePlugin, partition)
|
||||
select getGuid ? plugin.Id.ToString() : plugin.Name.ToLower()).ToList();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,7 +709,7 @@ public sealed partial class Sidecar
|
||||
|
||||
List<FileSystem> lstFs = new();
|
||||
|
||||
foreach(IFilesystem plugin in plugins.PluginsList.Values)
|
||||
foreach(IFilesystem plugin in plugins.Filesystems.Values)
|
||||
try
|
||||
{
|
||||
if(_aborted)
|
||||
@@ -766,7 +766,7 @@ public sealed partial class Sidecar
|
||||
|
||||
List<FileSystem> lstFs = new();
|
||||
|
||||
foreach(IFilesystem plugin in plugins.PluginsList.Values)
|
||||
foreach(IFilesystem plugin in plugins.Filesystems.Values)
|
||||
try
|
||||
{
|
||||
if(_aborted)
|
||||
|
||||
@@ -530,7 +530,7 @@ public sealed partial class Sidecar
|
||||
|
||||
List<FileSystem> lstFs = new();
|
||||
|
||||
foreach(IFilesystem plugin in plugins.PluginsList.Values)
|
||||
foreach(IFilesystem plugin in plugins.Filesystems.Values)
|
||||
try
|
||||
{
|
||||
if(_aborted)
|
||||
@@ -588,7 +588,7 @@ public sealed partial class Sidecar
|
||||
Sequence = xmlTrk.Sequence.Number
|
||||
};
|
||||
|
||||
foreach(IFilesystem plugin in plugins.PluginsList.Values)
|
||||
foreach(IFilesystem plugin in plugins.Filesystems.Values)
|
||||
try
|
||||
{
|
||||
if(_aborted)
|
||||
|
||||
@@ -97,7 +97,7 @@ public sealed class PluginsViewModel : ViewModelBase
|
||||
Author = partition.Author
|
||||
});
|
||||
|
||||
foreach(IFilesystem filesystem in GetPluginBase.Instance.PluginsList.Values)
|
||||
foreach(IFilesystem filesystem in GetPluginBase.Instance.Filesystems.Values)
|
||||
Filesystems.Add(new PluginModel
|
||||
{
|
||||
Name = filesystem.Name,
|
||||
|
||||
@@ -593,7 +593,7 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
|
||||
bool checkRaw = false;
|
||||
List<string> idPlugins;
|
||||
IFilesystem plugin;
|
||||
Type pluginType;
|
||||
PluginBase plugins = GetPluginBase.Instance;
|
||||
|
||||
if(partitions.Count == 0)
|
||||
@@ -636,11 +636,14 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
AaruConsole.WriteLine(string.Format(UI.Identified_by_0_plugins, idPlugins.Count));
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.PluginsList.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
plugin.GetInformation(imageFormat, partition, out string information, null);
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
var fsPlugin = plugin as IReadOnlyFilesystem;
|
||||
fs.GetInformation(imageFormat, partition, out string information, null);
|
||||
|
||||
var fsPlugin = fs as IReadOnlyFilesystem;
|
||||
|
||||
if(fsPlugin != null)
|
||||
{
|
||||
@@ -655,11 +658,11 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
var filesystemModel = new FileSystemModel
|
||||
{
|
||||
VolumeName =
|
||||
plugin.Metadata.VolumeName is null ? $"{plugin.Metadata.Type}"
|
||||
: $"{plugin.Metadata.VolumeName} ({plugin.Metadata.Type})",
|
||||
Filesystem = plugin,
|
||||
fs.Metadata.VolumeName is null ? $"{fs.Metadata.Type}"
|
||||
: $"{fs.Metadata.VolumeName} ({fs.Metadata.Type})",
|
||||
Filesystem = fs,
|
||||
ReadOnlyFilesystem = fsPlugin,
|
||||
ViewModel = new FileSystemViewModel(plugin.Metadata, information)
|
||||
ViewModel = new FileSystemViewModel(fs.Metadata, information)
|
||||
};
|
||||
|
||||
// TODO: Trap expanding item
|
||||
@@ -675,7 +678,7 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
Statistics.AddCommand("ls");
|
||||
}
|
||||
|
||||
Statistics.AddFilesystem(plugin.Metadata.Type);
|
||||
Statistics.AddFilesystem(fs.Metadata.Type);
|
||||
partitionModel.FileSystems.Add(filesystemModel);
|
||||
}
|
||||
}
|
||||
@@ -705,11 +708,14 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
AaruConsole.WriteLine(string.Format(UI.Identified_by_0_plugins, idPlugins.Count));
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.PluginsList.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
plugin.GetInformation(imageFormat, wholePart, out string information, null);
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
var fsPlugin = plugin as IReadOnlyFilesystem;
|
||||
fs.GetInformation(imageFormat, wholePart, out string information, null);
|
||||
|
||||
var fsPlugin = fs as IReadOnlyFilesystem;
|
||||
|
||||
if(fsPlugin != null)
|
||||
{
|
||||
@@ -722,11 +728,11 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
|
||||
var filesystemModel = new FileSystemModel
|
||||
{
|
||||
VolumeName = plugin.Metadata.VolumeName is null ? $"{plugin.Metadata.Type}"
|
||||
: $"{plugin.Metadata.VolumeName} ({plugin.Metadata.Type})",
|
||||
Filesystem = plugin,
|
||||
VolumeName = fs.Metadata.VolumeName is null ? $"{fs.Metadata.Type}"
|
||||
: $"{fs.Metadata.VolumeName} ({fs.Metadata.Type})",
|
||||
Filesystem = fs,
|
||||
ReadOnlyFilesystem = fsPlugin,
|
||||
ViewModel = new FileSystemViewModel(plugin.Metadata, information)
|
||||
ViewModel = new FileSystemViewModel(fs.Metadata, information)
|
||||
};
|
||||
|
||||
// TODO: Trap expanding item
|
||||
@@ -742,7 +748,7 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
Statistics.AddCommand("ls");
|
||||
}
|
||||
|
||||
Statistics.AddFilesystem(plugin.Metadata.Type);
|
||||
Statistics.AddFilesystem(fs.Metadata.Type);
|
||||
imageModel.PartitionSchemesOrFileSystems.Add(filesystemModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,14 +237,12 @@ public abstract class BlockMediaImageTest : BaseMediaImageTest
|
||||
string pluginName = idPlugins[j];
|
||||
|
||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName,
|
||||
out IReadOnlyFilesystem plugin))
|
||||
out Type pluginType))
|
||||
continue;
|
||||
|
||||
Assert.IsNotNull(plugin, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
Assert.IsNotNull(pluginType, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(new object[]
|
||||
{});
|
||||
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
|
||||
|
||||
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, pluginName));
|
||||
|
||||
@@ -278,13 +276,12 @@ public abstract class BlockMediaImageTest : BaseMediaImageTest
|
||||
{
|
||||
string pluginName = idPlugins[j];
|
||||
|
||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem plugin))
|
||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out Type pluginType))
|
||||
continue;
|
||||
|
||||
Assert.IsNotNull(plugin, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
Assert.IsNotNull(pluginType, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
|
||||
|
||||
Assert.IsNotNull(fs, $"Could not instantiate filesystem {pluginName} in {testFile}");
|
||||
|
||||
|
||||
@@ -188,14 +188,14 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
||||
for(int i = 0; i < track.FileSystems.Length; i++)
|
||||
{
|
||||
PluginBase plugins = GetPluginBase.Instance;
|
||||
bool found = plugins.PluginsList.TryGetValue(idPlugins[i], out IFilesystem plugin);
|
||||
bool found = plugins.Filesystems.TryGetValue(idPlugins[i], out Type pluginType);
|
||||
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
// It is not the case, it changes
|
||||
if(!found)
|
||||
continue;
|
||||
|
||||
var fs = Activator.CreateInstance(plugin.GetType()) as IFilesystem;
|
||||
var fs = Activator.CreateInstance(pluginType) as IFilesystem;
|
||||
|
||||
Assert.NotNull(fs,
|
||||
string.Format(Localization.Could_not_instantiate_filesystem_for_0,
|
||||
@@ -230,7 +230,7 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
||||
Assert.AreEqual(track.FileSystems[i].VolumeSerial, fs.Metadata.VolumeSerial,
|
||||
string.Format(Localization.Volume_serial_0, testFile));
|
||||
|
||||
if(Activator.CreateInstance(plugin.GetType()) is not IReadOnlyFilesystem rofs)
|
||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem rofs)
|
||||
{
|
||||
if(track.FileSystems[i].Contents != null ||
|
||||
track.FileSystems[i].ContentsJson != null ||
|
||||
|
||||
@@ -121,13 +121,12 @@ public abstract class FsExtractHashIssueTest
|
||||
{
|
||||
string pluginName = idPlugins[j];
|
||||
|
||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out IReadOnlyFilesystem plugin))
|
||||
if(!plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out Type pluginType))
|
||||
continue;
|
||||
|
||||
Assert.IsNotNull(plugin, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
Assert.IsNotNull(pluginType, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
|
||||
|
||||
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, pluginName));
|
||||
|
||||
|
||||
@@ -74,47 +74,48 @@ public abstract class FsExtractIssueTest
|
||||
if(idPlugins.Count == 0)
|
||||
continue;
|
||||
|
||||
IReadOnlyFilesystem plugin;
|
||||
ErrorNumber error;
|
||||
Type pluginType;
|
||||
ErrorNumber error;
|
||||
|
||||
if(idPlugins.Count > 1)
|
||||
{
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
Assert.IsNotNull(plugin, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
Assert.IsNotNull(pluginType, Localization.Could_not_instantiate_filesystem_plugin);
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
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;
|
||||
|
||||
error = fs.Mount(imageFormat, partitions[i], encodingClass, options, Namespace);
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, error, string.Format(Localization.Could_not_mount_0_in_partition_1, pluginName, i));
|
||||
Assert.AreEqual(ErrorNumber.NoError, error,
|
||||
string.Format(Localization.Could_not_mount_0_in_partition_1, pluginName, i));
|
||||
|
||||
ExtractFilesInDir("/", fs, Xattrs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out plugin);
|
||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
|
||||
if(plugin is null)
|
||||
if(pluginType is null)
|
||||
continue;
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
var fs = Activator.CreateInstance(pluginType) as IReadOnlyFilesystem;
|
||||
|
||||
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, plugin.Name));
|
||||
Assert.IsNotNull(fs, string.Format(Localization.Could_not_instantiate_filesystem_0, fs.Name));
|
||||
|
||||
filesystemFound = true;
|
||||
|
||||
error = fs.Mount(imageFormat, partitions[i], encodingClass, options, Namespace);
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, error, string.Format(Localization.Could_not_mount_0_in_partition_1, plugin.Name, i));
|
||||
Assert.AreEqual(ErrorNumber.NoError, error,
|
||||
string.Format(Localization.Could_not_mount_0_in_partition_1, fs.Name, i));
|
||||
|
||||
ExtractFilesInDir("/", fs, Xattrs);
|
||||
}
|
||||
@@ -137,7 +138,8 @@ public abstract class FsExtractIssueTest
|
||||
{
|
||||
error = fs.Stat(path + "/" + entry, out FileEntryInfo stat);
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, error, string.Format(Localization.Error_getting_stat_for_entry_0, entry));
|
||||
Assert.AreEqual(ErrorNumber.NoError, error,
|
||||
string.Format(Localization.Error_getting_stat_for_entry_0, entry));
|
||||
|
||||
if(stat.Attributes.HasFlag(FileAttributes.Directory))
|
||||
{
|
||||
@@ -151,7 +153,8 @@ public abstract class FsExtractIssueTest
|
||||
error = fs.ListXAttr(path + "/" + entry, out List<string> xattrs);
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, error,
|
||||
string.Format(Localization.Error_0_getting_extended_attributes_for_entry_1, error, path + "/" + entry));
|
||||
string.Format(Localization.Error_0_getting_extended_attributes_for_entry_1, error,
|
||||
path + "/" + entry));
|
||||
|
||||
if(error == ErrorNumber.NoError)
|
||||
foreach(string xattr in xattrs)
|
||||
@@ -160,7 +163,8 @@ public abstract class FsExtractIssueTest
|
||||
error = fs.GetXattr(path + "/" + entry, xattr, ref xattrBuf);
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, error,
|
||||
string.Format(Localization.Error_0_reading_extended_attributes_for_entry_1, error, path + "/" + entry));
|
||||
string.Format(Localization.Error_0_reading_extended_attributes_for_entry_1,
|
||||
error, path + "/" + entry));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +172,8 @@ public abstract class FsExtractIssueTest
|
||||
|
||||
error = fs.Read(path + "/" + entry, 0, stat.Length, ref outBuf);
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, error, string.Format(Localization.Error_0_reading_file_1, error, path + "/" + entry));
|
||||
Assert.AreEqual(ErrorNumber.NoError, error,
|
||||
string.Format(Localization.Error_0_reading_file_1, error, path + "/" + entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,8 +308,8 @@ sealed class ExtractFilesCommand : Command
|
||||
AaruConsole.WriteLine(UI.Filesystem_not_identified);
|
||||
else
|
||||
{
|
||||
IReadOnlyFilesystem plugin;
|
||||
ErrorNumber error = ErrorNumber.InvalidArgument;
|
||||
Type pluginType;
|
||||
ErrorNumber error = ErrorNumber.InvalidArgument;
|
||||
|
||||
if(idPlugins.Count > 1)
|
||||
{
|
||||
@@ -317,14 +317,12 @@ sealed class ExtractFilesCommand : Command
|
||||
}[/]");
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, plugin.Name)}[/]");
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, pluginType.Name)
|
||||
}[/]");
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
|
||||
if(fs is null)
|
||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||
@@ -350,18 +348,13 @@ sealed class ExtractFilesCommand : Command
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out plugin);
|
||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
|
||||
if(plugin == null)
|
||||
if(pluginType == null ||
|
||||
Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, plugin.Name)}[/]");
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
|
||||
if(fs is null)
|
||||
continue;
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, pluginType.Name)}[/]");
|
||||
|
||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||
{
|
||||
|
||||
@@ -221,7 +221,7 @@ sealed class FilesystemInfoCommand : Command
|
||||
}
|
||||
|
||||
List<string> idPlugins = null;
|
||||
IFilesystem plugin;
|
||||
Type pluginType;
|
||||
string information;
|
||||
|
||||
if(partitions)
|
||||
@@ -301,31 +301,35 @@ sealed class FilesystemInfoCommand : Command
|
||||
idPlugins.Count)}[/]");
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.PluginsList.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, plugin.Name)
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, fs.Name)
|
||||
}[/]");
|
||||
|
||||
plugin.GetInformation(imageFormat, partitionsList[i], out information,
|
||||
encodingClass);
|
||||
fs.GetInformation(imageFormat, partitionsList[i], out information,
|
||||
encodingClass);
|
||||
|
||||
AaruConsole.Write(information);
|
||||
Statistics.AddFilesystem(plugin.Metadata.Type);
|
||||
Statistics.AddFilesystem(fs.Metadata.Type);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
||||
plugins.Filesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
|
||||
if(plugin == null)
|
||||
if(pluginType == null ||
|
||||
Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, plugin.Name)}[/]");
|
||||
plugin.GetInformation(imageFormat, partitionsList[i], out information, encodingClass);
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, fs.Name)}[/]");
|
||||
fs.GetInformation(imageFormat, partitionsList[i], out information, encodingClass);
|
||||
AaruConsole.Write("{0}", information);
|
||||
Statistics.AddFilesystem(plugin.Metadata.Type);
|
||||
Statistics.AddFilesystem(fs.Metadata.Type);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -363,27 +367,31 @@ sealed class FilesystemInfoCommand : Command
|
||||
}[/]");
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.PluginsList.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.Filesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, plugin.Name)}[/]");
|
||||
plugin.GetInformation(imageFormat, wholePart, out information, encodingClass);
|
||||
if(Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, fs.Name)}[/]");
|
||||
fs.GetInformation(imageFormat, wholePart, out information, encodingClass);
|
||||
AaruConsole.Write(information);
|
||||
Statistics.AddFilesystem(plugin.Metadata.Type);
|
||||
Statistics.AddFilesystem(fs.Metadata.Type);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
||||
plugins.Filesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
|
||||
if(plugin != null)
|
||||
{
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, plugin.Name)}[/]");
|
||||
plugin.GetInformation(imageFormat, wholePart, out information, encodingClass);
|
||||
AaruConsole.Write(information);
|
||||
Statistics.AddFilesystem(plugin.Metadata.Type);
|
||||
}
|
||||
if(pluginType == null ||
|
||||
Activator.CreateInstance(pluginType) is not IFilesystem fs)
|
||||
break;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, fs.Name)}[/]");
|
||||
fs.GetInformation(imageFormat, wholePart, out information, encodingClass);
|
||||
AaruConsole.Write(information);
|
||||
Statistics.AddFilesystem(fs.Metadata.Type);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -279,8 +279,8 @@ sealed class LsCommand : Command
|
||||
AaruConsole.WriteLine(UI.Filesystem_not_identified);
|
||||
else
|
||||
{
|
||||
IReadOnlyFilesystem plugin;
|
||||
ErrorNumber error = ErrorNumber.InvalidArgument;
|
||||
Type pluginType;
|
||||
ErrorNumber error = ErrorNumber.InvalidArgument;
|
||||
|
||||
if(idPlugins.Count > 1)
|
||||
{
|
||||
@@ -288,16 +288,13 @@ sealed class LsCommand : Command
|
||||
}[/]");
|
||||
|
||||
foreach(string pluginName in idPlugins)
|
||||
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out plugin))
|
||||
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
||||
{
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, plugin.Name)}[/]");
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
|
||||
if(fs == null)
|
||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, fs.Name)}[/]");
|
||||
|
||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||
{
|
||||
ctx.AddTask(UI.Mounting_filesystem).IsIndeterminate();
|
||||
@@ -318,18 +315,12 @@ sealed class LsCommand : Command
|
||||
}
|
||||
else
|
||||
{
|
||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out plugin);
|
||||
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
||||
|
||||
if(plugin == null)
|
||||
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, plugin.Name)}[/]");
|
||||
|
||||
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
|
||||
Invoke(Array.Empty<object>());
|
||||
|
||||
if(fs == null)
|
||||
continue;
|
||||
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, fs.Name)}[/]");
|
||||
|
||||
Core.Spectre.ProgressSingleSpinner(ctx =>
|
||||
{
|
||||
|
||||
@@ -88,16 +88,19 @@ sealed class ListOptionsCommand : Command
|
||||
|
||||
AaruConsole.WriteLine(UI.Read_only_filesystems_options);
|
||||
|
||||
foreach(KeyValuePair<string, IReadOnlyFilesystem> kvp in plugins.ReadOnlyFilesystems)
|
||||
foreach(KeyValuePair<string, Type> kvp in plugins.ReadOnlyFilesystems)
|
||||
{
|
||||
List<(string name, Type type, string description)> options = kvp.Value.SupportedOptions.ToList();
|
||||
if(Activator.CreateInstance(kvp.Value) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
List<(string name, Type type, string description)> options = fs.SupportedOptions.ToList();
|
||||
|
||||
if(options.Count == 0)
|
||||
continue;
|
||||
|
||||
var table = new Table
|
||||
{
|
||||
Title = new TableTitle(string.Format(UI.Options_for_0, kvp.Value.Name))
|
||||
Title = new TableTitle(string.Format(UI.Options_for_0, fs.Name))
|
||||
};
|
||||
|
||||
table.AddColumn(UI.Title_Name);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
// Copyright © 2011-2023 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.NamingConventionBinder;
|
||||
@@ -153,7 +154,7 @@ sealed class FormatsCommand : Command
|
||||
table = new Table
|
||||
{
|
||||
Title = new TableTitle(string.Format(UI.Supported_filesystems_for_identification_and_information_only_0,
|
||||
plugins.PluginsList.Count(t => !t.Value.GetType().GetInterfaces().
|
||||
plugins.Filesystems.Count(t => !t.Value.GetInterfaces().
|
||||
Contains(typeof(
|
||||
IReadOnlyFilesystem)))))
|
||||
};
|
||||
@@ -163,12 +164,18 @@ sealed class FormatsCommand : Command
|
||||
|
||||
table.AddColumn(UI.Title_Filesystem);
|
||||
|
||||
foreach(KeyValuePair<string, IFilesystem> kvp in plugins.PluginsList.Where(t => !t.Value.GetType().
|
||||
GetInterfaces().Contains(typeof(IReadOnlyFilesystem))))
|
||||
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;
|
||||
|
||||
if(verbose)
|
||||
table.AddRow(kvp.Value.Id.ToString(), Markup.Escape(kvp.Value.Name));
|
||||
table.AddRow(fs.Id.ToString(), Markup.Escape(fs.Name));
|
||||
else
|
||||
table.AddRow(Markup.Escape(kvp.Value.Name));
|
||||
}
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
|
||||
@@ -185,11 +192,16 @@ sealed class FormatsCommand : Command
|
||||
|
||||
table.AddColumn(UI.Title_Filesystem);
|
||||
|
||||
foreach(KeyValuePair<string, IReadOnlyFilesystem> kvp in plugins.ReadOnlyFilesystems)
|
||||
foreach(KeyValuePair<string, Type> kvp in plugins.ReadOnlyFilesystems)
|
||||
{
|
||||
if(Activator.CreateInstance(kvp.Value) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
if(verbose)
|
||||
table.AddRow(kvp.Value.Id.ToString(), Markup.Escape(kvp.Value.Name));
|
||||
table.AddRow(fs.Id.ToString(), Markup.Escape(fs.Name));
|
||||
else
|
||||
table.AddRow(Markup.Escape(kvp.Value.Name));
|
||||
table.AddRow(Markup.Escape(fs.Name));
|
||||
}
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
// Copyright © 2011-2023 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.NamingConventionBinder;
|
||||
@@ -84,18 +85,23 @@ sealed class ListNamespacesCommand : Command
|
||||
|
||||
PluginBase plugins = GetPluginBase.Instance;
|
||||
|
||||
foreach(KeyValuePair<string, IReadOnlyFilesystem> kvp in
|
||||
plugins.ReadOnlyFilesystems.Where(kvp => kvp.Value.Namespaces is not null))
|
||||
foreach(KeyValuePair<string, Type> kvp in plugins.ReadOnlyFilesystems)
|
||||
{
|
||||
if(Activator.CreateInstance(kvp.Value) is not IReadOnlyFilesystem fs)
|
||||
continue;
|
||||
|
||||
if(fs.Namespaces is null)
|
||||
continue;
|
||||
|
||||
Table table = new()
|
||||
{
|
||||
Title = new TableTitle(string.Format(UI.Namespaces_for_0, kvp.Value.Name))
|
||||
Title = new TableTitle(string.Format(UI.Namespaces_for_0, fs.Name))
|
||||
};
|
||||
|
||||
table.AddColumn(UI.Title_Namespace);
|
||||
table.AddColumn(UI.Title_Description);
|
||||
|
||||
foreach(KeyValuePair<string, string> @namespace in kvp.Value.Namespaces.OrderBy(t => t.Key))
|
||||
foreach(KeyValuePair<string, string> @namespace in fs.Namespaces.OrderBy(t => t.Key))
|
||||
table.AddRow(@namespace.Key, @namespace.Value);
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
|
||||
Reference in New Issue
Block a user