Skip to content

was able to test on Linux successfully #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib7zip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
def free_propvariant(void_p):
#TODO make smarter
pvar = ffi.cast('PROPVARIANT*', void_p)
if pvar.vt == wintypes.VT_BSTR and pvar.bstrVal != ffi.NULL:
C.free(pvar.bstrVal)
if pvar.vt == wintypes.VARTYPE.VT_BSTR and pvar.bstrVal != ffi.NULL:
C.free( ffi.cast('char*',pvar.bstrVal)-4 )

C.memset(pvar, 0, ffi.sizeof('PROPVARIANT'))

suffixes = '', '7z.so', 'p7zip/7z.so'
prefixes = ['/lib', '/usr/lib']
suffixes = '7z.so', 'p7zip/7z.so'
prefixes = ['/lib', '/usr/lib', '/usr/local/lib', '/usr/libexec', '/home/linuxbrew/.linuxbrew/lib', '/opt/local/lib', '/sw/lib']
for suffix in suffixes:
for prefix in prefixes:
dll_paths.append(os.path.join(prefix, suffix))
Expand Down Expand Up @@ -143,16 +143,22 @@ def get_format_info():
assert num_formats != ffi.NULL
log.debug('GetNumberOfFormats() == %d', num_formats[0])

return {
get_string_prop(i, FormatProps.kName, dll7z.GetHandlerProperty2):
Format(
retdict = {}
for i in range(num_formats[0]):
start_signature = get_bytes_prop(i, FormatProps.kSignature, dll7z.GetHandlerProperty2)
if start_signature is None:
multi_signature = get_bytes_prop(i, FormatProps.kMultiSignature, dll7z.GetHandlerProperty2)
if multi_signature is not None:
size = multi_signature[0]
start_signature = multi_signature[1:size+1]

retdict[get_string_prop(i, FormatProps.kName, dll7z.GetHandlerProperty2)] = Format(
classid=get_classid(i, FormatProps.kClassID, dll7z.GetHandlerProperty2),
extensions=tuple(get_string_prop(i, FormatProps.kExtension, dll7z.GetHandlerProperty2).split()),
index=i,
start_signature=get_bytes_prop(i, FormatProps.kStartSignature, dll7z.GetHandlerProperty2),
start_signature=start_signature,
)
for i in range(num_formats[0])
}
return retdict

Method = namedtuple(
'Method',
Expand Down Expand Up @@ -181,7 +187,7 @@ def get_method_info():
getting_meths = False
log.debug('initializing')
formats = get_format_info()
max_sig_size = max(len(f.start_signature) for f in formats.values())
max_sig_size = max(len(f.start_signature or '') for f in formats.values())
getting_meths = True
methods = get_method_info()

Expand Down
10 changes: 3 additions & 7 deletions lib7zip/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __del__(self):

def close(self):
log.debug('Archive.close()')
if self.archive or self.archive.vtable or self.archive.vtable.Close == ffi.NULL:
if self.archive == ffi.NULL or self.archive.vtable == ffi.NULL or self.archive.vtable.Close == ffi.NULL:
log.warn('close failed, NULLs')
return
RNOK(self.archive.vtable.Close(self.archive))
Expand Down Expand Up @@ -190,14 +190,10 @@ def extract(self, file, password=None):

self.callback = callback = ArchiveExtractToStreamCallback(file, self.index, password)
self.cb_inst = callback_inst = callback.instances[py7ziptypes.IID_IArchiveExtractCallback]
#indices = ffi.new('const uint32_t indices[]', [self.index])

#indices_p = C.calloc(1, ffi.sizeof('uint32_t'))
#indices = ffi.cast('uint32_t*', indices_p)
#indices[0] = self.index
indices = ffi.new('uint32_t indices[1]', [self.index])

log.debug('starting extract of %s!', self.path)
RNOK(self.archive.archive.vtable.Extract(self.archive.archive, ffi.NULL, 0xFFFFFFFF, 0, callback_inst))
RNOK(self.archive.archive.vtable.Extract(self.archive.archive, indices, 1, 0, callback_inst))
log.debug('finished extract')
#C.free(indices_p)

Expand Down
8 changes: 8 additions & 0 deletions lib7zip/comtypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
import sys

IID_IUnknown = uuid.UUID('{00000000-0000-0000-C000-000000000046}')

Expand All @@ -8,6 +9,13 @@
uint32_t (*Release)(void*);
"""

if 'win' not in sys.platform:
# https://forum.lazarus.freepascal.org/index.php/topic,42701.msg298820.html#msg298820
CDEF_IUnknown += """
void* Reserved1;
void* Reserved2;
"""

CDEFS = """
typedef struct {
""" + CDEF_IUnknown + """
Expand Down
5 changes: 2 additions & 3 deletions lib7zip/py7ziptypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ class FormatProps(IntEnum):
kAddExtension = 3
kUpdate = 4
kKeepName = 5
kStartSignature = 6
kFinishSignature = 7
kAssociate = 8
kSignature = 6
kMultiSignature = 7

class MethodProps(IntEnum):
kID = 0
Expand Down
5 changes: 3 additions & 2 deletions lib7zip/simplecom.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def __init__(self):
try:
method = self.methods[name]
except KeyError:
ctype = ffi.typeof(getattr(vtable, name))
self.methods[name] = method = ffi.callback(ctype, getattr(self, name))
if name!='Reserved1' and name!='Reserved2':
ctype = ffi.typeof(getattr(vtable, name))
self.methods[name] = method = ffi.callback(ctype, getattr(self, name))

setattr(vtable, name, method)
self.vtables.append(vtable)
Expand Down