from os import environ
from pathlib import PurePath
-__programs: dict[str, str] = None
-
-def program(program: str) -> str:
- global __programs
-
- if (__programs == None):
- __programs = {}
-
- if (program not in __programs):
- __programs[program] = which(program)
-
- return __programs[program]
+import gamiki.support.custom_commands as custom
def dosbox(dir: PurePath, link: PurePath) -> int:
- if (program("app.sh") != None):
- cmd = [ program("app.sh"),"--wait","dosbox","--link",link.as_posix() ]
- elif(program("dosbox") != None):
- cmd = [ program("dosbox") ]
- else:
- raise RuntimeError("DosBox not found")
+
+ cmd, env = custom.cmd("dosbox", link, None)
+ if (not cmd):
+ if (prog := custom.program("dosbox")):
+ cmd = [ prog ]
+ else:
+ raise RuntimeError("DosBox not found")
base = dir.joinpath("base.conf")
if (base.exists()):
cmd.append("-conf")
cmd.append(dir.joinpath("start.conf").as_posix())
- return run(cmd, cwd=dir).returncode
-
-def start_sh(start: PurePath) -> int:
- env = environ.copy()
-
- if (program("launch.sh") != None):
- cmd = [ program("launch.sh"), "games", "--dlink", start.as_posix() ]
- env["OPTS"] = "--entrypoint=bash"
- else:
- cmd = [ start.as_posix() ]
-
- return run(cmd, cwd=start.parent, env=env).returncode
+ return run(cmd, cwd=dir, env=env).returncode
def wine(dir: PurePath) -> int:
- env = environ.copy()
- wine_bat = dir.joinpath("wine.bat").as_posix()
- wine_prefix = dir.joinpath("wine.prefix").as_posix()
+ wine_bat = dir.joinpath("wine.bat")
+ wine_prefix = dir.joinpath("wine.prefix")
- if (program("launch.sh") != None):
- cmd = [ program("launch.sh"), "wine", "--dlink", wine_bat ]
- env["OPTS"] = "-e WINEPREFIX='" + wine_prefix.replace("'", "\\'") + "'"
- elif (program("wine") != None):
- cmd = [ "wine", wine_bat ]
- else:
- raise RuntimeError("wine not found")
+ cmd, env = custom.cmd("wine", wine_bat, wine_prefix)
+ if (not cmd):
+ if (prog := custom.program("wine")):
+ cmd = [ prog, wine_bat.as_posix() ]
+ env["WINEPREFIX"] = wine_prefix.as_posix()
+ else:
+ raise RuntimeError("wine not found")
return run(cmd, cwd=dir, env=env).returncode
+def start_sh(start: PurePath) -> int:
+
+ cmd, env = custom.cmd("start_sh", start, None)
+ if (not cmd):
+ cmd = [ start.as_posix() ]
+
+ return run(cmd, cwd=start.parent, env=env).returncode
+
--- /dev/null
+from typing import Optional
+from subprocess import run
+from shutil import which
+from os import environ
+from pathlib import PurePath
+
+__programs__: dict[str, Optional[str]] = { }
+
+def program(program: str) -> Optional[str]:
+ global __programs__
+
+ if (program not in __programs__):
+ __programs__[program] = which(program)
+
+ return __programs__[program]
+
+def cmd (
+ prog: str, p1: PurePath, p2: Optional[PurePath]
+ ) -> (Optional[list[str]], dict[str, str]):
+
+ cmd = None
+ env = environ.copy()
+
+ match prog:
+ case "dosbox":
+ if (program("app.sh")):
+ cmd = [
+ program("app.sh"),"--wait","dosbox","--link",p1.as_posix()
+ ]
+ case "wine":
+ if (program("launch.sh")):
+ cmd = [ program("launch.sh"), "wine", "--dlink", p1.as_posix() ]
+ env["OPTS"] = (
+ "-e WINEPREFIX='" + p2.as_posix().replace("'", "\\'") + "'"
+ )
+ case "start_sh":
+ if (program("launch.sh")):
+ cmd = [
+ program("launch.sh"), "games", "--dlink", p1.as_posix()
+ ]
+ env["OPTS"] = "--entrypoint=bash"
+
+ return cmd, env
+