From: Niki Roo Date: Sun, 23 Mar 2025 20:11:11 +0000 (+0100) Subject: new: windows games support via wine X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=259d7c45b49ebfeb9d59446932898bce5a2b9cbc;p=gamiki.git new: windows games support via wine --- diff --git a/gamiki/builder.py b/gamiki/builder.py index 943143d..b63bc2c 100644 --- a/gamiki/builder.py +++ b/gamiki/builder.py @@ -2,6 +2,7 @@ from pathlib import Path, PurePath from . import Library, Game from .support import Support, SupportDos, SupportWin31, SupportGog, SupportExt +from .support import SupportWin class Builder: """Manage all the resources needed to run games.""" @@ -11,6 +12,7 @@ class Builder: supports = [] # be careful about the order supports.append(SupportGog()) + supports.append(SupportWin()) supports.append(SupportWin31()) supports.append(SupportDos()) supports.append(SupportExt()) diff --git a/gamiki/support/__init__.py b/gamiki/support/__init__.py index 095447b..c7e3aed 100644 --- a/gamiki/support/__init__.py +++ b/gamiki/support/__init__.py @@ -3,3 +3,4 @@ from .support_dos import SupportDos from .support_win31 import SupportWin31 from .support_gog import SupportGog from .support_ext import SupportExt +from .support_win import SupportWin diff --git a/gamiki/support/support_gog.py b/gamiki/support/support_gog.py index 3e832cd..2344aa3 100644 --- a/gamiki/support/support_gog.py +++ b/gamiki/support/support_gog.py @@ -24,7 +24,7 @@ class SupportGog(Support): env = environ.copy() - ffile = None + tfile = None if (Support.program("launch.sh") != None): tfile = Path( "/tmp/shared/.game-" @@ -50,7 +50,7 @@ class SupportGog(Support): if (rep.returncode != 0): print("\nError when running", game.name, ": RC", rep.returncode) - if (tfile != ""): + if (tfile != None): tfile.unlink() diff --git a/gamiki/support/support_win.py b/gamiki/support/support_win.py new file mode 100644 index 0000000..17e802b --- /dev/null +++ b/gamiki/support/support_win.py @@ -0,0 +1,46 @@ +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 SupportWin(Support): + """Supports Windows games via wine.""" + def __init__(self): + pass + + def supports(self, game: Game): + return game.dir.joinpath("wine.bat").exists() + + def start(self, game: Game, params: list[str] = []): + dir = game.dir.resolve() + + if (not dir.joinpath("wine.prefix").exists()): + raise RuntimeError("Windows game without a wine.prefix") + + wine_bat = dir.joinpath("wine.bat") + wine_prefix = dir.joinpath("wine.prefix").as_posix() + + env = environ.copy() + + tfile = None + if (Support.program("launch.sh") != None): + env["OPTS"] = "-e WINEPREFIX='" +wine_prefix.replace("'","\\'")+ "'" + cmd = [ + Support.program("launch.sh"), + "wine", "--dlink", wine_bat + ] + else: + env["WINEPREFIX"] = wine_prefix + cmd = [ "wine", wine_bat ] + + print("Running", game.name) + rep = run(cmd, env=env) + if (rep.returncode != 0): + print("\nError when running", game.name, ": RC", rep.returncode) + +