Automatically add extra Steam libraries

This commit is contained in:
kramo
2023-05-20 18:45:18 +02:00
parent caaeade600
commit 48685d2591
6 changed files with 7 additions and 95 deletions

View File

@@ -85,29 +85,6 @@ template $PreferencesWindow : Adw.PreferencesWindow {
valign: center; valign: center;
} }
} }
Adw.ActionRow {
title: _("Extra Steam Libraries");
subtitle: _("Select other directories where you have Steam games installed");
Revealer steam_clear_button_revealer {
transition-type: slide_left;
Button steam_clear_button {
label: _("Clear");
valign: center;
halign: end;
styles [
"destructive-action",
]
}
}
Button steam_extra_file_chooser_button {
icon-name: "folder-new-symbolic";
valign: center;
}
}
} }
Adw.ExpanderRow lutris_expander_row { Adw.ExpanderRow lutris_expander_row {

View File

@@ -16,12 +16,6 @@
<key name="steam-location" type="s"> <key name="steam-location" type="s">
<default>"~/.steam/"</default> <default>"~/.steam/"</default>
</key> </key>
<key name="steam-extra-dirs" type="as">
<default>[]</default>
</key>
<key name="steam-extra-dirs-hint" type="b">
<default>true</default>
</key>
<key name="lutris" type="b"> <key name="lutris" type="b">
<default>true</default> <default>true</default>
</key> </key>

View File

@@ -11,12 +11,7 @@
"--device=dri", "--device=dri",
"--socket=wayland", "--socket=wayland",
"--talk-name=org.freedesktop.Flatpak", "--talk-name=org.freedesktop.Flatpak",
"--filesystem=~/.steam/steam/:ro", "--filesystem=host:ro",
"--filesystem=xdg-data/lutris/:ro",
"--filesystem=xdg-cache/lutris/:ro",
"--filesystem=xdg-config/heroic/:ro",
"--filesystem=xdg-data/bottles/:ro",
"--filesystem=xdg-config/itch/:ro",
"--filesystem=~/.var/app/com.valvesoftware.Steam/data/Steam/:ro", "--filesystem=~/.var/app/com.valvesoftware.Steam/data/Steam/:ro",
"--filesystem=~/.var/app/net.lutris.Lutris/:ro", "--filesystem=~/.var/app/net.lutris.Lutris/:ro",
"--filesystem=~/.var/app/com.heroicgameslauncher.hgl/config/heroic/:ro", "--filesystem=~/.var/app/com.heroicgameslauncher.hgl/config/heroic/:ro",

View File

@@ -155,10 +155,13 @@ def steam_importer(win):
appmanifests = [] appmanifests = []
if not (lib_file := steam_dir / "steamapps" / "libraryfolders.vdf").is_file():
return
libraryfolders = lib_file.open().read()
steam_dirs = [ steam_dirs = [
Path(directory) for directory in win.schema.get_strv("steam-extra-dirs") Path(path) for path in re.findall('"path"\t\t"(.*)"\n', libraryfolders)
] ]
steam_dirs.append(steam_dir)
for directory in steam_dirs: for directory in steam_dirs:
if not (directory / "steamapps").exists(): if not (directory / "steamapps").exists():
@@ -173,4 +176,4 @@ def steam_importer(win):
importer.total_queue += len(appmanifests) importer.total_queue += len(appmanifests)
importer.queue += len(appmanifests) importer.queue += len(appmanifests)
get_games_async(win, appmanifests, directory, importer) get_games_async(win, appmanifests, steam_dir, importer)

View File

@@ -48,9 +48,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
steam_expander_row = Gtk.Template.Child() steam_expander_row = Gtk.Template.Child()
steam_file_chooser_button = Gtk.Template.Child() steam_file_chooser_button = Gtk.Template.Child()
steam_extra_file_chooser_button = Gtk.Template.Child()
steam_clear_button_revealer = Gtk.Template.Child()
steam_clear_button = Gtk.Template.Child()
lutris_expander_row = Gtk.Template.Child() lutris_expander_row = Gtk.Template.Child()
lutris_file_chooser_button = Gtk.Template.Child() lutris_file_chooser_button = Gtk.Template.Child()
@@ -109,34 +106,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
# Steam # Steam
self.create_preferences(self, "steam", "Steam") self.create_preferences(self, "steam", "Steam")
def update_revealer():
if self.schema.get_strv("steam-extra-dirs"):
self.steam_clear_button_revealer.set_reveal_child(True)
else:
self.steam_clear_button_revealer.set_reveal_child(False)
def add_steam_dir(_source, result, *_args):
try:
value = self.schema.get_strv("steam-extra-dirs")
value.append(self.file_chooser.select_folder_finish(result).get_path())
self.schema.set_strv("steam-extra-dirs", value)
self.import_changed = True
except GLib.GError:
return
update_revealer()
def clear_steam_dirs(*_args):
self.schema.set_strv("steam-extra-dirs", [])
self.import_changed = True
update_revealer()
update_revealer()
self.steam_extra_file_chooser_button.connect(
"clicked", self.choose_folder, add_steam_dir
)
self.steam_clear_button.connect("clicked", clear_steam_dirs)
# Lutris # Lutris
self.create_preferences(self, "lutris", "Lutris") self.create_preferences(self, "lutris", "Lutris")

View File

@@ -17,8 +17,6 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from pathlib import Path
from gi.repository import Adw, GLib, Gtk from gi.repository import Adw, GLib, Gtk
from .create_dialog import create_dialog from .create_dialog import create_dialog
@@ -123,30 +121,6 @@ class Importer:
_("Preferences"), _("Preferences"),
).connect("response", self.response, "sgdb") ).connect("response", self.response, "sgdb")
self.sgdb_exception = None self.sgdb_exception = None
elif (
self.win.schema.get_boolean("steam")
and self.win.schema.get_boolean("steam-extra-dirs-hint")
and not self.win.schema.get_strv("steam-extra-dirs")
):
steam_library_path = (
Path(self.win.schema.get_string("steam-location"))
/ "steamapps"
/ "libraryfolders.vdf"
)
if (
steam_library_path.exists()
and steam_library_path.read_text("utf-8").count('"path"') > 1
):
self.win.schema.set_boolean("steam-extra-dirs-hint", False)
create_dialog(
self.win,
_("Extra Steam Libraries"),
_(
"Looks like you have multiple Steam libraries. Would you like to add them in preferences?"
),
"open_preferences",
_("Preferences"),
).connect("response", self.response, "import", "steam_expander_row")
def update_progressbar(self): def update_progressbar(self):
try: try: