Files
Aaru/Aaru.Compression/Native.cs

84 lines
2.7 KiB
C#
Raw Normal View History

// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Native.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Compression.
//
// --[ Description ] ----------------------------------------------------------
//
// Checks that Aaru.Compression.Native library is available and usable.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
2025-08-20 18:51:05 +01:00
using System;
2022-03-07 07:36:44 +00:00
using System.Runtime.InteropServices;
2025-08-20 18:51:05 +01:00
using Sentry;
2022-03-07 07:36:44 +00:00
namespace Aaru.Compression;
/// <summary>Handles native implementations of compression algorithms</summary>
public static partial class Native
{
2022-03-06 13:29:38 +00:00
static bool _supported;
2022-03-06 13:29:38 +00:00
/// <summary>Set to return native as never supported</summary>
public static bool ForceManaged { get; set; }
2022-03-06 13:29:38 +00:00
/// <summary>
/// If set to <c>true</c> the native library was found and loaded correctly and its reported version is
/// compatible.
/// </summary>
public static bool IsSupported
{
get
{
2024-05-01 04:05:22 +01:00
if(ForceManaged) return false;
if(field) return _supported;
2022-03-06 13:29:38 +00:00
ulong version;
field = true;
2022-03-06 13:29:38 +00:00
try
{
version = AARU_get_acn_version();
}
2025-08-20 18:51:05 +01:00
catch(Exception ex)
2022-03-06 13:29:38 +00:00
{
2025-08-20 18:51:05 +01:00
SentrySdk.CaptureException(ex);
2022-03-06 13:29:38 +00:00
_supported = false;
2022-03-06 13:29:38 +00:00
return false;
}
2022-03-06 13:29:38 +00:00
// TODO: Check version compatibility
_supported = version >= 0x06000000;
2022-03-06 13:29:38 +00:00
return _supported;
}
}
2022-03-06 13:29:38 +00:00
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial ulong AARU_get_acn_version();
}