mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[models] Add tentative support for new file manifest fields
Why on earth would anybody want MD5 hashes?
This commit is contained in:
parent
b27879f21f
commit
eacb8eb006
|
@ -522,6 +522,21 @@ class FML:
|
||||||
logger.warning(f'Did not read {diff} bytes from chunk part!')
|
logger.warning(f'Did not read {diff} bytes from chunk part!')
|
||||||
bio.seek(diff)
|
bio.seek(diff)
|
||||||
|
|
||||||
|
# MD5 hash + MIME type
|
||||||
|
if _fml.version >= 1:
|
||||||
|
for fm in _fml.elements:
|
||||||
|
_has_md5 = struct.unpack('<I', bio.read(4))[0]
|
||||||
|
if _has_md5 != 0:
|
||||||
|
fm.hash_md5 = bio.read(16)
|
||||||
|
|
||||||
|
for fm in _fml.elements:
|
||||||
|
fm.mime_type = read_fstring(bio)
|
||||||
|
|
||||||
|
# SHA256 hash
|
||||||
|
if _fml.version >= 2:
|
||||||
|
for fm in _fml.elements:
|
||||||
|
fm.hash_sha256 = bio.read(32)
|
||||||
|
|
||||||
# we have to calculate the actual file size ourselves
|
# we have to calculate the actual file size ourselves
|
||||||
for fm in _fml.elements:
|
for fm in _fml.elements:
|
||||||
fm.file_size = sum(c.size for c in fm.chunk_parts)
|
fm.file_size = sum(c.size for c in fm.chunk_parts)
|
||||||
|
@ -531,14 +546,15 @@ class FML:
|
||||||
f'{_fml.size - size_read} bytes missing, skipping...')
|
f'{_fml.size - size_read} bytes missing, skipping...')
|
||||||
bio.seek(_fml.size - size_read, 1)
|
bio.seek(_fml.size - size_read, 1)
|
||||||
# downgrade version to prevent issues during serialisation
|
# downgrade version to prevent issues during serialisation
|
||||||
_fml.version = 1
|
_fml.version = 2
|
||||||
|
|
||||||
return _fml
|
return _fml
|
||||||
|
|
||||||
def write(self, bio):
|
def write(self, bio):
|
||||||
fml_start = bio.tell()
|
fml_start = bio.tell()
|
||||||
bio.write(struct.pack('<I', 0)) # placeholder size
|
bio.write(struct.pack('<I', 0)) # placeholder size
|
||||||
bio.write(struct.pack('B', self.version))
|
# currently we only serialise version 0
|
||||||
|
bio.write(struct.pack('B', 0))
|
||||||
bio.write(struct.pack('<I', len(self.elements)))
|
bio.write(struct.pack('<I', len(self.elements)))
|
||||||
|
|
||||||
for fm in self.elements:
|
for fm in self.elements:
|
||||||
|
@ -579,6 +595,9 @@ class FileManifest:
|
||||||
self.install_tags = []
|
self.install_tags = []
|
||||||
self.chunk_parts = []
|
self.chunk_parts = []
|
||||||
self.file_size = 0
|
self.file_size = 0
|
||||||
|
self.hash_md5 = b''
|
||||||
|
self.mime_type = ''
|
||||||
|
self.hash_sha256 = b''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def read_only(self):
|
def read_only(self):
|
||||||
|
|
Loading…
Reference in a new issue