2424import mmap
2525import os
2626
27+ import ctypes .util
2728from ctypes import c_char_p , c_wchar_p
2829from ctypes import c_int , c_longlong
2930from ctypes import c_size_t , c_ssize_t
8586# keys for plugin-provided locations
8687EXTRACTCODE_LIBARCHIVE_LIBDIR = 'extractcode.libarchive.libdir'
8788EXTRACTCODE_LIBARCHIVE_DLL = 'extractcode.libarchive.dll'
89+ _LIBRARY_NAME = 'libarchive'
8890
8991
9092def load_lib ():
@@ -96,11 +98,17 @@ def load_lib():
9698 dll = get_location (EXTRACTCODE_LIBARCHIVE_DLL )
9799 libdir = get_location (EXTRACTCODE_LIBARCHIVE_LIBDIR )
98100 if not (dll and libdir ) or not os .path .isfile (dll ) or not os .path .isdir (libdir ):
99- raise Exception (
100- 'CRITICAL: libarchive DLL is not installed. '
101- 'Unable to continue: you need to install a valid extractcode-libarchive '
102- 'plugin with a valid libarchive DLL available.'
103- )
101+ filepath = ctypes .util .find_library (_LIBRARY_NAME )
102+ libarchive = ctypes .cdll .LoadLibrary (filepath )
103+ if not libarchive :
104+ raise ImportError (
105+ 'CRITICAL: libarchive DLL is not installed. '
106+ 'Unable to continue: you need to install a valid extractcode-libarchive '
107+ 'plugin with a valid libarchive DLL available '
108+ 'or to have "libarchive" library installed in your system.'
109+ )
110+ logger .warning ('Cannot to use plugin for libarchive, defaulting to system library at ' + filepath )
111+ return libarchive
104112 return command .load_shared_library (dll , libdir )
105113
106114
0 commit comments