From 5f2da28f518f9daf3cc266906e53cffed66e1f15 Mon Sep 17 00:00:00 2001 From: derrod Date: Mon, 1 Jun 2020 11:20:26 +0200 Subject: [PATCH] [models] Enable JSON to binary manifest serialization --- legendary/models/json_manifest.py | 7 ++++++- legendary/models/manifest.py | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/legendary/models/json_manifest.py b/legendary/models/json_manifest.py index e05cf4c..54ad2e3 100644 --- a/legendary/models/json_manifest.py +++ b/legendary/models/json_manifest.py @@ -73,7 +73,12 @@ class JSONManifest(Manifest): return _manifest def write(self, *args, **kwargs): - raise NotImplementedError('Serializing JSON manifests is not supported') + # The version here only matters for the manifest header, + # the feature level in meta determines chunk folders etc. + # So all that's required for successful serialization is + # setting it to something high enough to be a binary manifest + self.version = 18 + return super().write(*args, **kwargs) class JSONManifestMeta(ManifestMeta): diff --git a/legendary/models/manifest.py b/legendary/models/manifest.py index 2508ee7..2f88796 100644 --- a/legendary/models/manifest.py +++ b/legendary/models/manifest.py @@ -68,7 +68,7 @@ class Manifest: self.size_uncompressed = 0 self.sha_hash = '' self.stored_as = 0 - self.version = 17 + self.version = 18 self.data = b'' # remainder @@ -87,7 +87,7 @@ class Manifest: _tmp = BytesIO(_m.data) _m.meta = ManifestMeta.read(_tmp) - _m.chunk_data_list = CDL.read(_tmp, _m.version) + _m.chunk_data_list = CDL.read(_tmp, _m.meta.feature_level) _m.file_manifest_list = FML.read(_tmp) _m.custom_fields = CustomFields.read(_tmp) @@ -175,7 +175,7 @@ class ManifestMeta: def __init__(self): self.meta_size = 0 self.data_version = 0 - self.feature_level = 17 + self.feature_level = 18 self.is_file_data = False self.app_id = 0 self.app_name = '' @@ -208,11 +208,14 @@ class ManifestMeta: _meta = cls() _meta.meta_size = struct.unpack('