From ecb230511f8156481b1ad92bda4e3823bb55a114 Mon Sep 17 00:00:00 2001 From: derrod Date: Fri, 31 Dec 2021 17:46:15 +0100 Subject: [PATCH] [core/utils] Clean up crossover bottle code a bit --- legendary/core.py | 12 ++++-------- legendary/utils/crossover.py | 9 ++++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/legendary/core.py b/legendary/core.py index 15b64de..c696dcb 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -33,7 +33,7 @@ from legendary.models.game import * from legendary.models.json_manifest import JSONManifest from legendary.models.manifest import Manifest, ManifestMeta from legendary.models.chunk import Chunk -from legendary.utils.crossover import mac_find_crossover_apps, mac_get_crossover_version +from legendary.utils.crossover import mac_find_crossover_apps, mac_get_crossover_version, mac_get_bottle_path from legendary.utils.egl_crypt import decrypt_epic_data from legendary.utils.env import is_windows_mac_or_pyi from legendary.utils.eos import EOSOverlayApp, query_registry_entries @@ -1839,9 +1839,7 @@ class LegendaryCore: manifest = self.load_manifest(r.content) base_url = manifest_url.rpartition('/')[0] - bottles_dir = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles') - path = os.path.join(bottles_dir, bottle_name) - + path = mac_get_bottle_path(bottle_name) if os.path.exists(path): raise FileExistsError(f'Bottle {bottle_name} already exists') @@ -1862,8 +1860,7 @@ class LegendaryCore: return dlm, analysis_result, path def finish_bottle_setup(self, bottle_name): - bottles_dir = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles') - path = os.path.join(bottles_dir, bottle_name) + path = mac_get_bottle_path(bottle_name) self.log.info('Creating bottle symlinks...') symlinks = [ @@ -1888,8 +1885,7 @@ class LegendaryCore: @staticmethod def remove_bottle(bottle_name): - bottles_dir = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles') - path = os.path.join(bottles_dir, bottle_name) + path = mac_get_bottle_path(bottle_name) if os.path.exists(path): delete_folder(path, recursive=True) diff --git a/legendary/utils/crossover.py b/legendary/utils/crossover.py index 71675b4..9398da3 100644 --- a/legendary/utils/crossover.py +++ b/legendary/utils/crossover.py @@ -40,9 +40,7 @@ def mac_get_crossover_bottles(): bottles_path = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles') if not os.path.exists(bottles_path): return [] - return sorted(p for p in os.listdir(bottles_path) if - os.path.isdir(os.path.join(bottles_path, p)) and - os.path.exists(os.path.join(bottles_path, p, 'cxbottle.conf'))) + return sorted(p for p in os.listdir(bottles_path) if mac_is_valid_bottle(p)) def mac_is_valid_bottle(bottle_name): @@ -50,6 +48,11 @@ def mac_is_valid_bottle(bottle_name): return os.path.exists(os.path.join(bottles_path, bottle_name, 'cxbottle.conf')) +def mac_get_bottle_path(bottle_name): + bottles_path = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles') + return os.path.join(bottles_path, bottle_name) + + def mac_is_crossover_running(): try: out = subprocess.check_output(['launchctl', 'list'])