2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-09-05 17:37:31 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Filters.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Filters.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Enumerates all filters and instantiates the correct one.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library 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
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-09-05 17:37:31 +01:00
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filters
|
|
|
|
|
{
|
|
|
|
|
public class FiltersList
|
|
|
|
|
{
|
|
|
|
|
public SortedDictionary<string, Filter> filtersList;
|
|
|
|
|
|
|
|
|
|
public FiltersList()
|
|
|
|
|
{
|
|
|
|
|
Assembly assembly = Assembly.GetAssembly(typeof(Filter));
|
|
|
|
|
filtersList = new SortedDictionary<string, Filter>();
|
|
|
|
|
|
|
|
|
|
foreach(Type type in assembly.GetTypes())
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!type.IsSubclassOf(typeof(Filter))) continue;
|
|
|
|
|
|
|
|
|
|
Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
|
|
|
|
if(!filtersList.ContainsKey(filter.Name.ToLower())) filtersList.Add(filter.Name.ToLower(), filter);
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); }
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Filter GetFilter(string path)
|
|
|
|
|
{
|
2016-09-12 01:13:12 +01:00
|
|
|
Filter noFilter = null;
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
foreach(Filter filter in filtersList.Values)
|
2016-09-12 01:13:12 +01:00
|
|
|
if(filter.UUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!filter.Identify(path)) continue;
|
|
|
|
|
|
|
|
|
|
Filter foundFilter =
|
|
|
|
|
(Filter)filter.GetType().GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
|
|
|
|
|
foundFilter.Open(path);
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(foundFilter.IsOpened()) return foundFilter;
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else noFilter = filter;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!noFilter.Identify(path)) return noFilter;
|
|
|
|
|
|
|
|
|
|
noFilter.Open(path);
|
2016-09-13 14:52:31 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(noFilter.IsOpened()) return noFilter;
|
2016-09-13 14:52:31 +01:00
|
|
|
|
2016-09-12 01:13:12 +01:00
|
|
|
return noFilter;
|
2016-09-05 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SortedDictionary<string, Filter> GetFiltersList()
|
|
|
|
|
{
|
|
|
|
|
return filtersList;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|