import os, json, glob
BASE = os.path.dirname(os.path.abspath(__file__))
files = glob.glob(os.path.join(BASE, '**', 'manifest.json'), recursive=True)
SEQ = ['\\(', '\\)', '\\[', '\\]']
def fix(v):
    if isinstance(v, str):
        for a in SEQ:
            v = v.replace(a, '$$')
        return v
    if isinstance(v, list):
        return [fix(x) for x in v]
    if isinstance(v, dict):
        return {k: fix(x) for k, x in v.items()}
    return v
changed = 0
for f in files:
    try:
        with open(f, encoding='utf-8') as fh:
            data = json.load(fh)
    except Exception:
        continue
    new = fix(data)
    if new != data:
        with open(f, 'w', encoding='utf-8') as fh:
            json.dump(new, fh, ensure_ascii=False, indent=1)
        changed += 1
print("manifests changed:", changed, "of", len(files))
