Files

41 lines
2.3 KiB
Python

"""Stale table identities: every ROOT/INSTALL/DOWNLOAD/SIZE/PATCH-INDEX/VFS ckey any LOCAL build config ever named,
minus every table the parent build config still names (the child keeps them), plus the parent DOWNLOAD (replaced here).
Refuses if any stale ckey is a ROOT file or a TVFS path. Output inputs/stale.json."""
import json,re,struct,sys
from pathlib import Path
H=Path(__file__).resolve().parent;sys.path.insert(0,str(H))
from compose import *
sys.path.append('/mnt/Games/@project/wt-master-merge/ops')
CFG=Path('/mnt/Games/OctoWoW-LOCAL-Client/Data/config')
TAB=lambda n:n in('root','install','download','size','patch-index','encoding') or n.startswith('vfs-')
def fields(t):
out={}
for l in t.splitlines():
if ' = ' in l:n,v=l.split(' = ',1);out[n]=v.split()
return out
hist=set()
for f in CFG.rglob('*'):
if f.is_file():
t=f.read_text(errors='ignore')
if '\nroot = ' in '\n'+t:hist|={v[0] for n,v in fields(t).items() if TAB(n) and n!='encoding'}
meta=load(BASE/'metadata.json');pc=fields((BASE/meta['config']['file']).read_text())
keep={v[0] for n,v in pc.items() if TAB(n)}
hx=lambda S:{x for x in S if re.fullmatch('[0-9a-f]{32}',x)}
stale=(hx(hist)-hx(keep))|{pc['download'][0]}
st=ParentReader();root=st.root
rootkeys=set()
for g in st.layout['groups']:rootkeys.update(root[g['ckeys_offset']+16*i:g['ckeys_offset']+16*i+16].hex() for i in range((g['ckeys_offset']-g['ids_offset'])//4))
assert not stale&rootkeys,len(stale&rootkeys)
import casc_tvfs as tvfs
prev=load(BASE/'core.json')['parts']
for b in('tvfs-parent','tvfs-child','tvfs-enus'):
raw=(BASE/prev[b]['decoded_file']).read_bytes();names=' '.join(tvfs.paths(raw,tvfs.layout(raw))).lower()
assert not any(s in names for s in stale),b
raw=(BASE/'decoded/encoding.bin').read_bytes();lay=casc.encoding_layout(raw);present=[];dead=set()
for _,page in lay['sections']['content']:
for k,r in casc._encoding_entries(page,'content'):
if k.hex() in stale:present.append(k.hex());dead.update(r[22+16*j:38+16*j].hex() for j in range(r[0]))
for t in hx(keep)-{pc['download'][0]}:assert t not in present
json.dump(dict(stale_ckeys=sorted(stale),present_ckeys=sorted(present),dead_ekeys=sorted(dead),root_files_checked=len(rootkeys)),open(H/'inputs/stale.json','w'),indent=0)
print('STALE',len(stale),'present',len(present),'dead ekeys',len(dead),'root keys checked',len(rootkeys))