From 6a8f8669439624663304112e3089aa8328fc93b2 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 16 Mar 2025 02:03:41 -0400 Subject: [PATCH] Add optional doom_flags.txt so you can add flags for all games. This is experimental and may be removed. --- Toby Doom Launcher.py | 63 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/Toby Doom Launcher.py b/Toby Doom Launcher.py index 5301882..60f39c2 100755 --- a/Toby Doom Launcher.py +++ b/Toby Doom Launcher.py @@ -1678,24 +1678,65 @@ class DoomLauncher(QMainWindow): process.wait() # Wait for the game to finish QApplication.instance().quit() # Quit the application + def get_flags_from_file(self) -> List[str]: + """Read additional launch flags from doom_flags.txt""" + flags = [] + + # Check multiple possible locations for the flags file + flag_file_locations = [ + Path.cwd() / "doom_flags.txt", # Current directory + self.gamePath / "doom_flags.txt", # Game path + Path.home() / "doom_flags.txt", # User's home directory + Path.home() / ".local/doom/doom_flags.txt", # ~/.local/doom directory + Path.home() / ".local/share/doom/doom_flags.txt" # ~/.local/share/doom directory + ] + + for flag_file in flag_file_locations: + if flag_file.exists(): + try: + with open(flag_file, 'r') as f: + # Read all lines, strip whitespace, and filter out empty lines + lines = [line.strip() for line in f.readlines()] + lines = [line for line in lines if line and not line.startswith('#')] + + # Split each line by whitespace to get individual flags + for line in lines: + flags.extend(line.split()) + + print(f"Loaded {len(flags)} flags from {flag_file}") + break # Use the first file found + except Exception as e: + print(f"Error reading flags file {flag_file}: {e}", file=sys.stderr) + + return flags + def launch_game(self, gameFiles: List[str], gameFlags: List[str] = None): """Launch game with speech processing""" if not gameFiles: return - + gzdoomPath = self.find_gzdoom() if not gzdoomPath: QMessageBox.critical(self, "Error", "GZDoom executable not found") return - + # Get selected IWAD iwadIndex = self.iwadCombo.currentIndex() if iwadIndex < 0: QMessageBox.critical(self, "Error", "Please select an IWAD first") return - + iwadPath = self.iwadCombo.itemData(iwadIndex) + # Initialize gameFlags if None + if gameFlags is None: + gameFlags = [] + + # Get additional flags from doom_flags.txt + additionalFlags = self.get_flags_from_file() + if additionalFlags: + gameFlags.extend(additionalFlags) + try: if platform.system() == "Windows": configFile = Path.cwd() / 'TobyConfig.ini' @@ -1704,12 +1745,12 @@ class DoomLauncher(QMainWindow): "-iwad", iwadPath, "-file"] + gameFiles if gameFlags: cmdLine.extend(gameFlags) - + # Use CREATE_NO_WINDOW flag to prevent console window startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE - + process = subprocess.Popen( cmdLine, cwd=str(self.gamePath), @@ -1720,14 +1761,14 @@ class DoomLauncher(QMainWindow): env=dict(os.environ, PYTHONUNBUFFERED="1"), startupinfo=startupinfo ) - + else: # For Linux/Mac, use stdbuf to unbuffer output cmdLine = ["stdbuf", "-oL", gzdoomPath, "-stdout", "-iwad", iwadPath, "-file"] + gameFiles if gameFlags: cmdLine.extend(gameFlags) - + process = subprocess.Popen( cmdLine, cwd=str(self.gamePath), @@ -1737,7 +1778,7 @@ class DoomLauncher(QMainWindow): universal_newlines=True, # This handles text encoding env=dict(os.environ, PYTHONUNBUFFERED="1") ) - + # Start speech processing thread speechThread = threading.Thread( target=self.speechHandler.speak_thread, @@ -1745,7 +1786,7 @@ class DoomLauncher(QMainWindow): daemon=True ) speechThread.start() - + # Start process monitor thread monitorThread = threading.Thread( target=self.monitor_game_process, @@ -1753,10 +1794,10 @@ class DoomLauncher(QMainWindow): daemon=True ) monitorThread.start() - + # Hide the window self.hide() - + except Exception as e: QMessageBox.critical(self, "Error", f"Failed to launch game: {e}")