mirror of
https://github.com/lutris/lutris
synced 2024-10-14 03:32:52 +00:00
Add export feature
This commit is contained in:
parent
4d8735a884
commit
531e261f8f
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -16,6 +16,8 @@ lutris (0.5.10) impish; urgency=medium
|
|||
* Add option to enable BattleEye anti-cheat support
|
||||
* Default to Retroarch cores in ~/.config/retroarch/cores if available
|
||||
* Add support for downloading patches and DLC for GOG games
|
||||
* Add --export command line flag to export a game (requires --dest for
|
||||
the destination path)
|
||||
* Enable F-Sync by default
|
||||
|
||||
-- Mathieu Comandon <strider@strycore.com> Fri, 04 Feb 2022 19:14:41 -0800
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
"""Directory management for runners"""
|
||||
|
||||
|
||||
class RunnerDirectory:
|
||||
|
||||
"""Class to reference and manipulate directories used by folders"""
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def __str__(self):
|
||||
return self.path
|
||||
|
||||
|
||||
# That's it for now. There's literally no code at all. Still figuring things
|
||||
# out here.
|
|
@ -1,6 +1,7 @@
|
|||
"""Module that actually runs the games."""
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
|
@ -787,3 +788,36 @@ class Game(GObject.Object):
|
|||
old_location, new_location, ex
|
||||
)
|
||||
return target_directory
|
||||
|
||||
|
||||
|
||||
def export_game(slug, dest_dir):
|
||||
# List of runner where we know for sure that 1 folder = 1 game.
|
||||
# For runners that handle ROMs, we have to handle this more finely.
|
||||
# There is likely more than one game in a ROM folder but a ROM
|
||||
# might have several files (like a bin/cue, or a multi-disk game)
|
||||
exportable_runners = [
|
||||
"linux",
|
||||
"wine",
|
||||
"dosbox",
|
||||
"scummvm",
|
||||
]
|
||||
|
||||
db_game = games_db.get_game_by_field(slug, "slug")
|
||||
if db_game["runner"] not in exportable_runners:
|
||||
raise RuntimeError("Game %s can't be exported." % db_game["name"])
|
||||
if not db_game["directory"]:
|
||||
raise RuntimeError("No game directory set. Could we guess it?")
|
||||
|
||||
game = Game(db_game["id"])
|
||||
db_game["config"] = game.config.game_level
|
||||
game_path = db_game["directory"]
|
||||
config_path = os.path.join(db_game["directory"], "%s.lutris" % slug)
|
||||
with open(config_path, "w", encoding="utf-8") as config_file:
|
||||
json.dump(db_game, config_file, indent=2)
|
||||
archive_path = os.path.join(dest_dir, "%s.7z" % slug)
|
||||
_7zip_path = os.path.join(settings.RUNTIME_DIR, "p7zip/7z")
|
||||
command = [_7zip_path, "a", archive_path, game_path]
|
||||
return_code = subprocess.call(command)
|
||||
if return_code != 0:
|
||||
print("Creating of archive in %s failed with return code %s" % (archive_path, return_code))
|
||||
|
|
|
@ -37,7 +37,7 @@ from lutris import settings
|
|||
from lutris.api import parse_installer_url, get_runners
|
||||
from lutris.command import exec_command
|
||||
from lutris.database import games as games_db
|
||||
from lutris.game import Game
|
||||
from lutris.game import Game, export_game
|
||||
from lutris.installer import get_installers
|
||||
from lutris.gui.dialogs.download import simple_downloader
|
||||
from lutris.gui.dialogs import ErrorDialog, InstallOrPlayDialog, LutrisInitDialog
|
||||
|
@ -211,6 +211,22 @@ class Application(Gtk.Application):
|
|||
_("Uninstall a Runner"),
|
||||
None,
|
||||
)
|
||||
self.add_main_option(
|
||||
"export",
|
||||
ord("e"),
|
||||
GLib.OptionFlags.NONE,
|
||||
GLib.OptionArg.STRING,
|
||||
_("Export a game"),
|
||||
None,
|
||||
)
|
||||
self.add_main_option(
|
||||
"dest",
|
||||
ord("d"),
|
||||
GLib.OptionFlags.NONE,
|
||||
GLib.OptionArg.STRING,
|
||||
_("Destination path for export"),
|
||||
None,
|
||||
)
|
||||
self.add_main_option(
|
||||
"json",
|
||||
ord("j"),
|
||||
|
@ -383,6 +399,12 @@ class Application(Gtk.Application):
|
|||
init_lutris()
|
||||
migrate()
|
||||
run_all_checks()
|
||||
|
||||
if options.contains("dest"):
|
||||
dest_dir = options.lookup_value("dest").get_string()
|
||||
else:
|
||||
dest_dir = None
|
||||
|
||||
# List game
|
||||
if options.contains("list-games"):
|
||||
game_list = games_db.get_games()
|
||||
|
@ -426,6 +448,14 @@ class Application(Gtk.Application):
|
|||
self.uninstall_runner(runner)
|
||||
return 0
|
||||
|
||||
if options.contains("export"):
|
||||
slug = options.lookup_value("export").get_string()
|
||||
if not dest_dir:
|
||||
print("No destination dir given")
|
||||
else:
|
||||
self.export(slug, dest_dir)
|
||||
return 0
|
||||
|
||||
# Execute command in Lutris context
|
||||
if options.contains("exec"):
|
||||
command = options.lookup_value("exec").get_string()
|
||||
|
@ -813,7 +843,7 @@ Also, check that the version specified is in the correct format.
|
|||
runner().install(version=None, downloader=simple_downloader, callback=None)
|
||||
print(f"'{runner_name}' has been installed")
|
||||
except (InvalidRunner, RunnerInstallationError) as ex:
|
||||
ErrorDialog(ex.message)
|
||||
print(ex.message)
|
||||
|
||||
def uninstall_runner_cli(self, runner_name):
|
||||
"""
|
||||
|
@ -835,6 +865,9 @@ Also, check that the version specified is in the correct format.
|
|||
else:
|
||||
print(f"Runner '{runner_name}' cannot be uninstalled.")
|
||||
|
||||
def export(self, slug, dest_dir):
|
||||
export_game(slug, dest_dir)
|
||||
|
||||
def do_shutdown(self): # pylint: disable=arguments-differ
|
||||
logger.info("Shutting down Lutris")
|
||||
if self.window:
|
||||
|
|
|
@ -86,7 +86,7 @@ class StyleManager(GObject.Object):
|
|||
self.color_scheme = self._read_value(value)
|
||||
else:
|
||||
raise Exception("Could not read color-scheme")
|
||||
except Exception as err:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _on_settings_changed(self, _proxy, _sender_name, signal_name, params):
|
||||
|
|
Loading…
Reference in a new issue