Read blendfile sub-version

Add support for reading the blend file's sub-version.
This commit is contained in:
Sybren A. Stüvel
2025-07-11 15:30:58 +02:00
parent 2489e4cbbc
commit 4c429e9212
2 changed files with 34 additions and 0 deletions
@@ -122,6 +122,7 @@ class BlendFile:
self.filepath = path
self.raw_filepath = path
self._is_modified = False
self.file_subversion = 0
self.fileobj = self._open_file(path, mode)
self.blocks = [] # type: BFBList
@@ -169,6 +170,8 @@ class BlendFile:
if block.code == b"DNA1":
self.decode_structs(block)
elif block.code == b"GLOB":
self.decode_glob(block)
else:
self.fileobj.seek(block.size, os.SEEK_CUR)
@@ -356,6 +359,25 @@ class BlendFile:
dna_struct.append_field(field)
dna_offset += dna_size
def decode_glob(self, block: "BlendFileBlock") -> None:
"""Partially decode the GLOB block to get the file sub-version."""
# Before this, the subversion didn't exist in 'FileGlobal'.
if self.header.version <= 242:
self.file_subversion = 0
return
# GLOB can appear in the file before DNA1, and so we cannot use DNA to
# parse the fields.
# The subversion is always the `short` at offset 4.
# block_data = io.BytesIO(block.raw_data())
endian = self.header.endian
self.fileobj.seek(4, os.SEEK_CUR) # Skip the next 4 bytes.
self.file_subversion = endian.read_short(self.fileobj)
# Skip to the next block.
self.fileobj.seek(block.file_offset + block.size, os.SEEK_SET)
def abspath(self, relpath: bpathlib.BlendPath) -> bpathlib.BlendPath:
"""Construct an absolute path from a blendfile-relative path."""