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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2015-10-12 06:39:31 +01:00
|
|
|
using System;
|
2023-10-05 13:47:59 +01:00
|
|
|
using Aaru.CommonTypes;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2025-08-17 05:50:25 +01:00
|
|
|
using Aaru.Logging;
|
2025-08-20 18:51:05 +01:00
|
|
|
using Sentry;
|
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
|
|
|
{
|
2025-08-21 23:59:37 +01:00
|
|
|
ITransactionTracer transaction = SentrySdk.StartTransaction("GetPlugin", "DetectImageFormat");
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
2014-06-16 02:07:23 +01:00
|
|
|
{
|
2023-10-05 13:47:59 +01:00
|
|
|
PluginRegister plugins = PluginRegister.Singleton;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
IBaseImage imageFormat = null;
|
|
|
|
|
|
|
|
|
|
// Check all but RAW plugin
|
2025-08-20 16:14:19 +01:00
|
|
|
foreach(IMediaImage imagePlugin in plugins.MediaImages.Values)
|
2022-12-17 19:27:27 +00:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imagePlugin is null) continue;
|
2022-12-17 19:27:27 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) continue;
|
2022-12-17 19:27:27 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.Core.Trying_plugin_0, imagePlugin.Name);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!imagePlugin.Identify(imageFilter)) continue;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
imageFormat = imagePlugin;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-08-20 18:51:05 +01:00
|
|
|
catch(Exception ex)
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2025-08-20 18:51:05 +01:00
|
|
|
SentrySdk.CaptureException(ex);
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
2022-12-17 19:27:27 +00:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imageFormat != null) return imageFormat;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
// Check all but RAW plugin
|
2023-10-06 00:46:36 +01:00
|
|
|
foreach(IByteAddressableImage imagePlugin in plugins.ByteAddressableImages.Values)
|
2022-12-17 20:03:47 +00:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imagePlugin is null) continue;
|
2022-12-17 20:03:47 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) continue;
|
2022-12-17 20:03:47 +00:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.Core.Trying_plugin_0, imagePlugin.Name);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!imagePlugin.Identify(imageFilter)) continue;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
imageFormat = imagePlugin;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-08-20 18:51:05 +01:00
|
|
|
catch(Exception ex)
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2025-08-20 18:51:05 +01:00
|
|
|
SentrySdk.CaptureException(ex);
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
2022-12-17 20:03:47 +00:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2025-08-21 23:59:37 +01:00
|
|
|
if(imageFormat != null)
|
|
|
|
|
{
|
|
|
|
|
transaction.Finish();
|
|
|
|
|
|
|
|
|
|
return imageFormat;
|
|
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
// Check only RAW plugin
|
2025-08-20 16:14:19 +01:00
|
|
|
foreach(IMediaImage imagePlugin in plugins.MediaImages.Values)
|
2022-12-17 19:27:27 +00:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imagePlugin is null) continue;
|
2022-12-17 19:27:27 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(imagePlugin.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) continue;
|
2022-12-17 19:27:27 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.Core.Trying_plugin_0, imagePlugin.Name);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(!imagePlugin.Identify(imageFilter)) continue;
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
imageFormat = imagePlugin;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-08-20 18:51:05 +01:00
|
|
|
catch(Exception ex)
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2025-08-20 18:51:05 +01:00
|
|
|
SentrySdk.CaptureException(ex);
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
2022-12-17 19:27:27 +00:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
// Still not recognized
|
2025-08-21 23:59:37 +01:00
|
|
|
transaction.Finish();
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return imageFormat;
|
|
|
|
|
}
|
2025-08-20 18:51:05 +01:00
|
|
|
catch(Exception ex)
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2025-08-20 18:51:05 +01:00
|
|
|
SentrySdk.CaptureException(ex);
|
|
|
|
|
|
2025-08-21 23:59:37 +01:00
|
|
|
transaction.Finish();
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return null;
|
2014-06-16 02:07:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|