From 3bd82c5644539d6842df6ee9be3e55712601645d Mon Sep 17 00:00:00 2001 From: klensy Date: Thu, 19 Jul 2018 12:12:35 +0300 Subject: [PATCH] fixes decoding cp1251 text (found in comments) --- blk_unpack.py | 10 +++++++++- setup.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/blk_unpack.py b/blk_unpack.py index 438d6a9..1b8c441 100644 --- a/blk_unpack.py +++ b/blk_unpack.py @@ -427,7 +427,15 @@ def get_block_value(self, id_offset: int, block_type: int) -> Tuple[Any, int]: def print_item(self, item_type: str, item_data, sub_units_names): if item_type == 'str': - return sub_units_names[item_data].decode("utf-8") + s = sub_units_names[item_data] + try: + return s.decode("utf-8") + except UnicodeDecodeError as e: # russian win encoding + return s.decode("cp1251") + except Exception as e: + import sys + from traceback import print_exc + print_exc(file=sys.stdout) elif item_type == 'float': return float('%.4f' % item_data) elif item_type == 'bool': diff --git a/setup.py b/setup.py index bd13983..02fa4fb 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( name="wt-tools", - version="0.2.1.2-dev", + version="0.2.1.3-dev", author='klensy', description="War Thunder resource extraction tools", options={"build_exe": {"includes": includes, "excludes": excludes, "include_files": includefiles,