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;
|
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;
|
2017-10-12 23:54:02 +01:00
|
|
|
using System.Text;
|
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
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
public class PluginBase
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
public SortedDictionary<string, Filesystem> PluginsList;
|
|
|
|
|
public SortedDictionary<string, PartPlugin> PartPluginsList;
|
|
|
|
|
public SortedDictionary<string, ImagePlugin> ImagePluginsList;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
|
|
|
public PluginBase()
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
PluginsList = new SortedDictionary<string, Filesystem>();
|
|
|
|
|
PartPluginsList = new SortedDictionary<string, PartPlugin>();
|
|
|
|
|
ImagePluginsList = new SortedDictionary<string, ImagePlugin>();
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-12 23:54:02 +01:00
|
|
|
public void RegisterAllPlugins(Encoding encoding = null)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
Assembly assembly;
|
2015-10-05 19:58:42 +01:00
|
|
|
|
|
|
|
|
assembly = Assembly.GetAssembly(typeof(ImagePlugin));
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
foreach(Type type in assembly.GetTypes())
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
if(type.IsSubclassOf(typeof(ImagePlugin)))
|
2013-12-16 01:04:17 +00:00
|
|
|
{
|
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
|
|
|
}
|
2016-07-28 22:25:26 +01:00
|
|
|
catch(Exception exception)
|
2015-10-05 19:45:07 +01:00
|
|
|
{
|
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));
|
|
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
foreach(Type type in assembly.GetTypes())
|
2015-10-05 19:58:42 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
if(type.IsSubclassOf(typeof(PartPlugin)))
|
2015-10-05 19:58:42 +01:00
|
|
|
{
|
|
|
|
|
PartPlugin plugin = (PartPlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
|
|
|
|
RegisterPartPlugin(plugin);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-28 22:25:26 +01:00
|
|
|
catch(Exception exception)
|
2015-10-05 19:58:42 +01:00
|
|
|
{
|
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
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
foreach(Type type in assembly.GetTypes())
|
2015-10-05 19:45:07 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
if(type.IsSubclassOf(typeof(Filesystem)))
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2017-10-12 23:54:02 +01:00
|
|
|
Filesystem plugin;
|
|
|
|
|
if(encoding != null)
|
|
|
|
|
plugin = (Filesystem)type.GetConstructor(new Type[] { encoding.GetType() }).Invoke(new object[] { encoding });
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
2016-07-28 22:25:26 +01:00
|
|
|
catch(Exception exception)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
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
|
|
|
{
|
2016-07-28 22:25:26 +01: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
|
|
|
{
|
2016-07-28 22:25:26 +01: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
|
|
|
{
|
2016-07-28 22:25:26 +01: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
|
|
|
}
|
|
|
|
|
|