Files
Aaru/Aaru.Compression/Native.cs

83 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/>.
//
// ----------------------------------------------------------------------------
2022-12-03 16:07:10 +00:00
// Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/
2022-03-07 07:36:44 +00:00
using System.Runtime.InteropServices;
namespace Aaru.Compression;
/// <summary>Handles native implementations of compression algorithms</summary>
2022-03-06 13:29:38 +00:00
public static class Native
{
2022-03-06 13:29:38 +00:00
static bool _checked;
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
{
2022-03-06 13:29:38 +00:00
if(ForceManaged)
return false;
2022-03-06 13:29:38 +00:00
if(_checked)
return _supported;
2022-03-06 13:29:38 +00:00
ulong version;
_checked = true;
2022-03-06 13:29:38 +00:00
try
{
version = AARU_get_acn_version();
}
catch
{
_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
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern ulong AARU_get_acn_version();
}