From 2338d25b39047acabd1a4a994432a99689545d8e Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Wed, 15 Jul 2020 17:19:16 +0200 Subject: [PATCH] expand rom auto_start to be customizable --- MultiClient.py | 13 +++++++++---- MultiMystery.py | 7 +++---- host.yaml | 4 ++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/MultiClient.py b/MultiClient.py index 00e1913d..dfc8c1bd 100644 --- a/MultiClient.py +++ b/MultiClient.py @@ -11,6 +11,8 @@ import multiprocessing import socket import sys import typing +import os +import subprocess from random import randrange @@ -378,7 +380,6 @@ SNES_ATTACHED = 3 def launch_qusb2snes(ctx: Context): qusb2snes_path = Utils.get_options()["general_options"]["qusb2snes"] - import os if not os.path.isfile(qusb2snes_path): qusb2snes_path = Utils.local_path(qusb2snes_path) @@ -1229,8 +1230,13 @@ async def game_watcher(ctx : Context): async def run_game(romfile): - import webbrowser - webbrowser.open(romfile) + auto_start = Utils.get_options()["general_options"].get("rom_start", True) + if auto_start is True: + import webbrowser + webbrowser.open(romfile) + elif os.path.isfile(auto_start): + subprocess.Popen([auto_start, romfile], + stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) async def websocket_server(websocket: websockets.WebSocketServerProtocol, path, ctx: Context): @@ -1320,7 +1326,6 @@ async def main(): adjustedromfile, adjusted = Utils.get_adjuster_settings(romfile) if adjusted: try: - import os os.replace(adjustedromfile, romfile) adjustedromfile = romfile except Exception as e: diff --git a/MultiMystery.py b/MultiMystery.py index 7af6625e..84b4d5a0 100644 --- a/MultiMystery.py +++ b/MultiMystery.py @@ -125,11 +125,10 @@ if __name__ == "__main__": if player_name: for file in os.listdir(output_path): if player_name in file: - import webbrowser + import MultiClient + import asyncio - romfilename = os.path.join(output_path, file) - print(f"Launching ROM file {romfilename}") - webbrowser.open(romfilename) + asyncio.run(MultiClient.run_game(os.path.join(output_path, file))) break if any((zip_roms, zip_multidata, zip_spoiler, zip_diffs)): diff --git a/host.yaml b/host.yaml index 748cdeaa..deae3197 100644 --- a/host.yaml +++ b/host.yaml @@ -3,6 +3,10 @@ general_options: rom_file: "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc" # set this to your (Q)Usb2Snes location if you want the MultiClient to attempt an auto start, does nothing if not found qusb2snes: "QUsb2Snes\\QUsb2Snes.exe" + # Set this to false to never autostart a rom (such as after patching) + # true for operating system default program + # alternatively, a path to a program to open the .sfc file with + rom_start: true #options for MultiServer #null means nothing, for the server this means to default the value #these overwrite command line arguments!