diff --git a/gge_tools.py b/gge_tools.py index bc42e68..ec3c4cb 100644 --- a/gge_tools.py +++ b/gge_tools.py @@ -16,13 +16,22 @@ from pathlib import Path def _decode_zip_name(info: zipfile.ZipInfo) -> str: """Python 3 zipfile авто-декодирует cp437 если флаг UTF-8 (0x800) не задан. - Для имён от Windows-архиваторов нужно re-encode→re-decode как cp866.""" + Реальные байты могут быть в UTF-8 (macOS `zip`) или cp866 (Windows-архиватор). + Пробуем оба, берём результат без replacement chars.""" if info.flag_bits & 0x800: return info.filename try: - return info.filename.encode('cp437').decode('cp866') - except UnicodeError: + raw = info.filename.encode('cp437') + except UnicodeEncodeError: return info.filename + for codec in ('utf-8', 'cp866'): + try: + decoded = raw.decode(codec) + if '�' not in decoded: + return decoded + except UnicodeDecodeError: + continue + return info.filename def extract_archive(zip_path: Path, target_dir: Path) -> dict: