mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[core/models] Make manifest merge part of Manifest class
This commit is contained in:
parent
0e23b8e4f0
commit
36e6e5f08a
|
@ -39,7 +39,6 @@ from legendary.lfs.eos import EOSOverlayApp, query_registry_entries
|
|||
from legendary.utils.game_workarounds import is_opt_enabled, update_workarounds, get_exe_override
|
||||
from legendary.utils.savegame_helper import SaveGameHelper
|
||||
from legendary.utils.selective_dl import games as sdl_games
|
||||
from legendary.utils.manifests import combine_manifests
|
||||
from legendary.lfs.wine_helpers import read_registry, get_shell_folders, case_insensitive_path_search
|
||||
|
||||
|
||||
|
@ -1325,7 +1324,7 @@ class LegendaryCore:
|
|||
self.log.info(f'Using optimized delta manifest to upgrade from build '
|
||||
f'"{old_manifest.meta.build_id}" to '
|
||||
f'"{new_manifest.meta.build_id}"...')
|
||||
combine_manifests(new_manifest, delta_manifest)
|
||||
new_manifest.apply_delta_manifest(delta_manifest)
|
||||
else:
|
||||
self.log.debug(f'No Delta manifest received from CDN.')
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
import struct
|
||||
|
@ -164,6 +166,43 @@ class Manifest:
|
|||
|
||||
return bio.tell() if fp else bio.getvalue()
|
||||
|
||||
def apply_delta_manifest(self, delta_manifest: Manifest):
|
||||
added = set()
|
||||
# overwrite file elements with the ones from the delta manifest
|
||||
for idx, file_elem in enumerate(self.file_manifest_list.elements):
|
||||
try:
|
||||
delta_file = delta_manifest.file_manifest_list.get_file_by_path(file_elem.filename)
|
||||
self.file_manifest_list.elements[idx] = delta_file
|
||||
added.add(delta_file.filename)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# add other files that may be missing
|
||||
for delta_file in delta_manifest.file_manifest_list.elements:
|
||||
if delta_file.filename not in added:
|
||||
self.file_manifest_list.elements.append(delta_file)
|
||||
# update count and clear map
|
||||
self.file_manifest_list.count = len(self.file_manifest_list.elements)
|
||||
self.file_manifest_list._path_map = None
|
||||
|
||||
# ensure guid map exists (0 will most likely yield no result, so ignore ValueError)
|
||||
try:
|
||||
self.chunk_data_list.get_chunk_by_guid(0)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# add new chunks from delta manifest to main manifest and again clear maps and update count
|
||||
existing_chunk_guids = self.chunk_data_list._guid_int_map.keys()
|
||||
|
||||
for chunk in delta_manifest.chunk_data_list.elements:
|
||||
if chunk.guid_num not in existing_chunk_guids:
|
||||
self.chunk_data_list.elements.append(chunk)
|
||||
|
||||
self.chunk_data_list.count = len(self.chunk_data_list.elements)
|
||||
self.chunk_data_list._guid_map = None
|
||||
self.chunk_data_list._guid_int_map = None
|
||||
self.chunk_data_list._path_map = None
|
||||
|
||||
|
||||
class ManifestMeta:
|
||||
serialisation_version = 0
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
from legendary.models.manifest import Manifest
|
||||
|
||||
|
||||
def combine_manifests(base_manifest: Manifest, delta_manifest: Manifest):
|
||||
added = set()
|
||||
# overwrite file elements with the ones from the delta manifest
|
||||
for idx, file_elem in enumerate(base_manifest.file_manifest_list.elements):
|
||||
try:
|
||||
delta_file = delta_manifest.file_manifest_list.get_file_by_path(file_elem.filename)
|
||||
base_manifest.file_manifest_list.elements[idx] = delta_file
|
||||
added.add(delta_file.filename)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# add other files that may be missing
|
||||
for delta_file in delta_manifest.file_manifest_list.elements:
|
||||
if delta_file.filename not in added:
|
||||
base_manifest.file_manifest_list.elements.append(delta_file)
|
||||
# update count and clear map
|
||||
base_manifest.file_manifest_list.count = len(base_manifest.file_manifest_list.elements)
|
||||
base_manifest.file_manifest_list._path_map = None
|
||||
|
||||
# ensure guid map exists
|
||||
try:
|
||||
base_manifest.chunk_data_list.get_chunk_by_guid(0)
|
||||
except:
|
||||
pass
|
||||
|
||||
# add new chunks from delta manifest to main manifest and again clear maps and update count
|
||||
existing_chunk_guids = base_manifest.chunk_data_list._guid_int_map.keys()
|
||||
|
||||
for chunk in delta_manifest.chunk_data_list.elements:
|
||||
if chunk.guid_num not in existing_chunk_guids:
|
||||
base_manifest.chunk_data_list.elements.append(chunk)
|
||||
|
||||
base_manifest.chunk_data_list.count = len(base_manifest.chunk_data_list.elements)
|
||||
base_manifest.chunk_data_list._guid_map = None
|
||||
base_manifest.chunk_data_list._guid_int_map = None
|
||||
base_manifest.chunk_data_list._path_map = None
|
Loading…
Reference in a new issue