2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Filename : PluginBase.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Component : Core algorithms.
|
2016-07-28 18:13:49 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Class to hold all installed plugins.
|
2016-07-28 18:13:49 +01:00
|
|
|
//
|
|
|
|
|
// --[ 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-26 06:05:12 +00:00
|
|
|
using System.Linq;
|
2014-04-14 02:29:13 +00:00
|
|
|
using System.Reflection;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Console;
|
2017-12-20 17:15:26 +00:00
|
|
|
using DiscImageChef.DiscImages;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.Filesystems;
|
2017-12-20 17:15:26 +00:00
|
|
|
using DiscImageChef.Partitions;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2017-05-27 14:54:15 +01:00
|
|
|
namespace DiscImageChef.Core
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2017-12-23 01:46:08 +00:00
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
/// Contain all plugins (filesystem, partition and image)
|
2017-12-23 01:46:08 +00:00
|
|
|
/// </summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public class PluginBase
|
|
|
|
|
{
|
2017-12-23 01:46:08 +00:00
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
/// List of all media image plugins
|
2017-12-23 01:46:08 +00:00
|
|
|
/// </summary>
|
2017-12-26 06:43:29 +00:00
|
|
|
public readonly SortedDictionary<string, IMediaImage> ImagePluginsList;
|
2017-12-23 01:46:08 +00:00
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
/// List of all partition plugins
|
2017-12-23 01:46:08 +00:00
|
|
|
/// </summary>
|
2017-12-26 06:43:29 +00:00
|
|
|
public readonly SortedDictionary<string, IPartition> PartPluginsList;
|
2017-12-23 01:46:08 +00:00
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
/// List of all filesystem plugins
|
2017-12-23 01:46:08 +00:00
|
|
|
/// </summary>
|
2017-12-26 06:43:29 +00:00
|
|
|
public readonly SortedDictionary<string, IFilesystem> PluginsList;
|
2017-12-26 07:23:09 +00:00
|
|
|
/// <summary>
|
2017-12-28 18:38:52 +00:00
|
|
|
/// List of read-only filesystem plugins
|
2017-12-26 07:23:09 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public readonly SortedDictionary<string, IReadOnlyFilesystem> ReadOnlyFilesystems;
|
2017-12-28 18:38:52 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// List of writable media image plugins
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly SortedDictionary<string, IWritableImage> WritableImages;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
/// Initializes the plugins lists
|
2017-12-23 01:46:08 +00:00
|
|
|
/// </summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public PluginBase()
|
|
|
|
|
{
|
2017-12-28 18:38:52 +00:00
|
|
|
PluginsList = new SortedDictionary<string, IFilesystem>();
|
2017-12-26 07:23:09 +00:00
|
|
|
ReadOnlyFilesystems = new SortedDictionary<string, IReadOnlyFilesystem>();
|
2017-12-28 18:38:52 +00:00
|
|
|
PartPluginsList = new SortedDictionary<string, IPartition>();
|
|
|
|
|
ImagePluginsList = new SortedDictionary<string, IMediaImage>();
|
|
|
|
|
WritableImages = new SortedDictionary<string, IWritableImage>();
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
Assembly assembly = Assembly.GetAssembly(typeof(IMediaImage));
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2017-12-28 18:38:52 +00:00
|
|
|
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IMediaImage)))
|
|
|
|
|
.Where(t => t.IsClass))
|
2011-03-03 18:34:33 +00:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
IMediaImage plugin = (IMediaImage)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
2017-12-21 06:06:19 +00:00
|
|
|
RegisterImagePlugin(plugin);
|
2015-10-05 19:45:07 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
2015-10-05 19:45:07 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
assembly = Assembly.GetAssembly(typeof(IPartition));
|
2015-10-05 19:58:42 +01:00
|
|
|
|
2017-12-28 18:38:52 +00:00
|
|
|
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IPartition)))
|
|
|
|
|
.Where(t => t.IsClass))
|
2015-10-05 19:58:42 +01:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-28 18:38:52 +00:00
|
|
|
IPartition plugin = (IPartition)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
2017-12-21 06:06:19 +00:00
|
|
|
RegisterPartPlugin(plugin);
|
2015-10-05 19:58:42 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
2015-10-05 19:58:42 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
assembly = Assembly.GetAssembly(typeof(IFilesystem));
|
2015-10-05 19:45:07 +01:00
|
|
|
|
2017-12-28 18:38:52 +00:00
|
|
|
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilesystem)))
|
|
|
|
|
.Where(t => t.IsClass))
|
2015-10-05 19:45:07 +01:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
IFilesystem plugin = (IFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
2017-12-21 06:06:19 +00:00
|
|
|
RegisterPlugin(plugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
2017-12-28 18:38:52 +00:00
|
|
|
|
2017-12-26 07:23:09 +00:00
|
|
|
assembly = Assembly.GetAssembly(typeof(IReadOnlyFilesystem));
|
|
|
|
|
|
2017-12-28 18:38:52 +00:00
|
|
|
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IReadOnlyFilesystem)))
|
|
|
|
|
.Where(t => t.IsClass))
|
2017-12-26 07:23:09 +00:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-28 18:38:52 +00:00
|
|
|
IReadOnlyFilesystem plugin =
|
|
|
|
|
(IReadOnlyFilesystem)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
|
2017-12-26 07:23:09 +00:00
|
|
|
RegisterReadOnlyFilesystem(plugin);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
2017-12-28 18:38:52 +00:00
|
|
|
|
|
|
|
|
assembly = Assembly.GetAssembly(typeof(IWritableImage));
|
|
|
|
|
|
|
|
|
|
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); }
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
void RegisterImagePlugin(IMediaImage plugin)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2017-12-23 17:41:23 +00:00
|
|
|
if(!ImagePluginsList.ContainsKey(plugin.Name.ToLower()))
|
|
|
|
|
ImagePluginsList.Add(plugin.Name.ToLower(), plugin);
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
void RegisterPlugin(IFilesystem plugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(!PluginsList.ContainsKey(plugin.Name.ToLower())) PluginsList.Add(plugin.Name.ToLower(), plugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:23:09 +00:00
|
|
|
void RegisterReadOnlyFilesystem(IReadOnlyFilesystem plugin)
|
|
|
|
|
{
|
2017-12-28 18:38:52 +00:00
|
|
|
if(!ReadOnlyFilesystems.ContainsKey(plugin.Name.ToLower()))
|
|
|
|
|
ReadOnlyFilesystems.Add(plugin.Name.ToLower(), plugin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegisterWritableMedia(IWritableImage plugin)
|
|
|
|
|
{
|
|
|
|
|
if(!WritableImages.ContainsKey(plugin.Name.ToLower())) WritableImages.Add(plugin.Name.ToLower(), plugin);
|
2017-12-26 07:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
void RegisterPartPlugin(IPartition partplugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2017-12-23 17:41:23 +00:00
|
|
|
if(!PartPluginsList.ContainsKey(partplugin.Name.ToLower()))
|
|
|
|
|
PartPluginsList.Add(partplugin.Name.ToLower(), partplugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|