Skip to content

Commit

Permalink
[cli/core/models] Support launchable DLC/Addons
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Dec 13, 2023
1 parent 837c166 commit ae8626e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions legendary/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,10 @@ def launch_game(self, args, extra):
logger.error(f'Game {app_name} is not currently installed!')
exit(1)

if igame.is_dlc and not igame.executable:
logger.error(f'{app_name} is DLC without an executable; please launch the base game instead!')
exit(1)
if igame.is_dlc:
if not igame.executable and not self.core.get_game(app_name).is_launchable_addon:
logger.error(f'{app_name} is non-runnable DLC; please launch the base game instead!')
exit(1)

if not os.path.exists(igame.install_path):
logger.fatal(f'Install directory "{igame.install_path}" appears to be deleted, cannot launch {app_name}!')
Expand Down
5 changes: 5 additions & 0 deletions legendary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ def get_launch_parameters(self, app_name: str, offline: bool = False,
install = self.lgd.get_installed_game(app_name)
game = self.lgd.get_game_meta(app_name)

# If it's a runnable DLC use the base game for the install information
if not install.executable and game.is_launchable_addon:
main_app_name = game.metadata['mainGameItem']['releaseInfo'][0]['appId']
install = self.lgd.get_installed_game(main_app_name)

# Disable wine for non-Windows executables (e.g. native macOS)
if not install.platform.startswith('Win'):
disable_wine = True
Expand Down
6 changes: 6 additions & 0 deletions legendary/models/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def additional_command_line(self):
return None
return self.metadata.get('customAttributes', {}).get('AdditionalCommandLine', {}).get('value', None)

@property
def is_launchable_addon(self):
if not self.metadata:
return False
return any(m['path'] == 'addons/launchable' for m in self.metadata.get('categories', []))

@property
def catalog_item_id(self):
if not self.metadata:
Expand Down

0 comments on commit ae8626e

Please sign in to comment.