Add support for multiple Steam library directories

This commit is contained in:
kramo
2023-03-21 15:40:21 +01:00
parent a7a1573569
commit 86dae1f972
4 changed files with 68 additions and 5 deletions

View File

@@ -30,6 +30,30 @@ template PreferencesWindow : Adw.PreferencesWindow {
valign: center;
}
}
Adw.ActionRow {
title: _("Extra Steam Libraries");
subtitle: _("Select other directories where you have Steam games installed");
Revealer steam_clear_button_revealer {
reveal-child: false;
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.PreferencesGroup heroic_group {

View File

@@ -15,6 +15,9 @@
</key>
<key name="steam-location" type="s">
<default>"~/.steam/"</default>
</key>
<key name="steam-extra-dirs" type="as">
<default>[]</default>
</key>
<key name="heroic-location" type="s">
<default>"~/.var/app/com.heroicgameslauncher.hgl/config/heroic/"</default>

View File

@@ -35,6 +35,9 @@ class PreferencesWindow(Adw.PreferencesWindow):
import_sideload_games_switch = Gtk.Template.Child()
steam_file_chooser_button = Gtk.Template.Child()
steam_extra_file_chooser_button = Gtk.Template.Child()
steam_clear_button = Gtk.Template.Child()
steam_clear_button_revealer = Gtk.Template.Child()
heroic_file_chooser_button = Gtk.Template.Child()
bottles_file_chooser_button = Gtk.Template.Child()
@@ -70,6 +73,12 @@ class PreferencesWindow(Adw.PreferencesWindow):
filechooser = Gtk.FileDialog()
def update_revealer():
if 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 set_steam_dir(_source, result, _unused):
try:
schema.set_string(
@@ -79,6 +88,19 @@ class PreferencesWindow(Adw.PreferencesWindow):
except GLib.GError:
pass
def add_steam_dir(_source, result, _unused):
try:
value = schema.get_strv("steam-extra-dirs")
value.append(filechooser.select_folder_finish(result).get_path())
schema.set_strv("steam-extra-dirs", value)
except GLib.GError:
pass
update_revealer()
def clear_steam_dirs(*_unused):
schema.set_strv("steam-extra-dirs", [])
update_revealer()
def set_heroic_dir(_source, result, _unused):
try:
schema.set_string(
@@ -100,7 +122,13 @@ class PreferencesWindow(Adw.PreferencesWindow):
def choose_folder(_widget, function):
filechooser.select_folder(parent_widget, None, function, None)
update_revealer()
self.steam_file_chooser_button.connect("clicked", choose_folder, set_steam_dir)
self.steam_extra_file_chooser_button.connect(
"clicked", choose_folder, add_steam_dir
)
self.steam_clear_button.connect("clicked", clear_steam_dirs)
self.heroic_file_chooser_button.connect(
"clicked", choose_folder, set_heroic_dir
)

View File

@@ -267,9 +267,17 @@ def steam_parser(parent_widget, action):
appmanifests = []
for open_file in os.listdir(os.path.join(steam_dir, "steamapps")):
path = os.path.join(steam_dir, "steamapps", open_file)
if os.path.isfile(path) and "appmanifest" in open_file:
appmanifests.append(path)
steam_dirs = schema.get_strv("steam-extra-dirs")
steam_dirs.append(steam_dir)
get_games_async(parent_widget, appmanifests, steam_dir, import_dialog)
for directory in steam_dirs:
if not os.path.exists(os.path.join(directory, "steamapps")):
steam_dirs.remove(directory)
for directory in steam_dirs:
for open_file in os.listdir(os.path.join(directory, "steamapps")):
path = os.path.join(directory, "steamapps", open_file)
if os.path.isfile(path) and "appmanifest" in open_file:
appmanifests.append(path)
get_games_async(parent_widget, appmanifests, directory, import_dialog)