mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[core/lfs] Clean up local manifest saving/loading
This commit is contained in:
parent
8f23770e43
commit
035e23b964
|
@ -313,7 +313,7 @@ class LegendaryCore:
|
|||
old_manifest = self.load_manfiest(old_manifest_data)
|
||||
elif not disable_patching and not force and self.is_installed(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)
|
||||
|
||||
base_urls = list(game.base_urls) # copy list for manipulation
|
||||
|
@ -357,9 +357,9 @@ class LegendaryCore:
|
|||
self.log.debug(f'Base urls: {base_urls}')
|
||||
new_manifest = self.load_manfiest(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,
|
||||
filename=f'{game.app_name}_{new_manifest.meta.build_version}', old=True)
|
||||
version=new_manifest.meta.build_version)
|
||||
|
||||
if not game_folder:
|
||||
if game.is_dlc:
|
||||
|
@ -374,6 +374,7 @@ class LegendaryCore:
|
|||
|
||||
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):
|
||||
os.makedirs(install_path)
|
||||
|
||||
|
|
|
@ -116,29 +116,23 @@ class LGDLFS:
|
|||
open(os.path.join(self.path, 'assets.json'), 'w'),
|
||||
indent=2, sort_keys=True)
|
||||
|
||||
def get_manifest(self, app_name, version=''):
|
||||
def _get_manifest_filename(self, app_name, 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:
|
||||
# if a version is specified load it from the versioned directory
|
||||
fname = clean_filename(f'{app_name}_{version}')
|
||||
manifest_file = os.path.join(self.path, 'manifests', 'old',
|
||||
f'{fname}.manifest')
|
||||
return os.path.join(self.path, 'manifests', 'old', f'{fname}.manifest')
|
||||
|
||||
if os.path.exists(manifest_file):
|
||||
return open(manifest_file, 'rb').read()
|
||||
else:
|
||||
def load_manifest(self, app_name, version=''):
|
||||
try:
|
||||
return open(self._get_manifest_filename(app_name, version), 'rb').read()
|
||||
except FileNotFoundError: # all other errors should propagate
|
||||
return None
|
||||
|
||||
def save_manifest(self, app_name, manifest_data, filename=None, old=False):
|
||||
if not filename:
|
||||
manifest_file = os.path.join(self.path, 'manifests', f'{app_name}.manifest')
|
||||
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 save_manifest(self, app_name, manifest_data, version=''):
|
||||
with open(self._get_manifest_filename(app_name, version), 'wb') as f:
|
||||
f.write(manifest_data)
|
||||
|
||||
def get_game_meta(self, app_name):
|
||||
_meta = self._game_metadata.get(app_name, None)
|
||||
|
|
Loading…
Reference in a new issue