diff --git a/lib7zip/__init__.py b/lib7zip/__init__.py index 8ff078d..9306011 100644 --- a/lib7zip/__init__.py +++ b/lib7zip/__init__.py @@ -62,8 +62,12 @@ aKey = OpenKey(HKEY_LOCAL_MACHINE, r"SOFTWARE\7-Zip", 0, KEY_READ) s7z_path = QueryValueEx(aKey, "Path")[0] except FileNotFoundError: - s7z_path = os.path.normpath('B:/tools/7z1604') + s7z_path = os.path.normpath('C:/Program Files/7-Zip') dll_paths.append(os.path.join(s7z_path, '7z.dll')) + + # add common zip install paths + #dll_paths.append(os.path.join("%PROGRAMFILES%\7-Zip", '7z.dll')) + #dll_paths.append(os.path.join("C:\Portableapps\7-Zip\App", '7z.dll')) ole32 = ffi.dlopen('ole32') free_propvariant = lambda x: ole32.PropVariantClear(x) @@ -83,7 +87,7 @@ def free_propvariant(void_p): suffixes = '', '7z.so', 'p7zip/7z.so' - prefixes = ['/lib', '/usr/lib'] + prefixes = ['/lib', '/usr/lib', '/data/data/com.termux/files/usr/lib'] for suffix in suffixes: for prefix in prefixes: dll_paths.append(os.path.join(prefix, suffix)) @@ -224,6 +228,8 @@ def get_method_info(): extensions = get_extensions_to_formats() # print(formats.values()) max_sig_size = max(len(f.start_signature or b'') for f in formats.values()) +if max_sig_size < 4096: + max_sig_size = 4096 getting_meths = True methods = get_method_info() diff --git a/lib7zip/archive.py b/lib7zip/archive.py index 8eb35c9..892fb0e 100644 --- a/lib7zip/archive.py +++ b/lib7zip/archive.py @@ -126,7 +126,7 @@ def __init__(self, filename: os.PathLike, stream=None, in_stream=None, forcetype @staticmethod def formats_by_path(path: PurePath) -> Iterator[str]: for suffix in reversed(path.suffixes): - names = extensions.get(suffix.lstrip('.'), None) + names = extensions.get(suffix.lower().lstrip('.'), None) if names is not None: yield from names @@ -159,6 +159,10 @@ def filter_unique(name): def filter_applicable_format(name, format): if format.start_signature and startswith(format.start_signature): yield from filter_unique(name) + elif format.start_signature and sigcmp.find(format.start_signature) > 0: # skip possible headers + yield from filter_unique(name) + #elif str(filename).lower().endswith(format.extensions): # match extensions only + # yield from filter_unique(name) for name in format_names: yield from filter_applicable_format(name, formats[name]) @@ -167,7 +171,7 @@ def filter_applicable_format(name, format): yield from filter_unique(name) for name, format in formats.items(): - if name in format_names: + if name in format_names or not format.start_signature: continue yield from filter_applicable_format(name, format) @@ -248,7 +252,7 @@ def arc_props_len(self) -> int: RNOK(self.archive.vtable.GetNumberOfArchiveProperties(self.archive, num)) return int(num[0]) - def get_arc_prop_info(self, index: int) -> tuple[Optional[str], ArchiveProps, VARTYPE]: + def get_arc_prop_info(self, index: int): # -> tuple[Optional[str], ArchiveProps, VARTYPE] propid = ffi.new('PROPID*') vt = ffi.new('VARTYPE*') name = ffi.new('wchar_t**') @@ -263,11 +267,11 @@ def get_arc_prop_info(self, index: int) -> tuple[Optional[str], ArchiveProps, VA free_string(name[0]) return name_str, ArchiveProps(propid[0]), VARTYPE(vt[0]) - def iter_arc_props_info(self) -> Iterator[tuple[Optional[str], ArchiveProps, VARTYPE]]: + def iter_arc_props_info(self): # -> Iterator[tuple[Optional[str], ArchiveProps, VARTYPE]]: for i in range(self.arc_props_len): yield self.get_arc_prop_info(i) - def iter_arc_props(self) -> Iterator[tuple[Optional[str], ArchiveProps, VARTYPE, Any]]: + def iter_arc_props(self): #-> Iterator[tuple[Optional[str], ArchiveProps, VARTYPE, Any]]: for name, prop, vt in self.iter_arc_props_info(): val = get_prop_val(partial(self.archive.vtable.GetArchiveProperty, self.archive, prop)) yield name, prop, vt, val @@ -356,12 +360,12 @@ def __getattr__(self, attr): propid = getattr(py7ziptypes.ArchiveProps, attr) return get_prop_val(partial(self.archive.itm_prop_fn, self.index, propid)) - def iter_props(self) -> Iterator[tuple[Optional[str], ArchiveProps, VARTYPE, Any]]: + def iter_props(self): # -> Iterator[tuple[Optional[str], ArchiveProps, VARTYPE, Any]]: for name, prop, vt in self.archive.iter_props_info(): val = get_prop_val(partial(self.archive.itm_prop_fn, self.index, prop)) yield name, prop, vt, val - def get_seq_in_stream(self) -> Optional[Any]: + def get_seq_in_stream(self): # -> Optional[Any]: get_void_ptr = ffi.new('void**') archive = self.archive.archive res = archive.vtable.QueryInterface(