예제 #1
0
        static NativeMethods()
        {
            IntPtr library = FunctionLoader.LoadNativeLibrary(
                new string[] { "libzma.dll", "lzma.dll" },
                new string[] { "liblzma.so.5", "liblzma.so" },
                new string[] { "liblzma.dylib" });

            if (library == IntPtr.Zero)
            {
                throw new FileLoadException("Could not load liblzma. On Linux, make sure you've installed liblzma or an equivalent package.");
            }

            lzma_stream_decoder_ptr          = FunctionLoader.LoadFunctionDelegate <lzma_stream_decoder_delegate>(library, nameof(lzma_stream_decoder));
            lzma_auto_decoder_ptr            = FunctionLoader.LoadFunctionDelegate <lzma_auto_decoder_delegate>(library, nameof(lzma_auto_decoder));
            lzma_alone_decoder_ptr           = FunctionLoader.LoadFunctionDelegate <lzma_alone_decoder_delegate>(library, nameof(lzma_alone_decoder));
            lzma_code_ptr                    = FunctionLoader.LoadFunctionDelegate <lzma_code_delegate>(library, nameof(lzma_code));
            lzma_stream_footer_decode_ptr    = FunctionLoader.LoadFunctionDelegate <lzma_stream_footer_decode_delegate>(library, nameof(lzma_stream_footer_decode));
            lzma_index_uncompressed_size_ptr = FunctionLoader.LoadFunctionDelegate <lzma_index_uncompressed_size_delegate>(library, nameof(lzma_index_uncompressed_size));
            lzma_index_buffer_decode_ptr     = FunctionLoader.LoadFunctionDelegate <lzma_index_buffer_decode_delegate>(library, nameof(lzma_index_buffer_decode));
            lzma_index_end_ptr               = FunctionLoader.LoadFunctionDelegate <lzma_index_end_delegate>(library, nameof(lzma_index_end));
            lzma_end_ptr                 = FunctionLoader.LoadFunctionDelegate <lzma_end_delegate>(library, nameof(lzma_end));
            lzma_easy_encoder_ptr        = FunctionLoader.LoadFunctionDelegate <lzma_easy_encoder_delegate>(library, nameof(lzma_easy_encoder));
            lzma_stream_encoder_mt_ptr   = FunctionLoader.LoadFunctionDelegate <lzma_stream_encoder_mt_delegate>(library, nameof(lzma_stream_encoder_mt), throwOnError: false);
            lzma_stream_buffer_bound_ptr = FunctionLoader.LoadFunctionDelegate <lzma_stream_buffer_bound_delegate>(library, nameof(lzma_stream_buffer_bound));
            lzma_easy_buffer_encode_ptr  = FunctionLoader.LoadFunctionDelegate <lzma_easy_buffer_encode_delegate>(library, nameof(lzma_easy_buffer_encode));
        }
예제 #2
0
        static NativeMethods()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (RuntimeInformation.OSArchitecture != Architecture.X64)
                {
                    throw new InvalidOperationException(".NET packaging only supports 64-bit Windows processes");
                }
            }

            var libraryPath     = Path.GetDirectoryName(typeof(NativeMethods).GetTypeInfo().Assembly.Location);
            var lzmaWindowsPath = Path.GetFullPath(Path.Combine(libraryPath, "../../runtimes/win7-x64/native/lzma.dll"));

            IntPtr library = FunctionLoader.LoadNativeLibrary(
                new string[] { lzmaWindowsPath, "lzma.dll" }, // lzma.dll is used when running unit tests.
                new string[] { "liblzma.so.5", "liblzma.so" },
                new string[] { "liblzma.dylib" });

            if (library == IntPtr.Zero)
            {
                throw new FileLoadException("Could not load liblzma. On Linux, make sure you've installed liblzma-dev or an equivalent package.");
            }

            lzma_stream_decoder_ptr          = FunctionLoader.LoadFunctionDelegate <lzma_stream_decoder_delegate>(library, nameof(lzma_stream_decoder));
            lzma_code_ptr                    = FunctionLoader.LoadFunctionDelegate <lzma_code_delegate>(library, nameof(lzma_code));
            lzma_stream_footer_decode_ptr    = FunctionLoader.LoadFunctionDelegate <lzma_stream_footer_decode_delegate>(library, nameof(lzma_stream_footer_decode));
            lzma_index_uncompressed_size_ptr = FunctionLoader.LoadFunctionDelegate <lzma_index_uncompressed_size_delegate>(library, nameof(lzma_index_uncompressed_size));
            lzma_index_buffer_decode_ptr     = FunctionLoader.LoadFunctionDelegate <lzma_index_buffer_decode_delegate>(library, nameof(lzma_index_buffer_decode));
            lzma_index_end_ptr               = FunctionLoader.LoadFunctionDelegate <lzma_index_end_delegate>(library, nameof(lzma_index_end));
            lzma_end_ptr                 = FunctionLoader.LoadFunctionDelegate <lzma_end_delegate>(library, nameof(lzma_end));
            lzma_easy_encoder_ptr        = FunctionLoader.LoadFunctionDelegate <lzma_easy_encoder_delegate>(library, nameof(lzma_easy_encoder));
            lzma_stream_encoder_mt_ptr   = FunctionLoader.LoadFunctionDelegate <lzma_stream_encoder_mt_delegate>(library, nameof(lzma_stream_encoder_mt), throwOnError: false);
            lzma_stream_buffer_bound_ptr = FunctionLoader.LoadFunctionDelegate <lzma_stream_buffer_bound_delegate>(library, nameof(lzma_stream_buffer_bound));
            lzma_easy_buffer_encode_ptr  = FunctionLoader.LoadFunctionDelegate <lzma_easy_buffer_encode_delegate>(library, nameof(lzma_easy_buffer_encode));
        }