From 991ee847129371f238981d14e7d9f4df4c2933b8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 20 Jul 2018 22:53:46 +0100 Subject: [PATCH] Implement IOC for plugin registration. --- .../.idea/contentModel.xml | 7 + .../DiscImageChef.Checksums.csproj | 1 + DiscImageChef.Checksums/Register.cs | 95 +++++++++++ .../DiscImageChef.CommonTypes.csproj | 1 + .../Interfaces/IPluginRegister.cs | 100 ++++++++++++ DiscImageChef.CommonTypes/PluginBase.cs | 152 ++++++++---------- DiscImageChef.Core/DiscImageChef.Core.csproj | 1 + DiscImageChef.Core/Filesystems.cs | 2 +- DiscImageChef.Core/GetPluginBase.cs | 63 ++++++++ DiscImageChef.Core/ImageFormat.cs | 2 +- DiscImageChef.Core/Partitions.cs | 2 +- DiscImageChef.Core/Sidecar/Sidecar.cs | 2 +- .../DiscImageChef.DiscImages.csproj | 1 + DiscImageChef.DiscImages/Register.cs | 100 ++++++++++++ .../DiscImageChef.Filesystems.csproj | 1 + DiscImageChef.Filesystems/Register.cs | 97 +++++++++++ .../DiscImageChef.Filters.csproj | 1 + DiscImageChef.Filters/Register.cs | 95 +++++++++++ .../DiscImageChef.Partitions.csproj | 1 + DiscImageChef.Partitions/Register.cs | 95 +++++++++++ DiscImageChef/Commands/Analyze.cs | 3 +- DiscImageChef/Commands/ConvertImage.cs | 3 +- DiscImageChef/Commands/DumpMedia.cs | 2 +- DiscImageChef/Commands/ExtractFiles.cs | 3 +- DiscImageChef/Commands/Formats.cs | 3 +- DiscImageChef/Commands/ListOptions.cs | 2 +- DiscImageChef/Commands/Ls.cs | 3 +- 27 files changed, 735 insertions(+), 103 deletions(-) create mode 100644 DiscImageChef.Checksums/Register.cs create mode 100644 DiscImageChef.CommonTypes/Interfaces/IPluginRegister.cs create mode 100644 DiscImageChef.Core/GetPluginBase.cs create mode 100644 DiscImageChef.DiscImages/Register.cs create mode 100644 DiscImageChef.Filesystems/Register.cs create mode 100644 DiscImageChef.Filters/Register.cs create mode 100644 DiscImageChef.Partitions/Register.cs diff --git a/.idea/.idea.DiscImageChef/.idea/contentModel.xml b/.idea/.idea.DiscImageChef/.idea/contentModel.xml index 8ca42633b..c7497797d 100644 --- a/.idea/.idea.DiscImageChef/.idea/contentModel.xml +++ b/.idea/.idea.DiscImageChef/.idea/contentModel.xml @@ -67,6 +67,7 @@ + @@ -109,6 +110,7 @@ + @@ -219,6 +221,7 @@ + @@ -522,6 +525,7 @@ + @@ -659,6 +663,7 @@ + @@ -707,6 +712,7 @@ + @@ -756,6 +762,7 @@ + diff --git a/DiscImageChef.Checksums/DiscImageChef.Checksums.csproj b/DiscImageChef.Checksums/DiscImageChef.Checksums.csproj index 0f1368e41..febea8af3 100644 --- a/DiscImageChef.Checksums/DiscImageChef.Checksums.csproj +++ b/DiscImageChef.Checksums/DiscImageChef.Checksums.csproj @@ -46,6 +46,7 @@ + diff --git a/DiscImageChef.Checksums/Register.cs b/DiscImageChef.Checksums/Register.cs new file mode 100644 index 000000000..b8fd8afdd --- /dev/null +++ b/DiscImageChef.Checksums/Register.cs @@ -0,0 +1,95 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Register.cs +// Author(s) : Natalia Portillo +// +// Component : Core algorithms. +// +// --[ Description ] ---------------------------------------------------------- +// +// Registers all plugins in this assembly. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using DiscImageChef.CommonTypes.Interfaces; + +namespace DiscImageChef.Checksums +{ + public class Register : IPluginRegister + { + public List GetAllChecksumPlugins() + { + return Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IChecksum))) + .Where(t => t.IsClass).ToList(); + } + + public List GetAllFilesystemPlugins() + { + return null; + } + + public List GetAllFilterPlugins() + { + return null; + } + + public List GetAllFloppyImagePlugins() + { + return null; + } + + public List GetAllMediaImagePlugins() + { + return null; + } + + public List GetAllPartitionPlugins() + { + return null; + } + + public List GetAllReadOnlyFilesystemPlugins() + { + return null; + } + + public List GetAllWritableFloppyImagePlugins() + { + return null; + } + + public List GetAllWritableImagePlugins() + { + return null; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj b/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj index 5bf5d8761..82a6cf82d 100644 --- a/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj +++ b/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj @@ -68,6 +68,7 @@ + diff --git a/DiscImageChef.CommonTypes/Interfaces/IPluginRegister.cs b/DiscImageChef.CommonTypes/Interfaces/IPluginRegister.cs new file mode 100644 index 000000000..4c2466149 --- /dev/null +++ b/DiscImageChef.CommonTypes/Interfaces/IPluginRegister.cs @@ -0,0 +1,100 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : IPluginsRegister.cs +// Author(s) : Natalia Portillo +// +// Component : Interfaces. +// +// --[ Description ] ---------------------------------------------------------- +// +// Interface that declares class and methods to call to register plugins. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; + +namespace DiscImageChef.CommonTypes.Interfaces +{ + public interface IPluginRegister + { + /// + /// Gets all checksum plugins + /// + /// List of checksum plugins + List GetAllChecksumPlugins(); + + /// + /// Gets all filesystem plugins + /// + /// List of filesystem plugins + List GetAllFilesystemPlugins(); + + /// + /// Gets all filter plugins + /// + /// List of filter plugins + List GetAllFilterPlugins(); + + /// + /// Gets all floppy image plugins + /// + /// List of floppy image plugins + List GetAllFloppyImagePlugins(); + + /// + /// Gets all media image plugins + /// + /// List of media image plugins + List GetAllMediaImagePlugins(); + + /// + /// Gets all partition plugins + /// + /// List of partition plugins + List GetAllPartitionPlugins(); + + /// + /// Gets all read-only filesystem plugins + /// + /// List of read-only filesystem plugins + List GetAllReadOnlyFilesystemPlugins(); + + /// + /// Gets all writable floppy image plugins + /// + /// List of writable floppy image plugins + List GetAllWritableFloppyImagePlugins(); + + /// + /// Gets all writable media image plugins + /// + /// List of writable media image plugins + List GetAllWritableImagePlugins(); + } +} \ No newline at end of file diff --git a/DiscImageChef.CommonTypes/PluginBase.cs b/DiscImageChef.CommonTypes/PluginBase.cs index 673eb9d80..84c1be396 100644 --- a/DiscImageChef.CommonTypes/PluginBase.cs +++ b/DiscImageChef.CommonTypes/PluginBase.cs @@ -39,9 +39,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using DiscImageChef.CommonTypes.Interfaces; -using DiscImageChef.Console; using DiscImageChef.Partitions; namespace DiscImageChef.CommonTypes @@ -51,6 +49,18 @@ namespace DiscImageChef.CommonTypes /// public class PluginBase { + /// + /// List of checksum plugins + /// + public readonly List Checksums; + /// + /// List of filter plugins + /// + public readonly SortedDictionary Filters; + /// + /// List of floppy image plugins + /// + public readonly SortedDictionary FloppyImages; /// /// List of all media image plugins /// @@ -68,6 +78,10 @@ namespace DiscImageChef.CommonTypes /// public readonly SortedDictionary ReadOnlyFilesystems; /// + /// List of writable floppy image plugins + /// + public readonly SortedDictionary WritableFloppyImages; + /// /// List of writable media image plugins /// public readonly SortedDictionary WritableImages; @@ -77,98 +91,62 @@ namespace DiscImageChef.CommonTypes /// public PluginBase() { - PluginsList = new SortedDictionary(); - ReadOnlyFilesystems = new SortedDictionary(); - PartPluginsList = new SortedDictionary(); - ImagePluginsList = new SortedDictionary(); - WritableImages = new SortedDictionary(); - - // We need to manually load assemblies :( - AppDomain.CurrentDomain.Load("DiscImageChef.DiscImages"); - AppDomain.CurrentDomain.Load("DiscImageChef.Filesystems"); - AppDomain.CurrentDomain.Load("DiscImageChef.Partitions"); - - Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach(Assembly assembly in assemblies) - { - foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IMediaImage))) - .Where(t => t.IsClass)) - try - { - IMediaImage plugin = - (IMediaImage)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }); - RegisterImagePlugin(plugin); - } - catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } - - foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IPartition))) - .Where(t => t.IsClass)) - try - { - IPartition plugin = (IPartition)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }); - RegisterPartPlugin(plugin); - } - catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } - - foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilesystem))) - .Where(t => t.IsClass)) - try - { - IFilesystem plugin = - (IFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }); - RegisterPlugin(plugin); - } - catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } - - foreach(Type type in assembly - .GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IReadOnlyFilesystem))) - .Where(t => t.IsClass)) - try - { - IReadOnlyFilesystem plugin = - (IReadOnlyFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }); - RegisterReadOnlyFilesystem(plugin); - } - catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } - - foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IWritableImage))) - .Where(t => t.IsClass)) - try - { - IWritableImage plugin = - (IWritableImage)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }); - RegisterWritableMedia(plugin); - } - catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } - } + PluginsList = new SortedDictionary(); + ReadOnlyFilesystems = new SortedDictionary(); + PartPluginsList = new SortedDictionary(); + ImagePluginsList = new SortedDictionary(); + WritableImages = new SortedDictionary(); + Checksums = new List(); + Filters = new SortedDictionary(); + FloppyImages = new SortedDictionary(); + WritableFloppyImages = new SortedDictionary(); } - void RegisterImagePlugin(IMediaImage plugin) + public void AddPlugins(IPluginRegister pluginRegister) { - if(!ImagePluginsList.ContainsKey(plugin.Name.ToLower())) - ImagePluginsList.Add(plugin.Name.ToLower(), plugin); - } + foreach(Type type in pluginRegister.GetAllChecksumPlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IChecksum plugin) + Checksums.Add(plugin); - void RegisterPlugin(IFilesystem plugin) - { - if(!PluginsList.ContainsKey(plugin.Name.ToLower())) PluginsList.Add(plugin.Name.ToLower(), plugin); - } + foreach(Type type in pluginRegister.GetAllFilesystemPlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IFilesystem plugin && + !PluginsList.ContainsKey(plugin.Name.ToLower())) + PluginsList.Add(plugin.Name.ToLower(), plugin); - void RegisterReadOnlyFilesystem(IReadOnlyFilesystem plugin) - { - if(!ReadOnlyFilesystems.ContainsKey(plugin.Name.ToLower())) - ReadOnlyFilesystems.Add(plugin.Name.ToLower(), plugin); - } + foreach(Type type in pluginRegister.GetAllFilterPlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IFilter plugin && + !Filters.ContainsKey(plugin.Name.ToLower())) + Filters.Add(plugin.Name.ToLower(), plugin); - void RegisterWritableMedia(IWritableImage plugin) - { - if(!WritableImages.ContainsKey(plugin.Name.ToLower())) WritableImages.Add(plugin.Name.ToLower(), plugin); - } + foreach(Type type in pluginRegister.GetAllFloppyImagePlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IFloppyImage plugin && + !FloppyImages.ContainsKey(plugin.Name.ToLower())) + FloppyImages.Add(plugin.Name.ToLower(), plugin); - void RegisterPartPlugin(IPartition partplugin) - { - if(!PartPluginsList.ContainsKey(partplugin.Name.ToLower())) - PartPluginsList.Add(partplugin.Name.ToLower(), partplugin); + foreach(Type type in pluginRegister.GetAllMediaImagePlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IMediaImage plugin && + !ImagePluginsList.ContainsKey(plugin.Name.ToLower())) + ImagePluginsList.Add(plugin.Name.ToLower(), plugin); + + foreach(Type type in pluginRegister.GetAllPartitionPlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IPartition plugin && + !PartPluginsList.ContainsKey(plugin.Name.ToLower())) + PartPluginsList.Add(plugin.Name.ToLower(), plugin); + + foreach(Type type in pluginRegister.GetAllReadOnlyFilesystemPlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IReadOnlyFilesystem plugin && + !ReadOnlyFilesystems.ContainsKey(plugin.Name.ToLower())) + ReadOnlyFilesystems.Add(plugin.Name.ToLower(), plugin); + + foreach(Type type in pluginRegister.GetAllWritableFloppyImagePlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IWritableFloppyImage plugin && + !WritableFloppyImages.ContainsKey(plugin.Name.ToLower())) + WritableFloppyImages.Add(plugin.Name.ToLower(), plugin); + + foreach(Type type in pluginRegister.GetAllWritableImagePlugins() ?? Enumerable.Empty()) + if(type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { }) is IWritableImage plugin && + !WritableImages.ContainsKey(plugin.Name.ToLower())) + WritableImages.Add(plugin.Name.ToLower(), plugin); } } } \ No newline at end of file diff --git a/DiscImageChef.Core/DiscImageChef.Core.csproj b/DiscImageChef.Core/DiscImageChef.Core.csproj index 99ecbf342..402db4173 100644 --- a/DiscImageChef.Core/DiscImageChef.Core.csproj +++ b/DiscImageChef.Core/DiscImageChef.Core.csproj @@ -46,6 +46,7 @@ + diff --git a/DiscImageChef.Core/Filesystems.cs b/DiscImageChef.Core/Filesystems.cs index e094f9499..694614bea 100644 --- a/DiscImageChef.Core/Filesystems.cs +++ b/DiscImageChef.Core/Filesystems.cs @@ -48,7 +48,7 @@ namespace DiscImageChef.Core /// Partition public static void Identify(IMediaImage imagePlugin, out List idPlugins, Partition partition) { - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; idPlugins = (from plugin in plugins.PluginsList.Values where plugin.Identify(imagePlugin, partition) diff --git a/DiscImageChef.Core/GetPluginBase.cs b/DiscImageChef.Core/GetPluginBase.cs new file mode 100644 index 000000000..5d530f43a --- /dev/null +++ b/DiscImageChef.Core/GetPluginBase.cs @@ -0,0 +1,63 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ImageFormat.cs +// Author(s) : Natalia Portillo +// +// Component : Core algorithms. +// +// --[ Description ] ---------------------------------------------------------- +// +// Gets a new instance of all known plugins. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using DiscImageChef.Checksums; +using DiscImageChef.CommonTypes; +using DiscImageChef.CommonTypes.Interfaces; + +namespace DiscImageChef.Core +{ + public static class GetPluginBase + { + public static PluginBase Instance + { + get + { + PluginBase instance = new PluginBase(); + + IPluginRegister checksumRegister = new Register(); + IPluginRegister imagesRegister = new DiscImages.Register(); + IPluginRegister filesystemsRegister = new DiscImageChef.Filesystems.Register(); + IPluginRegister filtersRegister = new Filters.Register(); + IPluginRegister partitionsRegister = new DiscImageChef.Partitions.Register(); + + instance.AddPlugins(checksumRegister); + instance.AddPlugins(imagesRegister); + instance.AddPlugins(filesystemsRegister); + instance.AddPlugins(filtersRegister); + instance.AddPlugins(partitionsRegister); + + return instance; + } + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Core/ImageFormat.cs b/DiscImageChef.Core/ImageFormat.cs index 25514f182..622374646 100644 --- a/DiscImageChef.Core/ImageFormat.cs +++ b/DiscImageChef.Core/ImageFormat.cs @@ -49,7 +49,7 @@ namespace DiscImageChef.Core { try { - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; IMediaImage imageFormat = null; diff --git a/DiscImageChef.Core/Partitions.cs b/DiscImageChef.Core/Partitions.cs index d5815ddc4..a409d064e 100644 --- a/DiscImageChef.Core/Partitions.cs +++ b/DiscImageChef.Core/Partitions.cs @@ -51,7 +51,7 @@ namespace DiscImageChef.Core /// List of found partitions public static List GetAll(IMediaImage image) { - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; List foundPartitions = new List(); List childPartitions = new List(); List checkedLocations = new List(); diff --git a/DiscImageChef.Core/Sidecar/Sidecar.cs b/DiscImageChef.Core/Sidecar/Sidecar.cs index f5a1352e9..d86913ae9 100644 --- a/DiscImageChef.Core/Sidecar/Sidecar.cs +++ b/DiscImageChef.Core/Sidecar/Sidecar.cs @@ -54,7 +54,7 @@ namespace DiscImageChef.Core public static CICMMetadataType Create(IMediaImage image, string imagePath, Guid filterId, Encoding encoding) { CICMMetadataType sidecar = image.CicmMetadata ?? new CICMMetadataType(); - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; FileInfo fi = new FileInfo(imagePath); FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read); diff --git a/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj b/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj index 07debf0b0..e58e84de4 100644 --- a/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj +++ b/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj @@ -65,6 +65,7 @@ + diff --git a/DiscImageChef.DiscImages/Register.cs b/DiscImageChef.DiscImages/Register.cs new file mode 100644 index 000000000..855fe9e48 --- /dev/null +++ b/DiscImageChef.DiscImages/Register.cs @@ -0,0 +1,100 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Register.cs +// Author(s) : Natalia Portillo +// +// Component : Core algorithms. +// +// --[ Description ] ---------------------------------------------------------- +// +// Registers all plugins in this assembly. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using DiscImageChef.CommonTypes.Interfaces; + +namespace DiscImageChef.DiscImages +{ + public class Register : IPluginRegister + { + public List GetAllChecksumPlugins() + { + return null; + } + + public List GetAllFilesystemPlugins() + { + return null; + } + + public List GetAllFilterPlugins() + { + return null; + } + + public List GetAllFloppyImagePlugins() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.GetInterfaces().Contains(typeof(IFloppyImage))).Where(t => t.IsClass).ToList(); + } + + public List GetAllMediaImagePlugins() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.GetInterfaces().Contains(typeof(IMediaImage))).Where(t => t.IsClass).ToList(); + } + + public List GetAllPartitionPlugins() + { + return null; + } + + public List GetAllReadOnlyFilesystemPlugins() + { + return null; + } + + public List GetAllWritableFloppyImagePlugins() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.GetInterfaces().Contains(typeof(IWritableFloppyImage))).Where(t => t.IsClass) + .ToList(); + } + + public List GetAllWritableImagePlugins() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.GetInterfaces().Contains(typeof(IWritableImage))).Where(t => t.IsClass) + .ToList(); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj index 1f6a43d89..2e3595fe0 100644 --- a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj +++ b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj @@ -70,6 +70,7 @@ + diff --git a/DiscImageChef.Filesystems/Register.cs b/DiscImageChef.Filesystems/Register.cs new file mode 100644 index 000000000..601c55df2 --- /dev/null +++ b/DiscImageChef.Filesystems/Register.cs @@ -0,0 +1,97 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Register.cs +// Author(s) : Natalia Portillo +// +// Component : Core algorithms. +// +// --[ Description ] ---------------------------------------------------------- +// +// Registers all plugins in this assembly. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using DiscImageChef.CommonTypes.Interfaces; + +namespace DiscImageChef.Filesystems +{ + public class Register : IPluginRegister + { + public List GetAllChecksumPlugins() + { + return null; + } + + public List GetAllFilesystemPlugins() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.GetInterfaces().Contains(typeof(IFilesystem))).Where(t => t.IsClass).ToList(); + } + + public List GetAllFilterPlugins() + { + return null; + } + + public List GetAllFloppyImagePlugins() + { + return null; + } + + public List GetAllMediaImagePlugins() + { + return null; + } + + public List GetAllPartitionPlugins() + { + return null; + } + + public List GetAllReadOnlyFilesystemPlugins() + { + return Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.GetInterfaces().Contains(typeof(IReadOnlyFilesystem))).Where(t => t.IsClass) + .ToList(); + } + + public List GetAllWritableFloppyImagePlugins() + { + return null; + } + + public List GetAllWritableImagePlugins() + { + return null; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Filters/DiscImageChef.Filters.csproj b/DiscImageChef.Filters/DiscImageChef.Filters.csproj index c4605691a..632ade0b2 100644 --- a/DiscImageChef.Filters/DiscImageChef.Filters.csproj +++ b/DiscImageChef.Filters/DiscImageChef.Filters.csproj @@ -46,6 +46,7 @@ + diff --git a/DiscImageChef.Filters/Register.cs b/DiscImageChef.Filters/Register.cs new file mode 100644 index 000000000..4208ddbfe --- /dev/null +++ b/DiscImageChef.Filters/Register.cs @@ -0,0 +1,95 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Register.cs +// Author(s) : Natalia Portillo +// +// Component : Core algorithms. +// +// --[ Description ] ---------------------------------------------------------- +// +// Registers all plugins in this assembly. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using DiscImageChef.CommonTypes.Interfaces; + +namespace DiscImageChef.Filters +{ + public class Register : IPluginRegister + { + public List GetAllChecksumPlugins() + { + return null; + } + + public List GetAllFilesystemPlugins() + { + return null; + } + + public List GetAllFilterPlugins() + { + return Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilter))) + .Where(t => t.IsClass).ToList(); + } + + public List GetAllFloppyImagePlugins() + { + return null; + } + + public List GetAllMediaImagePlugins() + { + return null; + } + + public List GetAllPartitionPlugins() + { + return null; + } + + public List GetAllReadOnlyFilesystemPlugins() + { + return null; + } + + public List GetAllWritableFloppyImagePlugins() + { + return null; + } + + public List GetAllWritableImagePlugins() + { + return null; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj b/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj index e3c1c851e..f596a066c 100644 --- a/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj +++ b/DiscImageChef.Partitions/DiscImageChef.Partitions.csproj @@ -51,6 +51,7 @@ + diff --git a/DiscImageChef.Partitions/Register.cs b/DiscImageChef.Partitions/Register.cs new file mode 100644 index 000000000..1d9d154b0 --- /dev/null +++ b/DiscImageChef.Partitions/Register.cs @@ -0,0 +1,95 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Register.cs +// Author(s) : Natalia Portillo +// +// Component : Core algorithms. +// +// --[ Description ] ---------------------------------------------------------- +// +// Registers all plugins in this assembly. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using DiscImageChef.CommonTypes.Interfaces; + +namespace DiscImageChef.Partitions +{ + public class Register : IPluginRegister + { + public List GetAllChecksumPlugins() + { + return null; + } + + public List GetAllFilesystemPlugins() + { + return null; + } + + public List GetAllFilterPlugins() + { + return null; + } + + public List GetAllFloppyImagePlugins() + { + return null; + } + + public List GetAllMediaImagePlugins() + { + return null; + } + + public List GetAllPartitionPlugins() + { + return Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IPartition))) + .Where(t => t.IsClass).ToList(); + } + + public List GetAllReadOnlyFilesystemPlugins() + { + return null; + } + + public List GetAllWritableFloppyImagePlugins() + { + return null; + } + + public List GetAllWritableImagePlugins() + { + return null; + } + } +} \ No newline at end of file diff --git a/DiscImageChef/Commands/Analyze.cs b/DiscImageChef/Commands/Analyze.cs index 79addcaf1..4b68944fe 100644 --- a/DiscImageChef/Commands/Analyze.cs +++ b/DiscImageChef/Commands/Analyze.cs @@ -37,7 +37,6 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using DiscImageChef.Core; -using DiscImageChef.Filters; namespace DiscImageChef.Commands { @@ -75,7 +74,7 @@ namespace DiscImageChef.Commands return; } - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; bool checkraw = false; diff --git a/DiscImageChef/Commands/ConvertImage.cs b/DiscImageChef/Commands/ConvertImage.cs index 955a6a813..d6705c904 100644 --- a/DiscImageChef/Commands/ConvertImage.cs +++ b/DiscImageChef/Commands/ConvertImage.cs @@ -42,7 +42,6 @@ using DiscImageChef.CommonTypes.Metadata; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; using DiscImageChef.Core; -using DiscImageChef.Filters; using Schemas; using Version = DiscImageChef.CommonTypes.Interop.Version; @@ -146,7 +145,7 @@ namespace DiscImageChef.Commands return; } - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; IMediaImage inputFormat = ImageFormat.Detect(inputFilter); if(inputFormat == null) diff --git a/DiscImageChef/Commands/DumpMedia.cs b/DiscImageChef/Commands/DumpMedia.cs index b1ade643a..a1dde48ea 100644 --- a/DiscImageChef/Commands/DumpMedia.cs +++ b/DiscImageChef/Commands/DumpMedia.cs @@ -159,7 +159,7 @@ namespace DiscImageChef.Commands return; } - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; List candidates = new List(); // Try extension diff --git a/DiscImageChef/Commands/ExtractFiles.cs b/DiscImageChef/Commands/ExtractFiles.cs index 09385deef..b6659aeb3 100644 --- a/DiscImageChef/Commands/ExtractFiles.cs +++ b/DiscImageChef/Commands/ExtractFiles.cs @@ -39,7 +39,6 @@ using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; using DiscImageChef.Core; -using DiscImageChef.Filters; namespace DiscImageChef.Commands { @@ -83,7 +82,7 @@ namespace DiscImageChef.Commands return; } - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; try { diff --git a/DiscImageChef/Commands/Formats.cs b/DiscImageChef/Commands/Formats.cs index 0067b366c..ba3be7b5b 100644 --- a/DiscImageChef/Commands/Formats.cs +++ b/DiscImageChef/Commands/Formats.cs @@ -36,7 +36,6 @@ using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.Console; using DiscImageChef.Core; -using DiscImageChef.Filters; using DiscImageChef.Partitions; namespace DiscImageChef.Commands @@ -45,7 +44,7 @@ namespace DiscImageChef.Commands { internal static void ListFormats(FormatsOptions formatsOptions) { - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; FiltersList filtersList = new FiltersList(); DicConsole.WriteLine("Supported filters ({0}):", filtersList.Filters.Count); diff --git a/DiscImageChef/Commands/ListOptions.cs b/DiscImageChef/Commands/ListOptions.cs index 74c735a5b..ecaad3b42 100644 --- a/DiscImageChef/Commands/ListOptions.cs +++ b/DiscImageChef/Commands/ListOptions.cs @@ -44,7 +44,7 @@ namespace DiscImageChef.Commands { internal static void DoList() { - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; DicConsole.WriteLine("Read-only filesystems options:"); foreach(KeyValuePair kvp in plugins.ReadOnlyFilesystems) diff --git a/DiscImageChef/Commands/Ls.cs b/DiscImageChef/Commands/Ls.cs index 624a69d72..3a4f1e960 100644 --- a/DiscImageChef/Commands/Ls.cs +++ b/DiscImageChef/Commands/Ls.cs @@ -38,7 +38,6 @@ using DiscImageChef.CommonTypes.Interfaces; using DiscImageChef.CommonTypes.Structs; using DiscImageChef.Console; using DiscImageChef.Core; -using DiscImageChef.Filters; namespace DiscImageChef.Commands { @@ -79,7 +78,7 @@ namespace DiscImageChef.Commands return; } - PluginBase plugins = new PluginBase(); + PluginBase plugins = GetPluginBase.Instance; try {