mirror of
https://github.com/lutris/lutris
synced 2024-09-05 23:46:21 +00:00
Retire "PATH_NOT_SET", "NOT_EXECUTABLE" and "NO_BIOS" in error codes in favor of exceptions.
Only NO_BIOS gets its own exception class, as its hte only one raised in more than one place. This way we can avoid repeating the message. elif error == "NO_BIOS": message_text = _("A bios file is required to run this game")
This commit is contained in:
parent
284cb0282d
commit
d5de4465f4
|
@ -21,6 +21,13 @@ class GameConfigError(MisconfigurationError):
|
|||
running properly."""
|
||||
|
||||
|
||||
class MissingBiosError(GameConfigError):
|
||||
"""Throw this error when the game requires a BIOS, but none is configured."""
|
||||
|
||||
def __init__(self, message=None, *args, **kwarg):
|
||||
super().__init__(message or _("A bios file is required to run this game"), *args, **kwarg)
|
||||
|
||||
|
||||
class AuthenticationError(LutrisError):
|
||||
"""Raised when authentication to a service fails"""
|
||||
|
||||
|
|
|
@ -275,19 +275,12 @@ class Game(GObject.Object):
|
|||
error = gameplay_info["error"]
|
||||
if error == "CUSTOM":
|
||||
message_text = gameplay_info["text"]
|
||||
elif error == "NO_BIOS":
|
||||
message_text = _("A bios file is required to run this game")
|
||||
elif error == "FILE_NOT_FOUND":
|
||||
filename = gameplay_info["file"]
|
||||
if filename:
|
||||
message_text = _("The file {} could not be found").format(filename)
|
||||
else:
|
||||
message_text = _("This game has no executable set. The install process didn't finish properly.")
|
||||
elif error == "NOT_EXECUTABLE":
|
||||
file = gameplay_info["file"]
|
||||
message_text = _("The file %s is not executable") % file
|
||||
elif error == "PATH_NOT_SET":
|
||||
message_text = _("The path '%s' is not set. please set it in the options.") % gameplay_info["path"]
|
||||
else:
|
||||
message_text = _("Unhandled error: %s") % gameplay_info["error"]
|
||||
return GameConfigError(message_text)
|
||||
|
|
|
@ -3,6 +3,7 @@ import os.path
|
|||
from gettext import gettext as _
|
||||
|
||||
from lutris.config import LutrisConfig
|
||||
from lutris.exceptions import MissingBiosError
|
||||
from lutris.runners.runner import Runner
|
||||
from lutris.util import display, extract, system
|
||||
|
||||
|
@ -132,7 +133,7 @@ class atari800(Runner):
|
|||
|
||||
bios_path = self.runner_config.get("bios_path")
|
||||
if not system.path_exists(bios_path):
|
||||
return {"error": "NO_BIOS"}
|
||||
raise MissingBiosError()
|
||||
good_bios = self.find_good_bioses(bios_path)
|
||||
for bios, filename in good_bios.items():
|
||||
arguments.append("-%s" % bios)
|
||||
|
|
|
@ -5,6 +5,7 @@ from gettext import gettext as _
|
|||
|
||||
# Lutris Modules
|
||||
from lutris.config import LutrisConfig
|
||||
from lutris.exceptions import MissingBiosError
|
||||
from lutris.runners.runner import Runner
|
||||
from lutris.util import system
|
||||
|
||||
|
@ -175,7 +176,7 @@ class hatari(Runner):
|
|||
params.append("--tos")
|
||||
params.append(self.runner_config["bios_file"])
|
||||
else:
|
||||
return {"error": "NO_BIOS"}
|
||||
raise MissingBiosError()
|
||||
diska = self.game_config.get("disk-a")
|
||||
if not system.path_exists(diska):
|
||||
return {"error": "FILE_NOT_FOUND", "file": diska}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
from gettext import gettext as _
|
||||
|
||||
from lutris.exceptions import MissingBiosError
|
||||
# Lutris Modules
|
||||
from lutris.runners.runner import Runner
|
||||
from lutris.util import system
|
||||
|
@ -77,7 +78,7 @@ class jzintv(Runner):
|
|||
arguments.append("--execimg=%s/exec.bin" % bios_path)
|
||||
arguments.append("--gromimg=%s/grom.bin" % bios_path)
|
||||
else:
|
||||
return {"error": "NO_BIOS"}
|
||||
raise MissingBiosError()
|
||||
rom_path = self.game_config.get("main_file") or ""
|
||||
if not system.path_exists(rom_path):
|
||||
return {"error": "FILE_NOT_FOUND", "file": rom_path}
|
||||
|
|
|
@ -156,16 +156,14 @@ class linux(Runner):
|
|||
"""Run native game."""
|
||||
launch_info = {}
|
||||
|
||||
if not self.game_exe or not system.path_exists(self.game_exe):
|
||||
return {"error": "FILE_NOT_FOUND", "file": self.game_exe}
|
||||
exe = self.game_exe
|
||||
if not exe or not system.path_exists(exe):
|
||||
return {"error": "FILE_NOT_FOUND", "file": exe}
|
||||
|
||||
# Quit if the file is not executable
|
||||
mode = os.stat(self.game_exe).st_mode
|
||||
mode = os.stat(exe).st_mode
|
||||
if not mode & stat.S_IXUSR:
|
||||
return {"error": "NOT_EXECUTABLE", "file": self.game_exe}
|
||||
|
||||
if not system.path_exists(self.game_exe):
|
||||
return {"error": "FILE_NOT_FOUND", "file": self.game_exe}
|
||||
raise GameConfigError(_("The file %s is not executable") % exe)
|
||||
|
||||
ld_preload = self.game_config.get("ld_preload")
|
||||
if ld_preload:
|
||||
|
@ -175,7 +173,7 @@ class linux(Runner):
|
|||
if ld_library_path:
|
||||
launch_info["ld_library_path"] = os.path.expanduser(ld_library_path)
|
||||
|
||||
command = [self.get_relative_exe(self.game_exe, self.working_dir)]
|
||||
command = [self.get_relative_exe(exe, self.working_dir)]
|
||||
|
||||
args = self.game_config.get("args") or ""
|
||||
for arg in split_arguments(args):
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
from gettext import gettext as _
|
||||
|
||||
from lutris import runtime, settings
|
||||
from lutris.exceptions import GameConfigError
|
||||
from lutris.runners.runner import Runner
|
||||
from lutris.util import system
|
||||
from lutris.util.jobs import AsyncCall
|
||||
|
@ -328,7 +329,7 @@ class mame(Runner): # pylint: disable=invalid-name
|
|||
rompath = self.runner_config.get("rompath")
|
||||
rom = os.path.basename(self.game_config.get("main_file"))
|
||||
if not rompath:
|
||||
return {'error': 'PATH_NOT_SET', 'path': 'rompath'}
|
||||
raise GameConfigError(_("The path '%s' is not set. please set it in the options.") % 'rompath')
|
||||
command += ["-rompath", rompath, rom]
|
||||
|
||||
if self.game_config.get("autoboot_command"):
|
||||
|
|
Loading…
Reference in a new issue