Provide a directory property on the runner

Many places can use this to be more readable, and I've updated some.

Many subclasses of Runner might still benefit.

But the real win is fs-uae. This still installs in 'fs-uae' not the
expected 'fsuae'; overriding directory lets us work around this.

So, now you can uninstall fs-uae.
This commit is contained in:
Daniel Johnson 2022-10-08 09:43:12 -04:00
parent bcc3ea86d0
commit 9b8622c32f
5 changed files with 26 additions and 18 deletions

View file

@ -863,16 +863,15 @@ Also, check that the version specified is in the correct format.
install the runner provided in prepare_runner_cli()
"""
runner_path = os.path.join(settings.RUNNER_DIR, runner_name)
if os.path.isdir(runner_path):
print(f"'{runner_name}' is already installed.")
else:
try:
runner = import_runner(runner_name)
runner().install(version=None, downloader=simple_downloader, callback=None)
try:
runner = import_runner(runner_name)()
if runner.is_installed():
print(f"'{runner_name}' is already installed.")
else:
runner.install(version=None, downloader=simple_downloader, callback=None)
print(f"'{runner_name}' has been installed")
except (InvalidRunner, RunnerInstallationError) as ex:
print(ex.message)
except (InvalidRunner, RunnerInstallationError) as ex:
print(ex.message)
def uninstall_runner_cli(self, runner_name):
"""

View file

@ -5,6 +5,7 @@ from gi.repository import Gtk
from lutris.gui.widgets.download_progress_box import DownloadProgressBox
from lutris.gui.dialogs import ModalDialog
class DownloadDialog(ModalDialog):
"""Dialog showing a download in progress."""

View file

@ -60,6 +60,7 @@ class RunnerInstallDialog(ModelessDialog):
super().__init__(title, parent, 0)
self.add_default_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.runner_name = runner.name
self.runner_directory = runner.directory
self.runner_info = {}
self.installing = {}
self.set_default_size(640, 480)
@ -250,18 +251,17 @@ class RunnerInstallDialog(ModelessDialog):
def get_installed_versions(self):
"""List versions available locally"""
runner_path = os.path.join(settings.RUNNER_DIR, self.runner_name)
if not os.path.exists(runner_path):
if not os.path.exists(self.runner_directory):
return set()
return {
tuple(p.rsplit("-", 1))
for p in os.listdir(runner_path)
for p in os.listdir(self.runner_directory)
if "-" in p
}
def get_runner_path(self, version, arch):
"""Return the local path where the runner is/will be installed"""
return os.path.join(settings.RUNNER_DIR, self.runner_name, "{}-{}".format(version, arch))
return os.path.join(self.runner_directory, "{}-{}".format(version, arch))
def get_dest_path(self, row):
"""Return temporary path where the runners should be downloaded to"""

View file

@ -2,6 +2,7 @@ import os
from collections import defaultdict
from gettext import gettext as _
from lutris import settings
from lutris.runners.runner import Runner
from lutris.util import system
from lutris.util.display import DISPLAY_MANAGER
@ -399,6 +400,10 @@ class fsuae(Runner):
},
]
@property
def directory(self):
return os.path.join(settings.RUNNER_DIR, "fs-uae")
def get_platform(self):
model = self.runner_config.get("model")
if model:

View file

@ -65,6 +65,10 @@ class Runner: # pylint: disable=too-many-public-methods
def name(self):
return self.__class__.__name__
@property
def directory(self):
return os.path.join(settings.RUNNER_DIR, self.name)
@property
def config(self):
if not self._config:
@ -393,7 +397,7 @@ class Runner: # pylint: disable=too-many-public-methods
)
opts = {"downloader": downloader, "callback": callback}
if self.download_url:
opts["dest"] = os.path.join(settings.RUNNER_DIR, self.name)
opts["dest"] = self.directory
return self.download_and_extract(self.download_url, **opts)
runner = self.get_runner_version(version)
if not runner:
@ -404,7 +408,7 @@ class Runner: # pylint: disable=too-many-public-methods
if "wine" in self.name:
opts["merge_single"] = True
opts["dest"] = os.path.join(
settings.RUNNER_DIR, self.name, "{}-{}".format(runner["version"], runner["architecture"])
self.directory, "{}-{}".format(runner["version"], runner["architecture"])
)
if self.name == "libretro" and version:
@ -456,11 +460,10 @@ class Runner: # pylint: disable=too-many-public-methods
system.remove_folder(game_path)
def can_uninstall(self):
runner_path = os.path.join(settings.RUNNER_DIR, self.name)
return os.path.isdir(runner_path)
return os.path.isdir(self.directory)
def uninstall(self):
runner_path = os.path.join(settings.RUNNER_DIR, self.name)
runner_path = self.directory
if os.path.isdir(runner_path):
system.remove_folder(runner_path)