From 49769b708330b9d284186b9f41ae5b5ad3b96eb9 Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Sat, 10 Jun 2023 18:45:56 +0200 Subject: [PATCH] Fix import hanging if custom Bottles location --- src/importers/bottles_importer.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/importers/bottles_importer.py b/src/importers/bottles_importer.py index 8da7dcf..a8e9699 100644 --- a/src/importers/bottles_importer.py +++ b/src/importers/bottles_importer.py @@ -83,15 +83,25 @@ def bottles_importer(): values["added"] = current_time values["last_played"] = 0 + # This will not work if both Cartridges and Bottles are installed via Flatpak + # as Cartridges can't access directories picked via Bottles' file picker portal + try: + bottles_location = Path( + yaml.safe_load((bottles_dir / "data.yml").read_text("utf-8"))[ + "custom_bottles_path" + ] + ) + except (FileNotFoundError, KeyError): + bottles_location = bottles_dir / "bottles" + + grid_path = ( + bottles_location + / game["bottle"]["path"] + / "grids" + / game["thumbnail"].split(":")[1] + ) + importer.save_game( values, - ( - bottles_dir - / "bottles" - / game["bottle"]["path"] - / "grids" - / game["thumbnail"].split(":")[1] - ) - if game["thumbnail"] - else None, + grid_path if game["thumbnail"] and grid_path.is_file() else None, )