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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2015-10-12 06:39:31 +01:00
|
|
|
using System;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.Console;
|
2014-06-16 02:07:23 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Core;
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
/// <summary>Core media image format operations</summary>
|
|
|
|
|
public static class ImageFormat
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2023-10-03 17:17:16 +01:00
|
|
|
const string MODULE_NAME = "Format detection";
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
/// <summary>Detects the image plugin that recognizes the data inside a filter</summary>
|
|
|
|
|
/// <param name="imageFilter">Filter</param>
|
|
|
|
|
/// <returns>Detected image plugin</returns>
|
|
|
|
|
public static IBaseImage Detect(IFilter imageFilter)
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2022-12-17 20:50:17 +00:00
|
|
|
PluginBase plugins = PluginBase.Singleton;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
IBaseImage imageFormat = null;
|
|
|
|
|
|
|
|
|
|
// Check all but RAW plugin
|
2022-12-17 19:27:27 +00:00
|
|
|
foreach(Type pluginType in plugins.MediaImages.Values)
|
|
|
|
|
{
|
|
|
|
|
if(Activator.CreateInstance(pluginType) is not IMediaImage imagePlugin)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
2023-10-03 17:17:16 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Core.Trying_plugin_0, imagePlugin.Name);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
if(!imagePlugin.Identify(imageFilter))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
imageFormat = imagePlugin;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2022-12-17 19:27:27 +00:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
if(imageFormat != null)
|
|
|
|
|
return imageFormat;
|
|
|
|
|
|
|
|
|
|
// Check all but RAW plugin
|
2022-12-17 20:03:47 +00:00
|
|
|
foreach(Type pluginType in plugins.ByteAddressableImages.Values)
|
|
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
2022-12-17 20:03:47 +00:00
|
|
|
if(Activator.CreateInstance(pluginType) is not IByteAddressableImage imagePlugin)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-10-03 17:17:16 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Core.Trying_plugin_0, imagePlugin.Name);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
if(!imagePlugin.Identify(imageFilter))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
imageFormat = imagePlugin;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2022-12-17 20:03:47 +00:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
if(imageFormat != null)
|
2017-12-20 17:15:26 +00:00
|
|
|
return imageFormat;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
// Check only RAW plugin
|
2022-12-17 19:27:27 +00:00
|
|
|
foreach(Type pluginType in plugins.MediaImages.Values)
|
|
|
|
|
{
|
|
|
|
|
if(Activator.CreateInstance(pluginType) is not IMediaImage imagePlugin)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(imagePlugin.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
2023-10-03 17:17:16 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Core.Trying_plugin_0, imagePlugin.Name);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
if(!imagePlugin.Identify(imageFilter))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
imageFormat = imagePlugin;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2022-12-17 19:27:27 +00:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
// Still not recognized
|
|
|
|
|
return imageFormat;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return null;
|
2014-06-16 02:07:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|