"""Decode selected original local resources for private offline palette research."""
import hashlib
import json
import re
import runpy
import sys
import zlib
from pathlib import Path
keys=sys.argv[1:]
sys.argv=['inventory','artifacts/galaxy-query-research/palette-resources/unused.json']
assets=runpy.run_path('research/galaxy_asset_inventory.py')
out=Path('artifacts/galaxy-query-research/palette-resources')
for key in keys:
path=assets['ROOT']/('0'+key[0])/key
data=assets['decode'](path)
(out/(key+'.fres')).write_bytes(data)
blocks=[]
for match in re.finditer(rb'\x78[\x01\x9c\xda]',data):
try:
decoder=zlib.decompressobj();body=decoder.decompress(data[match.start():],16*1024*1024)
if not decoder.eof:continue
except zlib.error:continue
index=len(blocks);(out/(key+f'.block{index}')).write_bytes(body)
blocks.append(dict(offset=match.start(),bytes=len(body),strings=[m.group().decode('ascii') for m in re.finditer(rb'[ -~]{4,}',body)]))
row=dict(source=str(path),sha256=hashlib.sha256(path.read_bytes()).hexdigest(),decodedBytes=len(data),blocks=blocks,
strings=[m.group().decode('ascii') for m in re.finditer(rb'[ -~]{4,}',data[:32768])])
(out/(key+'.json')).write_text(json.dumps(row,indent=2),encoding='utf-8')
print(json.dumps(row,indent=2))
"""Decode selected original local resources for private offline palette research."""
import hashlib
import json
import re
import runpy
import sys
import zlib
from pathlib import Path
keys=sys.argv[1:]
sys.argv=['inventory','artifacts/galaxy-query-research/palette-resources/unused.json']
assets=runpy.run_path('research/galaxy_asset_inventory.py')
out=Path('artifacts/galaxy-query-research/palette-resources')
for key in keys:
path=assets['ROOT']/('0'+key[0])/key
data=assets['decode'](path)
(out/(key+'.fres')).write_bytes(data)
blocks=[]
for match in re.finditer(rb'\x78[\x01\x9c\xda]',data):
try:
decoder=zlib.decompressobj();body=decoder.decompress(data[match.start():],16*1024*1024)
if not decoder.eof:continue
except zlib.error:continue
index=len(blocks);(out/(key+f'.block{index}')).write_bytes(body)
blocks.append(dict(offset=match.start(),bytes=len(body),strings=[m.group().decode('ascii') for m in re.finditer(rb'[ -~]{4,}',body)]))
row=dict(source=str(path),sha256=hashlib.sha256(path.read_bytes()).hexdigest(),decodedBytes=len(data),blocks=blocks,
strings=[m.group().decode('ascii') for m in re.finditer(rb'[ -~]{4,}',data[:32768])])
(out/(key+'.json')).write_text(json.dumps(row,indent=2),encoding='utf-8')
print(json.dumps(row,indent=2))