[core/lfs] Clean up local manifest saving/loading

This commit is contained in:
derrod 2020-04-25 23:02:46 +02:00
parent 8f23770e43
commit 035e23b964
2 changed files with 14 additions and 19 deletions

View file

@ -313,7 +313,7 @@ class LegendaryCore:
old_manifest = self.load_manfiest(old_manifest_data) old_manifest = self.load_manfiest(old_manifest_data)
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):
igame = self.get_installed_game(game.app_name) igame = self.get_installed_game(game.app_name)
if old_bytes := self.lgd.get_manifest(game.app_name, igame.version): if old_bytes := self.lgd.load_manifest(game.app_name, igame.version):
old_manifest = self.load_manfiest(old_bytes) 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
@ -357,9 +357,9 @@ class LegendaryCore:
self.log.debug(f'Base urls: {base_urls}') self.log.debug(f'Base urls: {base_urls}')
new_manifest = self.load_manfiest(new_manifest_data) new_manifest = self.load_manfiest(new_manifest_data)
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 in "old" folder as well for testing/downgrading/etc. # save manifest with version name as well for testing/downgrading/etc.
self.lgd.save_manifest(game.app_name, new_manifest_data, self.lgd.save_manifest(game.app_name, new_manifest_data,
filename=f'{game.app_name}_{new_manifest.meta.build_version}', old=True) version=new_manifest.meta.build_version)
if not game_folder: if not game_folder:
if game.is_dlc: if game.is_dlc:
@ -374,6 +374,7 @@ class LegendaryCore:
install_path = os.path.join(base_path, game_folder) install_path = os.path.join(base_path, game_folder)
# todo move this somewhere else so the directory only gets created once the download is started
if not os.path.exists(install_path): if not os.path.exists(install_path):
os.makedirs(install_path) os.makedirs(install_path)

View file

@ -116,29 +116,23 @@ class LGDLFS:
open(os.path.join(self.path, 'assets.json'), 'w'), open(os.path.join(self.path, 'assets.json'), 'w'),
indent=2, sort_keys=True) indent=2, sort_keys=True)
def get_manifest(self, app_name, version=''): def _get_manifest_filename(self, app_name, version=''):
if not version: if not version:
manifest_file = os.path.join(self.path, 'manifests', f'{app_name}.manifest') return os.path.join(self.path, 'manifests', f'{app_name}.manifest')
else: else:
# if a version is specified load it from the versioned directory # if a version is specified load it from the versioned directory
fname = clean_filename(f'{app_name}_{version}') fname = clean_filename(f'{app_name}_{version}')
manifest_file = os.path.join(self.path, 'manifests', 'old', return os.path.join(self.path, 'manifests', 'old', f'{fname}.manifest')
f'{fname}.manifest')
if os.path.exists(manifest_file): def load_manifest(self, app_name, version=''):
return open(manifest_file, 'rb').read() try:
else: return open(self._get_manifest_filename(app_name, version), 'rb').read()
except FileNotFoundError: # all other errors should propagate
return None return None
def save_manifest(self, app_name, manifest_data, filename=None, old=False): def save_manifest(self, app_name, manifest_data, version=''):
if not filename: with open(self._get_manifest_filename(app_name, version), 'wb') as f:
manifest_file = os.path.join(self.path, 'manifests', f'{app_name}.manifest') f.write(manifest_data)
elif filename and old:
manifest_file = os.path.join(self.path, 'manifests', f'old/{clean_filename(filename)}.manifest')
else:
manifest_file = os.path.join(self.path, 'manifests', f'{clean_filename(filename)}.manifest')
open(manifest_file, 'wb').write(manifest_data)
def get_game_meta(self, app_name): def get_game_meta(self, app_name):
_meta = self._game_metadata.get(app_name, None) _meta = self._game_metadata.get(app_name, None)