[models] Calculate group_num based on GUID

This commit is contained in:
derrod 2020-05-09 11:04:29 +02:00
parent 17ea65d2da
commit 8328a8ebaa

View file

@ -400,11 +400,12 @@ class ChunkInfo:
self.guid = None self.guid = None
self.hash = 0 self.hash = 0
self.sha_hash = b'' self.sha_hash = b''
self.group_num = 0
self.window_size = 0 self.window_size = 0
self.file_size = 0 self.file_size = 0
self._manifest_version = manifest_version self._manifest_version = manifest_version
# caches for things that are "expensive" to compute # caches for things that are "expensive" to compute
self._group_num = None
self._guid_str = None self._guid_str = None
self._guid_num = None self._guid_num = None
@ -427,16 +428,27 @@ class ChunkInfo:
return self._guid_num return self._guid_num
@property @property
def path(self): def group_num(self):
return '{}/{:02d}/{:016X}_{}.chunk'.format( if self._guid_num is not None:
get_chunk_dir(self._manifest_version), return self._group_num
# the result of this seems to always match the group number, but this is the "correct way"
(zlib.crc32(struct.pack('<I', self.guid[0]) + self._group_num = (zlib.crc32(
struct.pack('<I', self.guid[0]) +
struct.pack('<I', self.guid[1]) + struct.pack('<I', self.guid[1]) +
struct.pack('<I', self.guid[2]) + struct.pack('<I', self.guid[2]) +
struct.pack('<I', self.guid[3])) & 0xffffffff) % 100, struct.pack('<I', self.guid[3])
self.hash, ''.join('{:08X}'.format(g) for g in self.guid) ) & 0xffffffff) % 100
) return self._group_num
@group_num.setter
def group_num(self, value):
self._group_num = value
@property
def path(self):
return '{}/{:02d}/{:016X}_{}.chunk'.format(
get_chunk_dir(self._manifest_version), self.group_num,
self.hash, ''.join('{:08X}'.format(g) for g in self.guid))
class FML: class FML: