2014-04-17 19:58:14 +00:00
|
|
|
/***************************************************************************
|
2014-06-15 23:39:34 +01:00
|
|
|
The Disc Image Chef
|
2014-04-17 19:58:14 +00:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Filename : Plugins.cs
|
|
|
|
|
Version : 1.0
|
|
|
|
|
Author(s) : Natalia Portillo
|
|
|
|
|
|
|
|
|
|
Component : Plugins
|
|
|
|
|
|
|
|
|
|
Revision : $Revision$
|
|
|
|
|
Last change by : $Author$
|
|
|
|
|
Date : $Date$
|
|
|
|
|
|
|
|
|
|
--[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Base methods for plugins.
|
|
|
|
|
|
|
|
|
|
--[ License ] --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
2014-04-19 18:23:00 +01:00
|
|
|
it under the terms of the GNU General Public License as
|
2014-04-17 19:58:14 +00:00
|
|
|
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
|
2014-04-19 18:23:00 +01:00
|
|
|
GNU General Public License for more details.
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2014-04-19 18:23:00 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
2014-04-17 19:58:14 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
Copyright (C) 2011-2014 Claunia.com
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
//$Id$
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|