60 lines
3.5 KiB
Python
60 lines
3.5 KiB
Python
"""model.blob on ee45: replace world/model.blob (FDID 764428, wdc_enus-style enUS pin). Build a single additive art ROOT and both parent TVFS branches on the e250 source."""
|
|
import argparse,hashlib,json,os,re,shutil,struct,sys
|
|
from bisect import bisect_right,bisect_left
|
|
from frozen_store import encoding_bucket
|
|
from pathlib import Path
|
|
from frozen_store import Store as ParentReader,PARENT as BASE,BUILD as BASEKEY,ROOT,HERE,BUS,casc
|
|
sys.path[:0]=[str(BUS/'octo-help-active-20261120'),str(BUS/'linux-combined-faf3-20261121')]
|
|
import casc_tvfs as tvfs
|
|
from compose_core import publish
|
|
from compose_encoding import replace_field
|
|
from encoding_capacity import reserve
|
|
OUT=HERE/'candidate'
|
|
F=('content_key','encoding_key','encoded_size','decoded_size','encoding_spec')
|
|
controls={'BLP':143079,'M2':143077,'SKIN':489766,'OGG':537320}
|
|
def load(p):return json.loads(p.read_bytes())
|
|
def sha(d):return hashlib.sha256(d).hexdigest()
|
|
def md5(d):return hashlib.md5(d).hexdigest()
|
|
def file_sha(p):
|
|
with p.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest()
|
|
def save(p,o):
|
|
tmp=p.with_suffix('.part');tmp.write_text(json.dumps(o,indent=2)+'\n');tmp.replace(p)
|
|
def pick(row,fields=F):return {k:row[k] for k in fields}
|
|
def frame(data,parent):
|
|
encodings=[[(data,'Z')],[(data,'N')]]
|
|
for chunks in encodings:
|
|
encoded,row=casc.blte_framed(chunks)
|
|
key=bytes.fromhex(row['encoding_key']);entries=parent.index[encoding_bucket(key)]
|
|
ix=bisect_left(entries,key[:9])
|
|
if ix==len(entries) or entries[ix][:9]!=key[:9]:break
|
|
existing=parent.read(row['content_key'],row['encoding_key'])
|
|
if existing and existing[1]==encoded:break
|
|
else:raise ValueError('No candidate encoding with a verified or new full parent index key')
|
|
assert casc.decode_blte(encoded,encoding_key=row['encoding_key'],content_key=row['content_key'],max_decoded=536870912)==data
|
|
path=OUT/'payloads'/(row['encoding_key']+'.blte')
|
|
if path.exists():assert path.read_bytes()==encoded
|
|
else:path.write_bytes(encoded)
|
|
return dict(pick(row,('content_key','encoding_key','decoded_size','encoded_size')),encoding_spec=casc.blte_frame_spec(chunks),
|
|
decoded_sha256=sha(data),encoded_sha256=sha(encoded),encoded_file=path.relative_to(OUT).as_posix())
|
|
|
|
def main():
|
|
"""Prune-only stage: ROOT and TVFS unchanged (parent frames reused); DOWNLOAD loses the stale table records."""
|
|
for n in ('decoded','payloads'):(OUT/n).mkdir(parents=True,exist_ok=True)
|
|
sys.path.append('/mnt/Games/@project/wt-master-merge/ops');import encoding_prune as EP
|
|
spec=load(HERE/'components.json');assert spec==[]
|
|
prev=load(BASE/'core.json')['parts'];parts={}
|
|
for label,row in prev.items():
|
|
if label=='download':continue
|
|
for f in ('decoded_file','encoded_file'):
|
|
dst=OUT/row[f]
|
|
if not dst.exists():shutil.copyfile(BASE/row[f],dst)
|
|
assert file_sha(dst)==row[f.replace('_file','_sha256')]
|
|
parts[label]=row
|
|
dl=(BASE/prev['download']['decoded_file']).read_bytes();assert md5(dl)==prev['download']['content_key']
|
|
dead={bytes.fromhex(k) for k in load(HERE/'inputs/stale.json')['dead_ekeys']}
|
|
updated,audit=EP.prune_download(dl,dead)
|
|
parts['download']=publish(updated,'download',OUT)
|
|
save(OUT/'core.json',dict(parent_build=BASEKEY,parent_root=ROOT,parts=parts,assets=[],components=spec,complete_root_inverse=True,download_additions=0,download_prune=audit,table_updates={}))
|
|
print('CORE prune download',audit,flush=True)
|
|
if __name__=='__main__':main()
|