mirror of
https://github.com/lutris/lutris
synced 2024-09-15 22:09:55 +00:00
Use Game class to save game change + use InvalidRunner where appropriate
This commit is contained in:
parent
a8defffbf7
commit
0d01ea160d
|
@ -8,7 +8,7 @@ from gi.repository import GLib
|
|||
|
||||
from lutris import pga
|
||||
from lutris import settings
|
||||
from lutris.runners import import_runner
|
||||
from lutris.runners import import_runner, InvalidRunner
|
||||
from lutris.util.log import logger
|
||||
from lutris.util import audio, display, system
|
||||
from lutris.config import LutrisConfig
|
||||
|
@ -72,13 +72,17 @@ class Game(object):
|
|||
def load_config(self):
|
||||
"""Load the game's configuration."""
|
||||
self.config = LutrisConfig(game=self.slug)
|
||||
if self.is_installed:
|
||||
if not self.is_installed:
|
||||
return
|
||||
if not self.runner_name:
|
||||
logger.error('Incomplete data for %s', self.slug)
|
||||
return
|
||||
try:
|
||||
runner_class = import_runner(self.runner_name)
|
||||
if runner_class:
|
||||
self.runner = runner_class(self.config)
|
||||
else:
|
||||
logger.error("Unable to import runner %s for %s",
|
||||
self.runner_name, self.slug)
|
||||
except InvalidRunner:
|
||||
logger.error("Unable to import runner %s for %s",
|
||||
self.runner_name, self.slug)
|
||||
self.runner = runner_class(self.config)
|
||||
|
||||
def remove(self, from_library=False, from_disk=False):
|
||||
if from_disk:
|
||||
|
@ -89,6 +93,16 @@ class Game(object):
|
|||
else:
|
||||
pga.set_uninstalled(self.slug)
|
||||
|
||||
def save(self):
|
||||
self.config.save()
|
||||
pga.add_or_update(
|
||||
name=self.name,
|
||||
runner=self.runner_name,
|
||||
slug=self.slug,
|
||||
directory=self.directory,
|
||||
installed=self.is_installed
|
||||
)
|
||||
|
||||
def prelaunch(self):
|
||||
"""Verify that the current game can be launched."""
|
||||
if not self.runner.is_installed():
|
||||
|
|
|
@ -4,7 +4,6 @@ from gi.repository import Gtk, Pango
|
|||
from lutris.util.log import logger
|
||||
from lutris.config import LutrisConfig
|
||||
from lutris.game import Game
|
||||
from lutris import pga
|
||||
import lutris.runners
|
||||
from lutris.gui.dialogs import ErrorDialog
|
||||
from lutris.gui.widgets import VBox, Dialog
|
||||
|
@ -184,18 +183,30 @@ class GameDialogCommon(object):
|
|||
if not self.is_valid():
|
||||
return False
|
||||
name = self.name_entry.get_text()
|
||||
|
||||
# Do not modify slug
|
||||
if not self.slug:
|
||||
self.slug = slugify(name)
|
||||
|
||||
if not self.game:
|
||||
self.game = Game(self.slug)
|
||||
self.game.config = self.lutris_config
|
||||
|
||||
if not self.lutris_config.game:
|
||||
self.lutris_config.game = slugify(name)
|
||||
self.lutris_config.game = self.slug
|
||||
self.lutris_config.save()
|
||||
self.slug = self.lutris_config.game
|
||||
|
||||
runner_class = lutris.runners.import_runner(self.runner_name)
|
||||
runner = runner_class(self.lutris_config)
|
||||
pga.add_or_update(name, self.runner_name, slug=self.slug,
|
||||
directory=runner.game_path,
|
||||
installed=1)
|
||||
self.game.name = name
|
||||
self.game.slug = self.slug
|
||||
self.game.runner_name = self.runner_name
|
||||
self.game.directory = runner.game_path
|
||||
self.game.is_installed = True
|
||||
self.game.save()
|
||||
self.destroy()
|
||||
logger.debug("Saved %s", name)
|
||||
return True
|
||||
self.saved = True
|
||||
|
||||
|
||||
class AddGameDialog(Dialog, GameDialogCommon):
|
||||
|
@ -206,7 +217,7 @@ class AddGameDialog(Dialog, GameDialogCommon):
|
|||
self.parent_window = parent
|
||||
self.lutris_config = LutrisConfig()
|
||||
self.game = game
|
||||
self.installed = False
|
||||
self.saved = False
|
||||
|
||||
self.set_size_request(-1, 500)
|
||||
if game:
|
||||
|
@ -222,11 +233,6 @@ class AddGameDialog(Dialog, GameDialogCommon):
|
|||
self.build_action_area("Add", self.on_save)
|
||||
self.show_all()
|
||||
|
||||
def on_save(self, _button):
|
||||
name = self.name_entry.get_text()
|
||||
self.lutris_config.game = self.slug if self.slug else slugify(name)
|
||||
self.installed = super(AddGameDialog, self).on_save(_button)
|
||||
|
||||
|
||||
class EditGameConfigDialog(Dialog, GameDialogCommon):
|
||||
"""Game config edit dialog."""
|
||||
|
@ -239,6 +245,7 @@ class EditGameConfigDialog(Dialog, GameDialogCommon):
|
|||
self.lutris_config = game.config
|
||||
self.slug = game.slug
|
||||
self.runner_name = game.runner_name
|
||||
self.saved = False
|
||||
|
||||
self.set_size_request(500, 550)
|
||||
|
||||
|
|
|
@ -429,14 +429,14 @@ class LutrisWindow(object):
|
|||
game = Game(self.view.selected_game)
|
||||
add_game_dialog = AddGameDialog(self, game)
|
||||
add_game_dialog.run()
|
||||
if add_game_dialog.installed:
|
||||
if add_game_dialog.saved:
|
||||
self.view.set_installed(game)
|
||||
|
||||
def add_game(self, _widget, _data=None):
|
||||
"""Add a new game."""
|
||||
add_game_dialog = AddGameDialog(self)
|
||||
add_game_dialog.run()
|
||||
if add_game_dialog.runner_name and add_game_dialog.slug:
|
||||
if add_game_dialog.saved:
|
||||
self.add_game_to_view(add_game_dialog.slug)
|
||||
|
||||
def add_game_to_view(self, slug):
|
||||
|
@ -480,7 +480,7 @@ class LutrisWindow(object):
|
|||
game_slug = game.slug
|
||||
if game.is_installed:
|
||||
dialog = EditGameConfigDialog(self, game)
|
||||
if dialog.slug:
|
||||
if dialog.saved:
|
||||
game = Game(dialog.slug)
|
||||
self.view.remove_game(game_slug)
|
||||
self.view.add_game(game)
|
||||
|
|
|
@ -3,6 +3,7 @@ from lutris.gui.dialogs import GtkBuilderDialog
|
|||
from lutris.game import Game
|
||||
from lutris.util.system import is_removeable
|
||||
from lutris.gui.dialogs import QuestionDialog
|
||||
from lutris.runners import InvalidRunner
|
||||
|
||||
|
||||
class UninstallGameDialog(GtkBuilderDialog):
|
||||
|
@ -45,7 +46,11 @@ class UninstallGameDialog(GtkBuilderDialog):
|
|||
default_path = runner.default_path
|
||||
except AttributeError:
|
||||
default_path = "/"
|
||||
if not is_removeable(runner.game_path, excludes=[default_path]):
|
||||
try:
|
||||
game_path = runner.game_path
|
||||
except AttributeError:
|
||||
game_path = '/'
|
||||
if not is_removeable(game_path, excludes=[default_path]):
|
||||
remove_contents_button.set_sensitive(False)
|
||||
|
||||
path = self.game.directory or 'disk'
|
||||
|
|
|
@ -21,7 +21,9 @@ from lutris.game import Game
|
|||
from lutris.config import LutrisConfig
|
||||
from lutris.gui.config_dialogs import AddGameDialog
|
||||
from lutris.gui.dialogs import ErrorDialog, NoInstallerDialog
|
||||
from lutris.runners import wine, winesteam, steam, import_task, import_runner
|
||||
from lutris.runners import (
|
||||
wine, winesteam, steam, import_task, import_runner, InvalidRunner
|
||||
)
|
||||
|
||||
|
||||
class ScriptingError(Exception):
|
||||
|
@ -450,15 +452,15 @@ class ScriptInterpreter(object):
|
|||
def _get_file(self, fileid):
|
||||
return self.game_files.get(fileid)
|
||||
|
||||
def _check_required_params(self, params, script_data, command_name):
|
||||
def _check_required_params(self, params, command_data, command_name):
|
||||
"""Verify presence of a list of parameters required by a command."""
|
||||
if type(params) is str:
|
||||
params = [params]
|
||||
for param in params:
|
||||
if param not in script_data:
|
||||
if param not in command_data:
|
||||
raise ScriptingError('The "%s" parameter is mandatory for '
|
||||
'the %s command' % (param, command_name),
|
||||
script_data)
|
||||
command_data)
|
||||
|
||||
def check_md5(self, data):
|
||||
self._check_required_params(['file', 'value'], data, 'check_md5')
|
||||
|
@ -662,7 +664,12 @@ class ScriptInterpreter(object):
|
|||
runner_name, task_name = task_name.split('.')
|
||||
else:
|
||||
runner_name = self.script["runner"]
|
||||
runner = import_runner(runner_name)()
|
||||
try:
|
||||
runner_class = import_runner(runner_name)
|
||||
except InvalidRunner:
|
||||
raise ScriptingError('Invalid runner provided %s', runner_name)
|
||||
|
||||
runner = runner_class()
|
||||
|
||||
# Check/install Wine runner at version specified in the script
|
||||
wine_version = None
|
||||
|
|
Loading…
Reference in a new issue