mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 15:56:01 +00:00
* perf(steam): setup applies Steam's client update itself so the first launch has nothing to unpack The setup already downloads every package of Steam's client update. droiddeck-steam-preapply now extracts them and writes the .installed and .manifest records the way Steam's updater does, so the first launch verifies and starts instead of unpacking for about half a minute and restarting. When it cannot, the packages stay and Steam updates itself as before. * perf(setup): the Steam stage skips the plain packages it just applied, and Proton's install trusts the prefetch's checksum With the whole client update applied from the cached packages, the separate 362 MB plain-package install is redundant: the cache pass applies the update and finishes the install, and the plain install stays as the fallback. DroidDeck Proton's archive was hashed twice more at install time after the prefetch had already verified it; the install now reuses that result while the file is unchanged. * fix(steam): a failed or cancelled apply leaves nothing stale, extraction stays inside the Steam root, and a cache failure still installs A failed apply removes its record and the cache marker so the next run retries; cancelling stops the helper; entries that leave the Steam root, directly or through a symlink, are refused; the plain install still runs when the cache pass fails; Proton's install reuses the prefetch's verification only for the same digest. * fix(steam): a cancelled apply clears the cache marker too
93 lines
3.9 KiB
Python
Executable File
93 lines
3.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Extract Steam's cached update packages and record them the way Steam's own updater does."""
|
|
import hashlib, lzma, os, re, stat, struct, sys, time, zipfile, io, zlib, calendar
|
|
|
|
OSVER = "-184"
|
|
MTIME_OFFSET = 28800
|
|
|
|
|
|
def blocks(manifest):
|
|
out, cur, depth = {}, None, 0
|
|
for line in manifest.splitlines():
|
|
m = re.match(r'^(\t+)"([^"]+)"\s*(?:"([^"]*)")?\s*$', line)
|
|
if m and m.group(3) is None and len(m.group(1)) == 1:
|
|
cur = m.group(2)
|
|
out[cur] = {}
|
|
elif m and m.group(3) is not None and len(m.group(1)) == 2 and cur:
|
|
out[cur][m.group(2)] = m.group(3)
|
|
return out
|
|
|
|
|
|
def unvz(d):
|
|
if d[:3] != b"VZa" or d[-2:] != b"zv":
|
|
raise ValueError("not a VZip")
|
|
props = d[7]
|
|
dict_size = struct.unpack("<I", d[8:12])[0]
|
|
crc, size = struct.unpack("<II", d[-10:-2])
|
|
f = [{"id": lzma.FILTER_LZMA1, "dict_size": dict_size,
|
|
"lc": props % 9, "lp": (props // 9) % 5, "pb": props // 45}]
|
|
out = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=f).decompress(d[12:-10], max_length=size)
|
|
if len(out) != size or zlib.crc32(out) & 0xFFFFFFFF != crc:
|
|
raise ValueError("bad VZip")
|
|
return out
|
|
|
|
|
|
def inside(root, path):
|
|
return os.path.commonpath([root, path]) == root
|
|
|
|
|
|
def main(package_dir, steam_root, manifest_path, name):
|
|
steam_root = os.path.realpath(steam_root)
|
|
manifest = open(manifest_path, encoding="utf-8", errors="replace").read()
|
|
rows = {}
|
|
for block, attrs in blocks(manifest).items():
|
|
for key in ("zipvz", "file"):
|
|
f = attrs.get(key)
|
|
if f and os.path.isfile(os.path.join(package_dir, f)):
|
|
break
|
|
else:
|
|
raise SystemExit(f"missing package for {block}")
|
|
data = open(os.path.join(package_dir, f), "rb").read()
|
|
zdata = unvz(data) if key == "zipvz" else data
|
|
del data
|
|
with zipfile.ZipFile(io.BytesIO(zdata)) as z:
|
|
for info in z.infolist():
|
|
rel = info.filename.replace("\\", "/")
|
|
if rel.startswith("/") or ".." in rel.split("/"):
|
|
raise SystemExit(f"unsafe path in {block}: {rel}")
|
|
dest = os.path.join(steam_root, rel)
|
|
if not inside(steam_root, os.path.realpath(os.path.dirname(dest.rstrip("/")))):
|
|
raise SystemExit(f"path leaves the Steam root in {block}: {rel}")
|
|
mode = (info.external_attr >> 16) & 0xFFFF
|
|
mtime = calendar.timegm(info.date_time + (0, 0, 0)) + MTIME_OFFSET
|
|
if rel.endswith("/"):
|
|
os.makedirs(dest, exist_ok=True)
|
|
rows[rel] = (-1, mtime, 0)
|
|
continue
|
|
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
|
if stat.S_ISLNK(mode):
|
|
if os.path.lexists(dest):
|
|
os.unlink(dest)
|
|
os.symlink(z.read(info).decode(), dest)
|
|
rows[rel] = (-2, mtime, info.CRC)
|
|
continue
|
|
with open(dest + ".dd-tmp", "wb") as out:
|
|
out.write(z.read(info))
|
|
os.chmod(dest + ".dd-tmp", (mode & 0o777) | 0o644 if mode else 0o644)
|
|
os.replace(dest + ".dd-tmp", dest)
|
|
rows[rel] = (info.file_size, mtime, info.CRC)
|
|
del zdata
|
|
body = "".join(f"{p},{s};{m};{c}\n" for p, (s, m, c) in sorted(rows.items(), key=lambda kv: kv[0].upper()))
|
|
body += f"OSVER={OSVER}\nVERSION=3\n"
|
|
sha = hashlib.sha1(body.encode()).hexdigest().upper()
|
|
pkg = os.path.join(steam_root, "package")
|
|
os.makedirs(pkg, exist_ok=True)
|
|
tmp = os.path.join(pkg, name + ".installed.dd-tmp")
|
|
with open(tmp, "w", encoding="utf-8") as f:
|
|
f.write(body + f"SHA1={sha}\n")
|
|
os.replace(tmp, os.path.join(pkg, name + ".installed"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(*sys.argv[1:5])
|