python/vdfparser: Support parsing new appinfo.vdf format

master
Taeyeon Mori 2 years ago
parent 2cca6237df
commit 10057f1114
  1. 20
      lib/python/vdfparser.py

@ -335,6 +335,7 @@ class BinaryVdfParser:
class AppInfoFile: class AppInfoFile:
S_APP_HEADER = struct.Struct("<IIIIQ20sI") S_APP_HEADER = struct.Struct("<IIIIQ20sI")
S_APP_HEADER_V2 = struct.Struct("<IIIIQ20sI20s")
S_INT4 = struct.Struct("<I") S_INT4 = struct.Struct("<I")
@classmethod @classmethod
@ -353,7 +354,7 @@ class AppInfoFile:
return self.parser.parse(self.file) return self.parser.parse(self.file)
class App: class App:
__slots__ = "appinfo", "offset", "id", "size", "state", "last_update", "token", "hash", "changeset", "_data" __slots__ = "appinfo", "offset", "id", "size", "state", "last_update", "token", "hash", "changeset", "hash_bin", "_data"
def __init__(self, appinfo, offset, struct): def __init__(self, appinfo, offset, struct):
self.id = struct[0] self.id = struct[0]
@ -363,6 +364,7 @@ class AppInfoFile:
self.token = struct[4] self.token = struct[4]
self.hash = struct[5] self.hash = struct[5]
self.changeset = struct[6] self.changeset = struct[6]
self.hash_bin = struct[7] if len(struct) > 7 else None
self.appinfo = appinfo self.appinfo = appinfo
self.offset = offset self.offset = offset
self._data = None self._data = None
@ -396,13 +398,17 @@ class AppInfoFile:
def _load(self): def _load(self):
magic = self._read_exactly(4) magic = self._read_exactly(4)
if magic != b"\x27\x44\x56\x07": if magic == b"\x28\x44\x56\x07":
raise ValueError("Wrong appinfo.vdf magic") header_struct = self.S_APP_HEADER_V2
elif magic == b"\x27\x44\x56\x07":
header_struct = self.S_APP_HEADER
else:
raise ValueError("Unknown appinfo.vdf magic")
self._universe = self._read_int() self._universe = self._read_int()
self._apps = {} self._apps = {}
buffer = bytearray(self.S_APP_HEADER.size) buffer = bytearray(header_struct.size)
while True: while True:
read = self.file.readinto(buffer) read = self.file.readinto(buffer)
@ -410,17 +416,17 @@ class AppInfoFile:
if read < 4: if read < 4:
raise EOFError() raise EOFError()
struct = self.S_APP_HEADER.unpack(buffer) struct = header_struct.unpack(buffer)
appid, size, *_ = struct appid, size, *_ = struct
if appid == 0: if appid == 0:
return # Done return # Done
elif read < self.S_APP_HEADER.size: elif read < header_struct.size:
raise EOFError() raise EOFError()
self._apps[appid] = self.App(self, self.file.tell(), struct) self._apps[appid] = self.App(self, self.file.tell(), struct)
self.file.seek(size - (self.S_APP_HEADER.size - 8), io.SEEK_CUR) self.file.seek(size - (header_struct.size - 8), io.SEEK_CUR)
@property @property
def universe(self): def universe(self):

Loading…
Cancel
Save