the files
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""
|
||||
VPS: swap the CDN's Unity 6 avatar bundles for 2021.3.41f1-stamped copies, in place.
|
||||
|
||||
1. ConvertBundles2021.py /opt/campus/Data/CDN/AvatarBlobs -> /opt/campus/conv2021/out (already run)
|
||||
2. this script:
|
||||
- every converted file: original -> /opt/campus/AvatarBlobs.orig6000/<name>, converted -> AvatarBlobs/<name>
|
||||
- UGC.json / ImportedUGC.json / CreatedUGC.json: UnityAssetHash / UnityAsset2Hash rewritten from hashes.json
|
||||
(backups *.bak-conv2021 kept beside them)
|
||||
- prints what it did; the caller restarts the service so CustomItemsCache reloads
|
||||
Undo = move the .orig6000 files back and restore the .bak-conv2021 catalogs.
|
||||
"""
|
||||
import json, os, shutil, sys
|
||||
|
||||
BLOBS = "/opt/campus/Data/CDN/AvatarBlobs"
|
||||
OUT = "/opt/campus/conv2021/out"
|
||||
BACKUP = "/opt/campus/AvatarBlobs.orig6000"
|
||||
ITEMS = "/opt/campus/Data/APIS/items"
|
||||
|
||||
hashes = json.load(open(os.path.join(OUT, "hashes.json")))
|
||||
os.makedirs(BACKUP, exist_ok=True)
|
||||
|
||||
swapped = skipped = 0
|
||||
for name in hashes:
|
||||
src = os.path.join(OUT, name)
|
||||
live = os.path.join(BLOBS, name)
|
||||
if not os.path.exists(src):
|
||||
skipped += 1
|
||||
continue
|
||||
if os.path.exists(live) and not os.path.exists(os.path.join(BACKUP, name)):
|
||||
# Diamond Crown's originals were parked as .orig6000 beside the file by the one-item test.
|
||||
beside = live + ".orig6000"
|
||||
if os.path.exists(beside):
|
||||
shutil.move(beside, os.path.join(BACKUP, name))
|
||||
else:
|
||||
shutil.move(live, os.path.join(BACKUP, name))
|
||||
shutil.move(src, live)
|
||||
swapped += 1
|
||||
print(f"bundles: {swapped} swapped in, {skipped} had no converted copy; originals in {BACKUP}")
|
||||
|
||||
for cat in ("UGC.json", "ImportedUGC.json", "CreatedUGC.json"):
|
||||
path = os.path.join(ITEMS, cat)
|
||||
if not os.path.exists(path):
|
||||
continue
|
||||
root = json.load(open(path, encoding="utf-8"))
|
||||
changed = 0
|
||||
for it in root.get("Results", []):
|
||||
for s in it.get("CurrentSaves") or []:
|
||||
for ak, hk in (("UnityAsset", "UnityAssetHash"), ("UnityAsset2", "UnityAsset2Hash")):
|
||||
a = s.get(ak)
|
||||
if a and a in hashes and s.get(hk) != hashes[a]:
|
||||
s[hk] = hashes[a]
|
||||
changed += 1
|
||||
if changed:
|
||||
bak = path + ".bak-conv2021"
|
||||
if not os.path.exists(bak):
|
||||
shutil.copy2(path, bak)
|
||||
json.dump(root, open(path, "w", encoding="utf-8"), separators=(",", ":"))
|
||||
print(f"{cat}: {changed} hash(es) updated")
|
||||
Reference in New Issue
Block a user