2021-11-04 17:54:56 +00:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// 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-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2021-11-04 17:54:56 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
namespace Aaru.Compression;
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
2022-03-18 01:32:22 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles native implementations of compression algorithms
|
|
|
|
|
/// </summary>
|
2022-03-06 13:29:38 +00:00
|
|
|
public static class Native
|
2021-11-04 17:54:56 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
static bool _checked;
|
|
|
|
|
static bool _supported;
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Set to return native as never supported</summary>
|
|
|
|
|
public static bool ForceManaged { get; set; }
|
2021-11-04 17:54:56 +00:00
|
|
|
|
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
|
2021-11-04 17:54:56 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(ForceManaged)
|
|
|
|
|
return false;
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_checked)
|
|
|
|
|
return _supported;
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong version;
|
|
|
|
|
_checked = true;
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
version = AARU_get_acn_version();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_supported = false;
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// TODO: Check version compatibility
|
|
|
|
|
_supported = version >= 0x06000000;
|
2021-11-04 17:54:56 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return _supported;
|
2021-11-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
|
|
|
|
static extern ulong AARU_get_acn_version();
|
2021-11-04 17:54:56 +00:00
|
|
|
}
|