mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[utils] Add helpers for CrossOver on macOS
This commit is contained in:
parent
33b89f5e9a
commit
b5a2fba896
50
legendary/utils/crossover.py
Normal file
50
legendary/utils/crossover.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import logging
|
||||
import plistlib
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
logger = logging.getLogger('CXHelpers')
|
||||
|
||||
|
||||
def mac_get_crossover_version(app_path):
|
||||
try:
|
||||
plist = plistlib.load(open(os.path.join(app_path, 'Contents', 'Info.plist'), 'rb'))
|
||||
return plist['CFBundleShortVersionString']
|
||||
except Exception as e:
|
||||
logger.debug(f'Failed to load plist for "{app_path}" with {e!r}')
|
||||
return None
|
||||
|
||||
|
||||
def mac_find_crossover_apps():
|
||||
paths = ['/Applications/CrossOver.app']
|
||||
try:
|
||||
out = subprocess.check_output(['mdfind', 'kMDItemCFBundleIdentifier="com.codeweavers.CrossOver"'])
|
||||
paths.extend(out.decode('utf-8', 'replace').strip().split('\n'))
|
||||
except Exception as e:
|
||||
logger.warning(f'Trying to find CrossOver installs via mdfind failed: {e!r}')
|
||||
|
||||
valid = [p for p in paths if os.path.exists(os.path.join(p, 'Contents', 'Info.plist'))]
|
||||
found_tuples = set()
|
||||
|
||||
for path in valid:
|
||||
version = mac_get_crossover_version(path)
|
||||
if not version:
|
||||
continue
|
||||
logger.debug(f'Found Crossover {version} at "{path}"')
|
||||
found_tuples.add((version, path))
|
||||
|
||||
return sorted(found_tuples, reverse=True)
|
||||
|
||||
|
||||
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')))
|
||||
|
||||
|
||||
def mac_is_valid_bottle(bottle_name):
|
||||
bottles_path = os.path.expanduser('~/Library/Application Support/CrossOver/Bottles')
|
||||
return os.path.exists(os.path.join(bottles_path, bottle_name, 'cxbottle.conf'))
|
Loading…
Reference in a new issue