mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[cli/core] Fix manifest saving/loading
The refactoring didn't take into account that the raw manifest data still needs to be accessible. Since I did not want to modify the manifest model to hold the raw data (waste of RAM), just make the methods return the raw data again (at least for now)
This commit is contained in:
parent
8b63c482c1
commit
7dacd7ba35
|
@ -129,18 +129,19 @@ class LegendaryCLI:
|
||||||
# check if we even need to log in
|
# check if we even need to log in
|
||||||
if args.override_manifest:
|
if args.override_manifest:
|
||||||
logger.info(f'Loading manifest from "{args.override_manifest}"')
|
logger.info(f'Loading manifest from "{args.override_manifest}"')
|
||||||
manifest, _ = self.core.get_uri_manfiest(args.override_manifest)
|
manifest_data, _ = self.core.get_uri_manfiest(args.override_manifest)
|
||||||
elif self.core.is_installed(args.app_name) and not args.force_download:
|
elif self.core.is_installed(args.app_name) and not args.force_download:
|
||||||
logger.info(f'Loading installed manifest for "{args.app_name}"')
|
logger.info(f'Loading installed manifest for "{args.app_name}"')
|
||||||
manifest, _ = self.core.get_installed_manifest(args.app_name)
|
manifest_data, _ = self.core.get_installed_manifest(args.app_name)
|
||||||
else:
|
else:
|
||||||
logger.info(f'Logging in and downloading manifest for {args.app_name}')
|
logger.info(f'Logging in and downloading manifest for {args.app_name}')
|
||||||
if not self.core.login():
|
if not self.core.login():
|
||||||
logger.error('Login failed! Cannot continue with download process.')
|
logger.error('Login failed! Cannot continue with download process.')
|
||||||
exit(1)
|
exit(1)
|
||||||
game = self.core.get_game(args.app_name, update_meta=True)
|
game = self.core.get_game(args.app_name, update_meta=True)
|
||||||
manifest, _ = self.core.get_cdn_manifest(game, platform_override=args.platform_override)
|
manifest_data, _ = self.core.get_cdn_manifest(game, platform_override=args.platform_override)
|
||||||
|
|
||||||
|
manifest = self.core.load_manfiest(manifest_data)
|
||||||
files = sorted(manifest.file_manifest_list.elements,
|
files = sorted(manifest.file_manifest_list.elements,
|
||||||
key=lambda a: a.filename.lower())
|
key=lambda a: a.filename.lower())
|
||||||
|
|
||||||
|
|
|
@ -308,7 +308,7 @@ class LegendaryCore:
|
||||||
def get_installed_manifest(self, app_name):
|
def get_installed_manifest(self, app_name):
|
||||||
igame = self.get_installed_game(app_name)
|
igame = self.get_installed_game(app_name)
|
||||||
if old_bytes := self.lgd.load_manifest(app_name, igame.version):
|
if old_bytes := self.lgd.load_manifest(app_name, igame.version):
|
||||||
return self.load_manfiest(old_bytes), igame.base_urls
|
return old_bytes, igame.base_urls
|
||||||
|
|
||||||
def get_cdn_manifest(self, game, platform_override=''):
|
def get_cdn_manifest(self, game, platform_override=''):
|
||||||
base_urls = []
|
base_urls = []
|
||||||
|
@ -335,7 +335,7 @@ class LegendaryCore:
|
||||||
self.log.debug(f'Downloading manifest from {manifest["uri"]} ...')
|
self.log.debug(f'Downloading manifest from {manifest["uri"]} ...')
|
||||||
r = self.egs.unauth_session.get(manifest['uri'], params=params)
|
r = self.egs.unauth_session.get(manifest['uri'], params=params)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return self.load_manfiest(r.content), base_urls
|
return r.content, base_urls
|
||||||
|
|
||||||
def get_uri_manfiest(self, uri):
|
def get_uri_manfiest(self, uri):
|
||||||
if uri.startswith('http'):
|
if uri.startswith('http'):
|
||||||
|
@ -348,7 +348,7 @@ class LegendaryCore:
|
||||||
with open(uri, 'rb') as f:
|
with open(uri, 'rb') as f:
|
||||||
new_manifest_data = f.read()
|
new_manifest_data = f.read()
|
||||||
|
|
||||||
return self.load_manfiest(new_manifest_data), base_urls
|
return new_manifest_data, base_urls
|
||||||
|
|
||||||
def prepare_download(self, game: Game, base_game: Game = None, base_path: str = '',
|
def prepare_download(self, game: Game, base_game: Game = None, base_path: str = '',
|
||||||
status_q: Queue = None, max_shm: int = 0, max_workers: int = 0,
|
status_q: Queue = None, max_shm: int = 0, max_workers: int = 0,
|
||||||
|
@ -360,27 +360,29 @@ class LegendaryCore:
|
||||||
|
|
||||||
# load old manifest
|
# load old manifest
|
||||||
old_manifest = None
|
old_manifest = None
|
||||||
new_manifest_data = b''
|
|
||||||
|
|
||||||
# load old manifest if we have one
|
# load old manifest if we have one
|
||||||
if override_old_manifest:
|
if override_old_manifest:
|
||||||
self.log.info(f'Overriding old manifest with "{override_old_manifest}"')
|
self.log.info(f'Overriding old manifest with "{override_old_manifest}"')
|
||||||
old_manifest, _ = self.get_uri_manfiest(override_old_manifest)
|
old_bytes, _ = self.get_uri_manfiest(override_old_manifest)
|
||||||
|
old_manifest = self.load_manfiest(old_bytes)
|
||||||
elif not disable_patching and not force and self.is_installed(game.app_name):
|
elif not disable_patching and not force and self.is_installed(game.app_name):
|
||||||
old_manifest, _ = self.get_installed_manifest(game.app_name)
|
old_bytes, _ = self.get_installed_manifest(game.app_name)
|
||||||
|
old_manifest = self.load_manfiest(old_bytes)
|
||||||
|
|
||||||
base_urls = list(game.base_urls) # copy list for manipulation
|
base_urls = list(game.base_urls) # copy list for manipulation
|
||||||
|
|
||||||
if override_manifest:
|
if override_manifest:
|
||||||
self.log.info(f'Overriding manifest with "{override_manifest}"')
|
self.log.info(f'Overriding manifest with "{override_manifest}"')
|
||||||
new_manifest, _base_urls = self.get_uri_manfiest(override_manifest)
|
new_manifest_data, _base_urls = self.get_uri_manfiest(override_manifest)
|
||||||
# if override manifest has a base URL use that instead
|
# if override manifest has a base URL use that instead
|
||||||
if _base_urls:
|
if _base_urls:
|
||||||
base_urls = _base_urls
|
base_urls = _base_urls
|
||||||
else:
|
else:
|
||||||
new_manifest, _base_urls = self.get_cdn_manifest(game, platform_override)
|
new_manifest_data, _base_urls = self.get_cdn_manifest(game, platform_override)
|
||||||
base_urls.extend(i for i in _base_urls if i not in base_urls)
|
base_urls.extend(i for i in _base_urls if i not in base_urls)
|
||||||
|
|
||||||
|
new_manifest = self.load_manfiest(new_manifest_data)
|
||||||
self.log.debug(f'Base urls: {base_urls}')
|
self.log.debug(f'Base urls: {base_urls}')
|
||||||
self.lgd.save_manifest(game.app_name, new_manifest_data)
|
self.lgd.save_manifest(game.app_name, new_manifest_data)
|
||||||
# save manifest with version name as well for testing/downgrading/etc.
|
# save manifest with version name as well for testing/downgrading/etc.
|
||||||
|
|
Loading…
Reference in a new issue