From 9d18ef03fae553e71c7d0216826ef187f6e703b0 Mon Sep 17 00:00:00 2001 From: derrod Date: Mon, 6 Dec 2021 18:10:30 +0100 Subject: [PATCH] [cli/core/models] Add property for partner link id/type --- legendary/cli.py | 7 +++---- legendary/core.py | 7 +++---- legendary/models/game.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index 9287062..95bc709 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -1759,9 +1759,9 @@ class LegendaryCLI: uplay_games = [] activated = 0 for game in games: - if game.metadata.get('customAttributes', {}).get('partnerLinkType', {}).get('value') != 'ubisoft': + if game.partner_link_type != 'ubisoft': continue - if game.metadata.get('customAttributes', {}).get('partnerLinkId', {}).get('value') in redeemed: + if game.partner_link_id in redeemed: activated += 1 continue uplay_games.append(game) @@ -1782,8 +1782,7 @@ class LegendaryCLI: try: for game in uplay_games: - game_id = game.metadata.get('customAttributes', {}).get('partnerLinkId', {}).get('value') - self.core.egs.store_claim_uplay_code(ubi_account_id, game_id) + self.core.egs.store_claim_uplay_code(ubi_account_id, game.partner_link_id) self.core.egs.store_redeem_uplay_codes(ubi_account_id) except Exception as e: logger.error(f'Failed to redeem Uplay codes: {e!r}') diff --git a/legendary/core.py b/legendary/core.py index b4b5d04..41f2b96 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -1357,12 +1357,11 @@ class LegendaryCore: uplay_required = True # check if the game requires linking to an external account first - partner_link = game.metadata.get('customAttributes', {}).get('partnerLinkType', {}).get('value', None) - if partner_link and partner_link != 'ubisoft': - results.warnings.add(f'This game requires linking to "{partner_link}", ' + if game.partner_link_type and game.partner_link_type != 'ubisoft': + results.warnings.add(f'This game requires linking to "{game.partner_link_type}", ' f'this is currently unsupported and the game may not work.') - if uplay_required or partner_link == 'ubisoft': + if uplay_required or game.partner_link_type == 'ubisoft': if os.name == 'nt': results.warnings.add('This game requires installation of Uplay/Ubisoft Connect, direct ' 'installation via Uplay is recommended. ' diff --git a/legendary/models/game.py b/legendary/models/game.py index 077682d..bf58536 100644 --- a/legendary/models/game.py +++ b/legendary/models/game.py @@ -71,6 +71,18 @@ class Game: return None return self.metadata.get('customAttributes', {}).get('ThirdPartyManagedApp', {}).get('value', None) + @property + def partner_link_type(self): + if not self.metadata: + return None + return self.metadata.get('customAttributes', {}).get('partnerLinkType', {}).get('value', None) + + @property + def partner_link_id(self): + if not self.metadata: + return None + return self.metadata.get('customAttributes', {}).get('partnerLinkId', {}).get('value', None) + @property def supports_cloud_saves(self): return self.metadata and (self.metadata.get('customAttributes', {}).get('CloudSaveFolder') is not None)