2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2015-10-12 06:39:31 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2015-10-12 06:39:31 +01:00
|
|
|
using System;
|
2017-12-21 07:08:26 +00:00
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.Console;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Core
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
|
|
|
|
public static class ImageFormat
|
|
|
|
|
{
|
2017-12-23 01:46:08 +00:00
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
/// Detects the image plugin that recognizes the data inside a filter
|
2017-12-23 01:46:08 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="imageFilter">Filter</param>
|
|
|
|
|
/// <returns>Detected image plugin</returns>
|
2017-12-26 06:05:12 +00:00
|
|
|
public static IMediaImage Detect(IFilter imageFilter)
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-07-20 22:53:46 +01:00
|
|
|
PluginBase plugins = GetPluginBase.Instance;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
IMediaImage imageFormat = null;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
|
|
|
|
// Check all but RAW plugin
|
2017-12-26 06:05:12 +00:00
|
|
|
foreach(IMediaImage imageplugin in plugins.ImagePluginsList.Values.Where(imageplugin =>
|
|
|
|
|
imageplugin.Id !=
|
2017-12-23 17:41:23 +00:00
|
|
|
new
|
|
|
|
|
Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
|
|
|
)
|
|
|
|
|
try
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2017-12-21 07:08:26 +00:00
|
|
|
DicConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imageplugin.Name);
|
2017-12-28 19:56:36 +00:00
|
|
|
if(!imageplugin.Identify(imageFilter)) continue;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
imageFormat = imageplugin;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-23 17:41:23 +00:00
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2017-12-21 23:00:30 +00:00
|
|
|
|
|
|
|
|
if(imageFormat != null) return imageFormat;
|
2017-12-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
// Check only RAW plugin
|
2017-12-26 06:05:12 +00:00
|
|
|
foreach(IMediaImage imageplugin in plugins.ImagePluginsList.Values.Where(imageplugin =>
|
|
|
|
|
imageplugin.Id ==
|
2017-12-23 17:41:23 +00:00
|
|
|
new
|
|
|
|
|
Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
|
|
|
)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imageplugin.Name);
|
2017-12-28 19:56:36 +00:00
|
|
|
if(!imageplugin.Identify(imageFilter)) continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2017-12-23 17:41:23 +00:00
|
|
|
imageFormat = imageplugin;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-23 17:41:23 +00:00
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2014-06-16 02:07:23 +01:00
|
|
|
|
|
|
|
|
// Still not recognized
|
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
|
|
|
}
|