add qemu support via qemu.sh
authorNiki Roo <niki@nikiroo.be>
Sat, 3 May 2025 12:50:06 +0000 (14:50 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 3 May 2025 12:50:06 +0000 (14:50 +0200)
gamiki/support/__init__.py
gamiki/support/commands.py
gamiki/support/custom_commands.py
gamiki/support/support.py
gamiki/support/support_qemu.py [new file with mode: 0644]

index 7b22862af630bf12eb758ce4c1645d2e08779779..2c5c3ec64fad859ffea2ebc26e75dea034f288af 100644 (file)
@@ -5,11 +5,13 @@ from .support_win31 import SupportWin31
 from .support_gog   import SupportGog
 from .support_ext   import SupportExt
 from .support_win   import SupportWin
+from .support_qemu  import SupportQemu
 
 Support.all = [ SupportGog()  ,  # gaminfo
                 SupportWin()  ,  # wine.bat
                 SupportWin31(),  # start.conf + C/WINDOWS
                 SupportDos()  ,  # start.conf + no C/WINDOWS
+                SupportQemu() ,  # qemu.config + disk
                 SupportExt()     # start.sh
 ]
 
index bdaf48500d645df85da82b28b748c7e06ebcc11e..654a925300364b6d9c54846ef87d13c17b874485 100644 (file)
@@ -66,6 +66,30 @@ def wine(dir: PurePath, link: PurePath, opt: str = None) -> int:
     
     return run(cmd, cwd=dir, env=env).returncode
 
+def qemu(dir: PurePath, link: PurePath, opt: str = None) -> int:
+    
+    cmd, env = custom.cmd("qemu", link, None)    
+    if (not cmd):
+        prog = custom.program("qemu")
+        if (prog):
+            cmd = [ prog ]
+        else:
+            raise RuntimeError("qemu not found")
+    
+    if (opt):
+        start = dir.joinpath(f"qemu-{opt}.config")
+    else:
+        start = dir.joinpath("qemu.config")
+    
+    if (not start.exists()):
+        return 404;
+    
+    # TODO: port qemu.sh in python and use it here
+    cmd = [ "qemu.sh" ];
+    cmd.append(start.as_posix())
+
+    return run(cmd, cwd=dir, env=env).returncode
+
 def start_sh(start: PurePath) -> int:
     
     cmd, env = custom.cmd("start_sh", start, None)
index 2af010fd81148c82f30a9a02b789fc424f120fa6..d77c3f31ae499d1c4b82c0d8ed1b9e79d3a7de8a 100644 (file)
@@ -39,6 +39,11 @@ def cmd(prog:str, t:PurePath, lnk:PurePath, pre:PurePath=None) -> (list, dict):
                 + "-e WINEPREFIX='" + pre.as_posix().replace("'", "\\'") + "'"
                 + " -v '" + lnk_path + ":" + lnk_path + "'"
             )
+    elif (prog == "qemu"):
+        if (program("app.sh")):
+            cmd = [ 
+                program("app.sh"),"--wait", "qemu"
+            ]
     elif (prog == "start_sh"):
         if (program("launch.sh")):
             cmd = [ 
index 20b8a0ee35a171c5a1a3b794f4f3e61f02128b0a..7e69309f084470508328049fb19f51e97e7cd7e9 100644 (file)
@@ -18,7 +18,7 @@ class Support:
 
     def _running(self, game: Game, opt: str = None):
         if (opt):
-            print("Running", game.name, "(option: " + opt + ")")
+            print("Running", game.name, "(" + game.opts.get(opt)  +")")
         else:
             print("Running", game.name)
         
diff --git a/gamiki/support/support_qemu.py b/gamiki/support/support_qemu.py
new file mode 100644 (file)
index 0000000..28bfb98
--- /dev/null
@@ -0,0 +1,19 @@
+from gamiki                  import Game
+from gamiki.support          import Support
+from gamiki.support.commands import qemu
+
+class SupportQemu(Support):
+    """Supports games run under VMs in qEmu."""
+            
+    def supports(self, game: Game):
+        return (
+                game.dir.joinpath("qemu.config").exists()
+                and game.dir.joinpath("disk").exists()
+        )
+    
+    def _start(self, game: Game, opt: str = None):
+        self._running(game, opt)
+        rep = qemu(game.dir.resolve(), game.library.dir.resolve(), opt)
+        if (rep != 0):
+            self._error(game, rep)
+