From cbaf509375cba4db2f003eb6f130b8e9d9a70070 Mon Sep 17 00:00:00 2001 From: Raffson Date: Sun, 17 Mar 2024 01:24:27 +0100 Subject: [PATCH] Avoid crash with incompatible save on startup --- qt_ui/windows/QLiberationWindow.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/qt_ui/windows/QLiberationWindow.py b/qt_ui/windows/QLiberationWindow.py index bfe61851..59e4b109 100644 --- a/qt_ui/windows/QLiberationWindow.py +++ b/qt_ui/windows/QLiberationWindow.py @@ -108,7 +108,7 @@ class QLiberationWindow(QMainWindow): if last_save_file: logging.info("Loading last saved game : " + str(last_save_file)) game = persistency.load_game(last_save_file) - self.migrate_game(game, last_save_file) + game = self.migrate_game(game, last_save_file) self.onGameGenerated(game) self.updateWindowTitle(last_save_file if game else None) else: @@ -316,7 +316,7 @@ class QLiberationWindow(QMainWindow): ) if file is not None and file[0] != "": game = persistency.load_game(file[0]) - self.migrate_game(game, file[0]) + game = self.migrate_game(game, file[0]) GameUpdateSignal.get_instance().game_loaded.emit(game) self.updateWindowTitle(file[0]) @@ -324,15 +324,23 @@ class QLiberationWindow(QMainWindow): def migrate_game(self, game, path): if game: is_liberation = ".liberation" in path - Migrator(game, is_liberation) + try: + Migrator(game, is_liberation) + return game + except Exception: + self.incompatible_save_popup(path) else: - relative_path = Path(path) - QMessageBox.critical( - self, - "Incompatible save", - "Incompatible save file detected, please report the issue on GitHub or Discord.\n" - f"Make sure to include the campaign that fails to load, i.e.:\n\n{relative_path}", - ) + self.incompatible_save_popup(path) + return None + + def incompatible_save_popup(self, path): + relative_path = Path(path) + QMessageBox.critical( + self, + "Incompatible save", + "Incompatible save file detected, please report the issue on GitHub or Discord.\n" + f"Make sure to include the campaign that fails to load, i.e.:\n\n{relative_path}", + ) def saveGame(self): logging.info("Saving game")