Files

42 lines
2.2 KiB
Python
Raw Permalink Normal View History

"""Fetch only the Windows x64 release entry from the official Godot template ZIP.
HTTP ranges avoid downloading the Android/Linux/macOS templates (1 GB total).
zipfile verifies the selected member's CRC on read. No downloaded code is run.
"""
import io, urllib.request, zipfile
from pathlib import Path
URL='https://github.com/godotengine/godot-builds/releases/download/4.3-stable/Godot_v4.3-stable_export_templates.tpz'
class RemoteZip(io.RawIOBase):
def __init__(self):
self.pos=0
req=urllib.request.Request(URL,headers={'Range':'bytes=0-0','User-Agent':'Demon-build/0.4'})
with urllib.request.urlopen(req,timeout=60) as r:
if r.status!=206: raise RuntimeError('Server did not honor HTTP Range')
self.size=int(r.headers['Content-Range'].split('/')[-1])
self.url=r.url
def seekable(self): return True
def readable(self): return True
def tell(self): return self.pos
def seek(self,offset,whence=0):
self.pos=offset if whence==0 else self.pos+offset if whence==1 else self.size+offset
return self.pos
def read(self,n=-1):
if n<0: n=self.size-self.pos
n=min(n,self.size-self.pos)
if n<=0:return b''
req=urllib.request.Request(self.url,headers={'Range':f'bytes={self.pos}-{self.pos+n-1}','User-Agent':'Demon-build/0.4'})
with urllib.request.urlopen(req,timeout=120) as r:
if r.status!=206: raise RuntimeError('Range response required')
start=int(r.headers['Content-Range'].split(' ')[1].split('-')[0])
if start!=self.pos:raise RuntimeError('Unexpected range')
data=r.read()
if len(data)!=n:raise RuntimeError('Incomplete range')
self.pos+=n
return data
with zipfile.ZipFile(RemoteZip()) as z:
names=[x for x in z.namelist() if x.endswith('windows_release_x86_64.exe')]
if len(names)!=1:raise RuntimeError(str([x for x in z.namelist() if 'windows' in x]))
out=Path(__file__).resolve().parent/'templates'/'windows_release_x86_64.exe'
out.parent.mkdir(exist_ok=True)
out.write_bytes(z.read(names[0]))
print(f'Official Windows template: {out} ({out.stat().st_size} bytes), ZIP CRC verified')