diff --git a/Aaru.Compression/Aaru.Compression.csproj b/Aaru.Compression/Aaru.Compression.csproj index 02d77991c..02b8a5d1c 100644 --- a/Aaru.Compression/Aaru.Compression.csproj +++ b/Aaru.Compression/Aaru.Compression.csproj @@ -72,6 +72,7 @@ + @@ -88,6 +89,7 @@ + diff --git a/Aaru.Compression/Native.cs b/Aaru.Compression/Native.cs new file mode 100644 index 000000000..28155af40 --- /dev/null +++ b/Aaru.Compression/Native.cs @@ -0,0 +1,83 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : Native.cs +// Author(s) : Natalia Portillo +// +// 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2021 Natalia Portillo +// ****************************************************************************/ + +using System.Runtime.InteropServices; + +namespace Aaru.Compression +{ + public static class Native + { + static bool _checked; + static bool _supported; + + /// Set to return native as never supported + public static bool ForceManaged { get; set; } + + /// + /// If set to true the native library was found and loaded correctly and its reported version is + /// compatible. + /// + public static bool IsSupported + { + get + { + if(ForceManaged) + return false; + + if(_checked) + return _supported; + + ulong version; + _checked = true; + + try + { + version = get_acn_version(); + } + catch + { + _supported = false; + + return false; + } + + // TODO: Check version compatibility + _supported = version >= 0x06000000; + + return _supported; + } + } + + [DllImport("libAaru.Compression.Native", SetLastError = true)] + static extern ulong get_acn_version(); + } +} \ No newline at end of file