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;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.Text;
|
|
|
|
|
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
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
public class PluginBase
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
public SortedDictionary<string, Filesystem> PluginsList;
|
2017-12-20 17:15:26 +00:00
|
|
|
public SortedDictionary<string, PartitionPlugin> PartPluginsList;
|
2016-09-05 17:37:31 +01:00
|
|
|
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>();
|
2017-12-20 17:15:26 +00:00
|
|
|
PartPluginsList = new SortedDictionary<string, PartitionPlugin>();
|
2016-09-05 17:37:31 +01:00
|
|
|
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
|
|
|
{
|
2017-12-21 23:00:30 +00:00
|
|
|
Assembly 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
|
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!type.IsSubclassOf(typeof(ImagePlugin))) continue;
|
|
|
|
|
|
2017-12-21 16:59:15 +00:00
|
|
|
ImagePlugin plugin = (ImagePlugin)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-20 17:15:26 +00:00
|
|
|
assembly = Assembly.GetAssembly(typeof(PartitionPlugin));
|
2015-10-05 19:58:42 +01:00
|
|
|
|
2016-07-28 22:25:26 +01:00
|
|
|
foreach(Type type in assembly.GetTypes())
|
2015-10-05 19:58:42 +01:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!type.IsSubclassOf(typeof(PartitionPlugin))) continue;
|
|
|
|
|
|
2017-12-21 16:59:15 +00:00
|
|
|
PartitionPlugin plugin = (PartitionPlugin)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
|
|
|
|
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
|
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!type.IsSubclassOf(typeof(Filesystem))) continue;
|
|
|
|
|
|
|
|
|
|
Filesystem plugin;
|
|
|
|
|
if(encoding != null)
|
2017-12-21 16:59:15 +00:00
|
|
|
plugin = (Filesystem)type.GetConstructor(new[] {encoding.GetType()})?.Invoke(new object[] {encoding});
|
|
|
|
|
else plugin = (Filesystem)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); }
|
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
|
|
|
{
|
2017-12-20 23:07:46 +00:00
|
|
|
if(!ImagePluginsList.ContainsKey(plugin.Name.ToLower())) 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
|
|
|
{
|
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-20 17:15:26 +00:00
|
|
|
void RegisterPartPlugin(PartitionPlugin partplugin)
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2017-12-20 23:07:46 +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
|
|
|
}
|