new: windows games support via wine
authorNiki Roo <niki@nikiroo.be>
Sun, 23 Mar 2025 20:11:11 +0000 (21:11 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 23 Mar 2025 20:11:11 +0000 (21:11 +0100)
gamiki/builder.py
gamiki/support/__init__.py
gamiki/support/support_gog.py
gamiki/support/support_win.py [new file with mode: 0644]

index 943143d31c4b2ebfd90e85f339abd9a8880fb217..b63bc2c2caa04b997018f5af427ee76fcd08b2bf 100644 (file)
@@ -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())
index 095447b8e5d4e8b0895c2a42888b9e84ff2fd64d..c7e3aed184c186f84ae5478f8eff6760b476a47a 100644 (file)
@@ -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
index 3e832cd5626bec6d3d2d6372ca198f521e6c1dc9..2344aa3907665a652ed7e98d306230cd5b5f41a8 100644 (file)
@@ -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 (file)
index 0000000..17e802b
--- /dev/null
@@ -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)
+        
+