2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Plugins.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Plugins
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Base methods for 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// Copyright © 2011-2016 Natalia Portillo
|
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-04-14 02:29:13 +00:00
|
|
|
using System.Reflection;
|
2014-06-15 23:39:34 +01:00
|
|
|
using DiscImageChef.ImagePlugins;
|
|
|
|
|
using DiscImageChef.PartPlugins;
|
2016-07-21 16:15:39 +01:00
|
|
|
using DiscImageChef.Filesystems;
|
2016-01-11 19:24:17 +00:00
|
|
|
using DiscImageChef.Console;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2014-06-15 23:39:34 +01:00
|
|
|
namespace DiscImageChef
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
public class PluginBase
|
|
|
|
|
{
|
2016-07-21 16:15:39 +01:00
|
|
|
public Dictionary<string, Filesystem> PluginsList;
|
2014-04-14 02:29:13 +00:00
|
|
|
public Dictionary<string, PartPlugin> PartPluginsList;
|
2013-12-16 01:04:17 +00:00
|
|
|
public Dictionary<string, ImagePlugin> ImagePluginsList;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
|
|
|
public PluginBase()
|
|
|
|
|
{
|
2016-07-21 16:15:39 +01:00
|
|
|
PluginsList = new Dictionary<string, Filesystem>();
|
2014-04-14 02:29:13 +00:00
|
|
|
PartPluginsList = new Dictionary<string, PartPlugin>();
|
|
|
|
|
ImagePluginsList = new Dictionary<string, ImagePlugin>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterAllPlugins()
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2015-10-05 19:58:42 +01:00
|
|
|
Assembly assembly;
|
|
|
|
|
|
|
|
|
|
assembly = Assembly.GetAssembly(typeof(ImagePlugin));
|
2011-03-03 18:34:33 +00:00
|
|
|
|
|
|
|
|
foreach (Type type in assembly.GetTypes())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-12-16 01:04:17 +00:00
|
|
|
if (type.IsSubclassOf(typeof(ImagePlugin)))
|
|
|
|
|
{
|
2015-10-05 19:45:07 +01:00
|
|
|
ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
2014-04-14 02:29:13 +00:00
|
|
|
RegisterImagePlugin(plugin);
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
2015-10-05 19:45:07 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
2016-01-11 19:24:17 +00:00
|
|
|
DicConsole.ErrorWriteLine("Exception {0}", exception);
|
2015-10-05 19:45:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-05 19:58:42 +01:00
|
|
|
assembly = Assembly.GetAssembly(typeof(PartPlugin));
|
|
|
|
|
|
|
|
|
|
foreach (Type type in assembly.GetTypes())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (type.IsSubclassOf(typeof(PartPlugin)))
|
|
|
|
|
{
|
|
|
|
|
PartPlugin plugin = (PartPlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
|
|
|
|
RegisterPartPlugin(plugin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
2016-01-11 19:24:17 +00:00
|
|
|
DicConsole.ErrorWriteLine("Exception {0}", exception);
|
2015-10-05 19:58:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
assembly = Assembly.GetAssembly(typeof(Filesystem));
|
2015-10-05 19:45:07 +01:00
|
|
|
|
|
|
|
|
foreach (Type type in assembly.GetTypes())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-21 16:15:39 +01:00
|
|
|
if (type.IsSubclassOf(typeof(Filesystem)))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2016-07-21 16:15:39 +01:00
|
|
|
Filesystem plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
2014-04-14 02:29:13 +00:00
|
|
|
RegisterPlugin(plugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
2016-01-11 19:24:17 +00:00
|
|
|
DicConsole.ErrorWriteLine("Exception {0}", exception);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
void RegisterImagePlugin(ImagePlugin plugin)
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
if (!ImagePluginsList.ContainsKey(plugin.Name.ToLower()))
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
ImagePluginsList.Add(plugin.Name.ToLower(), plugin);
|
2013-12-16 01:04:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
void RegisterPlugin(Filesystem plugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
if (!PluginsList.ContainsKey(plugin.Name.ToLower()))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
PluginsList.Add(plugin.Name.ToLower(), plugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
void RegisterPartPlugin(PartPlugin partplugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
if (!PartPluginsList.ContainsKey(partplugin.Name.ToLower()))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
PartPluginsList.Add(partplugin.Name.ToLower(), partplugin);
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2011-03-03 18:34:33 +00:00
|
|
|
}
|
|
|
|
|
|