Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More reality-aligned base URL workflow #679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion legendary/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def list_files(self, args):
# check if we even need to log in
if args.override_manifest:
logger.info(f'Loading manifest from "{args.override_manifest}"')
manifest_data, _ = self.core.get_uri_manifest(args.override_manifest)
manifest_data = self.core.get_uri_manifest(args.override_manifest)
elif self.core.is_installed(args.app_name) and not args.force_download:
logger.info(f'Loading installed manifest for "{args.app_name}"')
manifest_data, _ = self.core.get_installed_manifest(args.app_name)
Expand Down
24 changes: 9 additions & 15 deletions legendary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,11 @@ def get_uri_manifest(self, uri):
r = self.egs.unauth_session.get(uri)
r.raise_for_status()
new_manifest_data = r.content
base_urls = [r.url.rpartition('/')[0]]
else:
base_urls = []
with open(uri, 'rb') as f:
new_manifest_data = f.read()

return new_manifest_data, base_urls
return new_manifest_data

def get_delta_manifest(self, base_url, old_build_id, new_build_id):
"""Get optimized delta manifest (doesn't seem to exist for most games)"""
Expand Down Expand Up @@ -1338,7 +1336,7 @@ def prepare_download(self, game: Game, base_game: Game = None, base_path: str =
# load old manifest if we have one
if override_old_manifest:
self.log.info(f'Overriding old manifest with "{override_old_manifest}"')
old_bytes, _ = self.get_uri_manifest(override_old_manifest)
old_bytes = self.get_uri_manifest(override_old_manifest)
old_manifest = self.load_manifest(old_bytes)
elif not disable_patching and not force and self.is_installed(game.app_name):
old_bytes, _base_urls = self.get_installed_manifest(game.app_name)
Expand All @@ -1350,24 +1348,20 @@ def prepare_download(self, game: Game, base_game: Game = None, base_path: str =
else:
old_manifest = self.load_manifest(old_bytes)

base_urls = game.base_urls

# The EGS client uses plaintext HTTP by default for the purposes of enabling simple DNS based
# CDN redirection to a (local) cache. In Legendary this will be a config option.
disable_https = disable_https or self.lgd.config.getboolean('Legendary', 'disable_https', fallback=False)

if override_manifest:
self.log.info(f'Overriding manifest with "{override_manifest}"')
new_manifest_data, _base_urls = self.get_uri_manifest(override_manifest)
# if override manifest has a base URL use that instead
if _base_urls:
base_urls = _base_urls
new_manifest_data = self.get_uri_manifest(override_manifest)
_, base_urls, _ = self.get_cdn_urls(game, platform)
else:
new_manifest_data, base_urls = self.get_cdn_manifest(game, platform, disable_https=disable_https)
# overwrite base urls in metadata with current ones to avoid using old/dead CDNs
game.base_urls = base_urls
# save base urls to game metadata
self.lgd.set_game_meta(game.app_name, game)
# overwrite base urls in metadata with current ones to avoid using old/dead CDNs
game.base_urls = base_urls
# save base urls to game metadata
self.lgd.set_game_meta(game.app_name, game)

self.log.info('Parsing game manifest...')
new_manifest = self.load_manifest(new_manifest_data)
Expand All @@ -1384,7 +1378,7 @@ def prepare_download(self, game: Game, base_game: Game = None, base_path: str =
if old_manifest and new_manifest and not disable_delta:
if override_delta_manifest:
self.log.info(f'Overriding delta manifest with "{override_delta_manifest}"')
delta_manifest_data, _ = self.get_uri_manifest(override_delta_manifest)
delta_manifest_data = self.get_uri_manifest(override_delta_manifest)
else:
delta_manifest_data = self.get_delta_manifest(base_urls[0],
old_manifest.meta.build_id,
Expand Down
Loading