1
0
Fork 0
mirror of synced 2024-06-09 14:14:41 +12:00

Add logging for Games, error handling

This commit is contained in:
Dummerle 2021-04-22 14:11:12 +02:00
parent a03f38ba39
commit ee467d9398
2 changed files with 17 additions and 1 deletions

View file

@ -1,7 +1,7 @@
import os
from logging import getLogger
from PyQt5.QtCore import pyqtSignal, QProcess, QSettings, Qt
from PyQt5.QtCore import pyqtSignal, QProcess, QSettings, Qt, QByteArray
from PyQt5.QtWidgets import QGroupBox, QMessageBox, QAction
from custom_legendary.core import LegendaryCore
@ -108,12 +108,27 @@ class BaseInstalledWidget(QGroupBox):
if not self.proc:
logger.error("Could not start process")
return 1
self.game_logger = getLogger(self.game.app_name)
self.proc.finished.connect(self.finished)
self.proc.readyReadStandardOutput.connect(self.stdout)
self.proc.readyReadStandardError.connect(self.stderr)
self.proc.start(params[0], params[1:])
self.launch_signal.emit(self.igame.app_name)
self.game_running = True
self.data = QByteArray()
return 0
def stdout(self):
data = self.proc.readAllStandardOutput()
stdout = bytes(data).decode("utf-8")
self.game_logger.info(stdout)
def stderr(self):
stderr = bytes(self.proc.readAllStandardError()).decode("utf-8")
self.game_logger.error(stderr)
QMessageBox.warning(self, "Warning", stderr)
def finished(self, exit_code):
logger.info("Game exited with exit code: " + str(exit_code))
self.finish_signal.emit(self.game.app_name)

View file

@ -39,6 +39,7 @@ def launch_game(core, app_name: str, offline: bool = False, skip_version_check:
params, cwd, env = core.get_launch_parameters(app_name=app_name, offline=offline)
process = QProcess()
process.setProcessChannelMode(QProcess.MergedChannels)
process.setWorkingDirectory(cwd)
environment = QProcessEnvironment()
for e in env: