Try utf-16 if utf-8 fails

This commit is contained in:
Dustin Pianalto 2018-05-09 16:34:24 -08:00
parent a90f97129e
commit 4610eca508

View File

@ -95,7 +95,7 @@ def process_files(z) -> (ConfigParser, ConfigParser, list):
# Clean the Game.ini file, removing unnecessary lines # Clean the Game.ini file, removing unnecessary lines
try: try:
with open(f'{path}{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') game_config = process_file(file, 'game.ini')
mods = check_for_mods(file) mods = check_for_mods(file)
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(e) print(e)
@ -104,7 +104,7 @@ def process_files(z) -> (ConfigParser, ConfigParser, list):
contents = file.read() contents = file.read()
file.write(contents.decode('utf-16-le').encode('utf-8')) file.write(contents.decode('utf-16-le').encode('utf-8'))
with open(f'{path}{filename}', encoding='utf-8') as file: with open(f'{path}{filename}', encoding='utf-8') as file:
game_config = process_file(file, 'game.ini', 'utf-16-le') game_config = process_file(file, 'game.ini')
mods = check_for_mods(file) mods = check_for_mods(file)
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(e) print(e)
@ -114,7 +114,7 @@ def process_files(z) -> (ConfigParser, ConfigParser, list):
print(filename) print(filename)
try: try:
with open(f'{path}{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') dino_data[filename] = process_file(file, 'dino.ini')
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(e) print(e)
try: try:
@ -122,7 +122,7 @@ def process_files(z) -> (ConfigParser, ConfigParser, list):
contents = file.read() contents = file.read()
file.write(contents.decode('utf-16-le').encode('utf-8')) file.write(contents.decode('utf-16-le').encode('utf-8'))
with open(f'{path}{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-16-le') dino_data[filename] = process_file(file, 'dino.ini')
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
print(e) print(e)
return 0, 0, 0 return 0, 0, 0