2021-10-14 01:38:59 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Native.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Checksums.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Checks that Aaru.Checksums.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
|
2021-10-14 01:38:59 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2025-08-20 18:51:05 +01:00
|
|
|
using System;
|
2022-03-07 07:36:42 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2025-08-20 18:51:05 +01:00
|
|
|
using Sentry;
|
2022-03-07 07:36:42 +00:00
|
|
|
|
2022-11-23 18:16:04 +00:00
|
|
|
namespace Aaru.Checksums;
|
|
|
|
|
|
2022-11-15 15:58:41 +00:00
|
|
|
/// <summary>Handles native implementations of compression algorithms</summary>
|
2024-05-01 05:36:13 +01:00
|
|
|
public static partial class Native
|
2021-10-14 01:38:59 +01:00
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
static bool _supported;
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
/// <summary>Set to return native as never supported</summary>
|
|
|
|
|
public static bool ForceManaged { get; set; }
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2022-03-06 13:29:37 +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
|
2021-10-14 01:38:59 +01:00
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
if(ForceManaged) return false;
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2025-11-24 01:40:50 +00:00
|
|
|
if(field) return _supported;
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
ulong version;
|
2025-11-24 01:40:50 +00:00
|
|
|
field = true;
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
version = get_acn_version();
|
|
|
|
|
}
|
2025-08-20 18:51:05 +01:00
|
|
|
catch(Exception ex)
|
2022-03-06 13:29:37 +00:00
|
|
|
{
|
|
|
|
|
_supported = false;
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2025-08-20 18:51:05 +01:00
|
|
|
SentrySdk.CaptureException(ex);
|
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
// TODO: Check version compatibility
|
|
|
|
|
_supported = version >= 0x06000000;
|
2021-10-14 01:38:59 +01:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
return _supported;
|
2021-10-14 01:38:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-06 13:29:37 +00:00
|
|
|
|
2024-05-01 05:36:13 +01:00
|
|
|
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
|
|
|
|
private static partial ulong get_acn_version();
|
2021-10-14 01:38:59 +01:00
|
|
|
}
|