from pathlib import Path, PurePath
from . import Library, Game
-from .support import Support, SupportDos, SupportWin31, SupportGog
+from .support import Support, SupportDos, SupportWin31, SupportGog, SupportExt
class Builder:
"""Manage all the resources needed to run games."""
self.libraries : list[Library] = []
self.games : list[Game] = []
- supports = []
+ supports = [] # be careful about the order
supports.append(SupportGog())
- supports.append(SupportWin31()) # prio over DOS
+ supports.append(SupportWin31())
supports.append(SupportDos())
+ supports.append(SupportExt())
targets = []
config = Path("~/.games.cfg").expanduser()
--- /dev/null
+from random import random
+from math import floor
+from os import environ
+from pathlib import Path
+from subprocess import run
+from shutil import which
+
+from . import Support
+from ..game import Game
+
+class SupportExt(Support):
+ """Supports external games via the 'games' docker or natively."""
+ def __init__(self):
+ pass
+
+ def supports(self, game: Game):
+ return game.dir.joinpath("start.sh").exists()
+
+ def start(self, game: Game, params: list[str] = []):
+ dir = game.dir.resolve()
+
+ env = environ.copy()
+
+ ffile = None
+ if (Support.program("launch.sh") != None):
+ tfile = Path(
+ "/tmp/shared/.game-"
+ + "{0:6d}".format(floor(random() * 1000000))
+ + ".sh"
+ )
+ with open(tfile, 'w', encoding="utf-8") as data:
+ data.write("#!/bin/sh\n")
+ data.write("cd '" + dir.as_posix() + "'\n")
+ data.write("./start.sh\n")
+ tfile.chmod(0o777)
+ env["OPTS"] = "--entrypoint=" + tfile.as_posix()
+ cmd = [
+ Support.program("launch.sh"),
+ "games", "--link", dir.as_posix()
+ ]
+ else:
+ cmd = [ dir.joinpath("start.sh").as_posix() ]
+
+ print("Running", game.name)
+ rep = run(cmd, cwd=dir, env=env)
+ if (rep.returncode != 0):
+ print("\nError when running", game.name, ": RC", rep.returncode)
+
+ if (tfile != ""):
+ tfile.unlink()
+