from pathlib import Path
import hashlib,json
root=Path(__file__).resolve().parent
m=json.loads((root/'source-checksums.json').read_text())
data=[]
for part in m['parts']:
    b=(root/part['name']).read_bytes()
    if len(b)!=part['bytes'] or hashlib.sha256(b).hexdigest()!=part['sha256']:
        raise SystemExit('A source part is missing or corrupted')
    data.append(b)
out=b''.join(data)
if hashlib.sha256(out).hexdigest()!=m['sha256']:raise SystemExit('Archive checksum mismatch')
with (root/m['archive']).open('xb') as f:f.write(out)
print('Source archive assembled and verified. Extract it and read README-SOURCE.txt.')
