From e3dc53ee7dc5a62ca0258bd9d52b4f433124da73 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Wed, 9 May 2018 16:02:42 -0800 Subject: [PATCH] Try utf-16 if utf-8 fails --- exts/imports/process_files.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/exts/imports/process_files.py b/exts/imports/process_files.py index dfcd3fb..3923b35 100644 --- a/exts/imports/process_files.py +++ b/exts/imports/process_files.py @@ -84,33 +84,35 @@ def process_files(z) -> (ConfigParser, ConfigParser, list): dino_data = dict() game_config = ConfigParser() mods = list() - z.extractall(path='submissions_temp/tmp/') - for filename in os.listdir('submissions_temp/tmp/'): + path = 'submissions_temp/tmp/' + z.extractall(path=path) + for filename in os.listdir(path): if filename.endswith('.ini'): # ignore any files that don't end with .ini if filename.lower() == 'game.ini': # Clean the Game.ini file, removing unnecessary lines try: - with open(filename, encoding='utf-8') as file: + with open(f'{path}{filename}', encoding='utf-8') as file: game_config = process_file(file, 'game.ini', 'utf-8') + mods = check_for_mods(file) except UnicodeDecodeError as e: print(e) try: - with open(filename, encoding='utf-16-le') as file: + with open(f'{path}{filename}', encoding='utf-16-le') as file: game_config = process_file(file, 'game.ini', 'utf-16-le') + mods = check_for_mods(file) except UnicodeDecodeError as e: print(e) return 0, 0, 0 - mods = check_for_mods(z.open(filename)) elif 'DinoExport' in filename: # Get the contents of all DinoExport_*.ini files loaded into a dict try: - with open(filename, encoding='utf-8') as file: + with open(f'{path}{filename}', encoding='utf-8') as file: dino_data[filename] = process_file(file, 'dino.ini', 'utf-8') except UnicodeDecodeError as e: print(e) try: - with open(filename, encoding='utf-16-le') as file: + with open(f'{path}{filename}', encoding='utf-16-le') as file: dino_data[filename] = process_file(file, 'dino.ini', 'utf-16-le') except UnicodeDecodeError as e: print(e)