// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : ArchiveFormat.cs // Author(s) : Natalia Portillo // // Component : Core algorithms. // // --[ Description ] ---------------------------------------------------------- // // Detects archive 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ using System; using Aaru.CommonTypes; using Aaru.CommonTypes.Interfaces; using Aaru.Logging; using Sentry; namespace Aaru.Core; /// Core archive format operations public static class ArchiveFormat { const string MODULE_NAME = "Format detection"; /// Detects the archive plugin that recognizes the data inside a filter /// Filter /// Detected archive plugin public static IArchive Detect(IFilter archiveFilter) { ITransactionTracer transaction = SentrySdk.StartTransaction("GetPlugin", "DetectArchive"); try { PluginRegister plugins = PluginRegister.Singleton; IArchive format = null; // Check all but RAW plugin foreach(IArchive plugin in plugins.Archives.Values) { if(plugin is null) continue; try { AaruLogging.Debug(MODULE_NAME, Localization.Core.Trying_plugin_0, plugin.Name); if(!plugin.Identify(archiveFilter)) continue; format = plugin; break; } catch(Exception ex) { SentrySdk.CaptureException(ex); } } // Not recognized transaction.Finish(); return format; } catch(Exception ex) { SentrySdk.CaptureException(ex); transaction.Finish(); return null; } } }