Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

2.4 KB
Raw Blame
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile


with tempfile.TemporaryDirectory(prefix="np-shortcut-icons-") as temporary:
    root = Path(temporary)
    run = root / "Applications/Game.app/Contents/MacOS/run.sh"
    run.parent.mkdir(parents=True)
    run.write_text('#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/100\n\n')
    icon = root / "Applications/Game.app/Contents/Resources/shortcut.icns"
    icon.parent.mkdir()
    icon.write_bytes(b"old icon")
    shutil.copytree(root / "Applications", root / "Desktop")
    desktop_icon = root / "Desktop/Game.app/Contents/Resources/shortcut.icns"
    desktop_icon.write_bytes(b"user icon")

    support = root / "Library/Application Support/bridgeplay"
    support.mkdir(parents=True)
    (support / "appinfo").write_text("#!/bin/sh\nprintf 'name=Game\\nicon=abc123\\n'\n")
    (support / "iconmaker").write_text(
        '#!/bin/sh\nif [ "$1" = --shortcuts ]; then exec "$REAL_ICONMAKER" "$@"; fi\ncp "$1" "$2"\n')
    for helper in ("appinfo", "iconmaker"):
        (support / helper).chmod(0o755)
    steam = root / "Steam"
    client = steam / "Steam.AppBundle/Steam/Contents/MacOS"
    client.mkdir(parents=True)
    (steam / "appcache").mkdir()
    (steam / "appcache/appinfo.vdf").write_bytes(b"vdf")
    art = steam / "appcache/librarycache/100/abc123.jpg"
    art.parent.mkdir(parents=True)
    art.write_bytes(b"game art")
    stock = client / "steam.icns"
    stock.write_bytes(b"old icon")
    env = dict(os.environ, HOME=str(root), REAL_ICONMAKER=str(Path(sys.argv[1]).resolve()))
    for app_id in ("", "0", "01x", "1;2"):
        assert subprocess.run(["/bin/sh", "dylib/feats/compat_run.sh", "shortcut-icons", app_id, str(client)],
                               env=env, timeout=5).returncode == 1
    assert subprocess.run(["/bin/sh", "dylib/feats/compat_run.sh", "shortcut-icons", "100", "relative/MacOS"],
                           env=env, timeout=5).returncode == 1
    subprocess.run(["/bin/sh", "dylib/feats/compat_run.sh", "shortcut-icons", "100", str(client)],
                   env=env, check=True, timeout=10)
    assert icon.read_bytes() == b"game art"
    assert desktop_icon.read_bytes() == b"user icon"
    assert (support / "shortcut-icons/100/game.icns").read_bytes() == b"game art"
    assert not (support / "launchers").exists()

print("shortcut-launch: Steam-made shortcuts get artwork, custom icons and bad arguments are left alone")