forked from rosebudai/OpenRCT2-Web
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""Keep the browser title scene on one park to avoid a blocking park swap."""
|
||
|
|
|
||
|
|
from io import BytesIO
|
||
|
|
from pathlib import Path
|
||
|
|
from tempfile import NamedTemporaryFile
|
||
|
|
from zipfile import ZipFile
|
||
|
|
|
||
|
|
|
||
|
|
assets_path = Path(__file__).resolve().parents[1] / "build/www/assets.zip"
|
||
|
|
title_script = (
|
||
|
|
b"# Browser title sequence\n"
|
||
|
|
b"LOAD Kahuna Point by Enrico Dandolo & Kyphii & RobMan.park\n"
|
||
|
|
b"ZOOM 0\n"
|
||
|
|
b"LOCATION 97 54\n"
|
||
|
|
+ b"WAIT 60000\n" * 1000
|
||
|
|
)
|
||
|
|
|
||
|
|
with ZipFile(assets_path) as assets:
|
||
|
|
sequence_bytes = assets.read("sequence/openrct2.parkseq")
|
||
|
|
|
||
|
|
sequence_output = BytesIO()
|
||
|
|
with ZipFile(BytesIO(sequence_bytes)) as source, ZipFile(sequence_output, "w") as target:
|
||
|
|
for entry in source.infolist():
|
||
|
|
target.writestr(entry, title_script if entry.filename == "script.txt" else source.read(entry))
|
||
|
|
|
||
|
|
with NamedTemporaryFile(dir=assets_path.parent, suffix=".zip", delete=False) as temporary:
|
||
|
|
temporary_path = Path(temporary.name)
|
||
|
|
|
||
|
|
try:
|
||
|
|
with ZipFile(assets_path) as source, ZipFile(temporary_path, "w") as target:
|
||
|
|
for entry in source.infolist():
|
||
|
|
data = sequence_output.getvalue() if entry.filename == "sequence/openrct2.parkseq" else source.read(entry)
|
||
|
|
target.writestr(entry, data)
|
||
|
|
temporary_path.replace(assets_path)
|
||
|
|
except BaseException:
|
||
|
|
temporary_path.unlink(missing_ok=True)
|
||
|
|
raise
|