Skip to content

Commit

Permalink
Use UTF-8 in case of encoding error
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdoehne committed Jun 5, 2021
1 parent ea9f15d commit dd6ed4f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions stellarisdashboard/parsing/save_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,13 @@ def parse_save(self, filename):
self.save_filename = filename
logger.info(f"Parsing Save File {self.save_filename}...")
with zipfile.ZipFile(self.save_filename) as save_zip:
# encoding guess based on EU4 wiki https://eu4.paradoxwikis.com/Save-game_editing#File_locations
gamestate = save_zip.read("gamestate").decode("cp1252")
gamestate = save_zip.read("gamestate")
try:
# default encoding guess based on EU4 wiki https://eu4.paradoxwikis.com/Save-game_editing#File_locations
gamestate = gamestate.decode("cp1252")
except UnicodeError:
# attempt UTF-8, ignoring any further errors
gamestate = gamestate.decode("utf-8", errors="ignore")
self.parse_from_string(gamestate)
return self.gamestate_dict

Expand Down

0 comments on commit dd6ed4f

Please sign in to comment.