[cli/core/models] Access namespace/catalog item id directly

This commit is contained in:
derrod 2021-12-02 14:28:21 +01:00
parent 999ff36667
commit 356f0f84f5
4 changed files with 28 additions and 26 deletions

View file

@ -218,7 +218,7 @@ class LegendaryCLI:
writer.writerow(['App name', 'App title', 'Version', 'Is DLC'])
for game in games:
writer.writerow((game.app_name, game.app_title, game.app_version(args.platform), False))
for dlc in dlc_list[game.asset_infos[args.platform].catalog_item_id]:
for dlc in dlc_list[game.catalog_item_id]:
writer.writerow((dlc.app_name, dlc.app_title, dlc.app_version(args.platform), True))
return
@ -226,7 +226,7 @@ class LegendaryCLI:
_out = []
for game in games:
_j = vars(game)
_j['dlcs'] = [vars(dlc) for dlc in dlc_list[game.asset_infos[args.platform].catalog_item_id]]
_j['dlcs'] = [vars(dlc) for dlc in dlc_list[game.catalog_item_id]]
_out.append(_j)
return self._print_json(_out, args.pretty_json)
@ -243,10 +243,10 @@ class LegendaryCLI:
print(f' ! This game has to be installed through third-party store ({_store}, not supported)')
else:
print(f' ! No version information (unknown cause)')
for dlc in dlc_list[game.asset_infos[args.platform].catalog_item_id]:
for dlc in dlc_list[game.catalog_item_id]:
print(f' + {dlc.app_title} (App name: {dlc.app_name} | Version: {dlc.app_version(args.platform)})')
if not dlc.app_version(args.platform):
print(' ! This DLC is included in the game does not have to be downloaded separately')
print(f' ! This DLC is either included in the base game, or not available for {args.platform}')
print(f'\nTotal: {len(games)}')
@ -1382,17 +1382,11 @@ class LegendaryCLI:
logger.info('Game not installed and offline mode enabled, cannot load manifest.')
elif game:
entitlements = self.core.egs.get_user_entitlements()
# get latest metadata and manifest
if game.asset_infos[args.platform].catalog_item_id:
egl_meta = self.core.egs.get_game_info(game.asset_infos[args.platform].namespace,
game.asset_infos[args.platform].catalog_item_id)
game.metadata = egl_meta
egl_meta = self.core.egs.get_game_info(game.namespace, game.catalog_item_id)
game.metadata = egl_meta
# Get manifest if asset exists for current platform
if args.platform in game.asset_infos:
manifest_data, _ = self.core.get_cdn_manifest(game, args.platform)
else:
# Origin games do not have asset info, so fall back to info from metadata
egl_meta = self.core.egs.get_game_info(game.metadata['namespace'],
game.metadata['id'])
game.metadata = egl_meta
if game:
game_infos = info_items['game']

View file

@ -473,7 +473,7 @@ class LegendaryCore:
return []
_, dlcs = self.get_game_and_dlc_list(update_assets=False, platform=platform)
return dlcs[game.asset_infos[platform].catalog_item_id]
return dlcs[game.catalog_item_id]
def get_installed_platforms(self):
return {i.platform for i in self._get_installed_list(False)}
@ -602,11 +602,8 @@ class LegendaryCore:
if install.requires_ot and not offline:
self.log.info('Getting ownership token.')
ovt = self.egs.get_ownership_token(game.asset_infos[install.platform].namespace,
game.asset_infos[install.platform].catalog_item_id)
ovt_path = os.path.join(self.lgd.get_tmp_path(),
f'{game.asset_infos[install.platform].namespace}'
f'{game.asset_infos[install.platform].catalog_item_id}.ovt')
ovt = self.egs.get_ownership_token(game.namespace, game.catalog_item_id)
ovt_path = os.path.join(self.lgd.get_tmp_path(), f'{game.namespace}{game.catalog_item_id}.ovt')
with open(ovt_path, 'wb') as f:
f.write(ovt)
params.egl_parameters.append(f'-epicovt={ovt_path}')
@ -995,8 +992,7 @@ class LegendaryCore:
return old_bytes, igame.base_urls
def get_cdn_urls(self, game, platform='Windows'):
m_api_r = self.egs.get_game_manifest(game.asset_infos[platform].namespace,
game.asset_infos[platform].catalog_item_id,
m_api_r = self.egs.get_game_manifest(game.namespace, game.catalog_item_id,
game.app_name, platform)
# never seen this outside the launcher itself, but if it happens: PANIC!
@ -1531,8 +1527,8 @@ class LegendaryCore:
mf.write(manifest_data)
mancpn = dict(FormatVersion=0, AppName=app_name,
CatalogItemId=lgd_game.asset_infos['Windows'].catalog_item_id,
CatalogNamespace=lgd_game.asset_infos['Windows'].namespace)
CatalogItemId=lgd_game.catalog_item_id,
CatalogNamespace=lgd_game.namespace)
with open(os.path.join(egstore_folder, f'{egl_game.installation_guid}.mancpn', ), 'w') as mcpnf:
json.dump(mancpn, mcpnf, indent=4, sort_keys=True)

View file

@ -134,8 +134,8 @@ class EGLManifest:
tmp.app_version_string = igame.version
tmp.base_urls = igame.base_urls
tmp.build_label = 'Live'
tmp.catalog_item_id = game.asset_infos['Windows'].catalog_item_id
tmp.namespace = game.asset_infos['Windows'].namespace
tmp.catalog_item_id = game.catalog_item_id
tmp.namespace = game.namespace
tmp.display_name = igame.title
tmp.install_location = igame.install_path
tmp.install_size = igame.install_size

View file

@ -75,6 +75,18 @@ class Game:
def supports_cloud_saves(self):
return self.metadata and (self.metadata.get('customAttributes', {}).get('CloudSaveFolder') is not None)
@property
def catalog_item_id(self):
if not self.metadata:
return None
return self.metadata['id']
@property
def namespace(self):
if not self.metadata:
return None
return self.metadata['namespace']
@classmethod
def from_json(cls, json):
tmp = cls(