2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-12 06:39:31 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Filename : ImageFormat.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 ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Detects disc image format.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2015-10-12 06:39:31 +01:00
|
|
|
using System;
|
2016-10-10 02:05:49 +01:00
|
|
|
using DiscImageChef.Console;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Filters;
|
2017-12-20 17:15:26 +00:00
|
|
|
using DiscImageChef.DiscImages;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
2017-05-27 15:17:20 +01:00
|
|
|
namespace DiscImageChef.Core
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
|
|
|
|
public static class ImageFormat
|
|
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
public static ImagePlugin Detect(Filter imageFilter)
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
ImagePlugin imageFormat;
|
2014-06-16 02:07:23 +01:00
|
|
|
PluginBase plugins = new PluginBase();
|
|
|
|
|
plugins.RegisterAllPlugins();
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
imageFormat = null;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
|
|
|
|
// Check all but RAW plugin
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(ImagePlugin imageplugin in plugins.ImagePluginsList.Values)
|
|
|
|
|
if(imageplugin.PluginUuid != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2015-12-23 23:46:31 +00:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imageplugin.Name);
|
|
|
|
|
if(imageplugin.IdentifyImage(imageFilter))
|
2015-12-23 23:46:31 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
imageFormat = imageplugin;
|
2015-12-23 23:46:31 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-27 01:49:52 +01:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
catch { }
|
|
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2014-06-16 02:07:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check only RAW plugin
|
2017-12-20 17:15:26 +00:00
|
|
|
if(imageFormat == null)
|
|
|
|
|
foreach(ImagePlugin imageplugin in plugins.ImagePluginsList.Values)
|
|
|
|
|
if(imageplugin.PluginUuid == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2015-12-23 23:46:31 +00:00
|
|
|
try
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
DicConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imageplugin.Name);
|
|
|
|
|
if(imageplugin.IdentifyImage(imageFilter))
|
2015-12-23 23:46:31 +00:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
imageFormat = imageplugin;
|
2015-12-23 23:46:31 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-27 01:49:52 +01:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
catch { }
|
2016-08-27 01:49:52 +01:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2014-06-16 02:07:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Still not recognized
|
2017-12-20 23:07:46 +00:00
|
|
|
if(imageFormat == null) return null;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return imageFormat;
|
2014-06-16 02:07:23 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
catch { return null; }
|
2014-06-16 02:07:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|