[gnome-games] steam: Support multiple Steam instances
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] steam: Support multiple Steam instances
- Date: Fri, 10 Aug 2018 20:25:47 +0000 (UTC)
commit 39646055d31f983b4c71b0584d86a372ec0d8769
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Fri Aug 10 02:16:40 2018 +0500
steam: Support multiple Steam instances
This will be used in the next commit to add support for Steam in Flatpak.
plugins/steam/src/steam-icon.vala | 16 +++++++---------
plugins/steam/src/steam-plugin.vala | 23 +++++++++++++++++------
plugins/steam/src/steam-uid.vala | 10 ++++++----
plugins/steam/src/steam-uri-iterator.vala | 8 +++++---
plugins/steam/src/steam-uri-source.vala | 13 +++++++------
5 files changed, 42 insertions(+), 28 deletions(-)
---
diff --git a/plugins/steam/src/steam-icon.vala b/plugins/steam/src/steam-icon.vala
index a8cd9ebb..03a4d0c4 100644
--- a/plugins/steam/src/steam-icon.vala
+++ b/plugins/steam/src/steam-icon.vala
@@ -1,27 +1,25 @@
// This file is part of GNOME Games. License: GPL-3.0+.
private class Games.SteamIcon : Object, Icon {
- private static GLib.Icon? steam_icon;
+ private GLib.Icon? steam_icon;
private string game_id;
private GLib.Icon? icon;
private bool searched;
- static construct {
+ public SteamIcon (string app_id, string game_id) {
+ this.game_id = game_id;
+
+ searched = false;
+
try {
- steam_icon = GLib.Icon.new_for_string ("steam");
+ steam_icon = GLib.Icon.new_for_string (app_id);
}
catch (Error e) {
warning ("%s\n", e.message);
}
}
- public SteamIcon (string game_id) {
- this.game_id = game_id;
-
- searched = false;
- }
-
public GLib.Icon? get_icon () {
if (searched)
return icon ?? steam_icon;
diff --git a/plugins/steam/src/steam-plugin.vala b/plugins/steam/src/steam-plugin.vala
index e394e361..383c0c02 100644
--- a/plugins/steam/src/steam-plugin.vala
+++ b/plugins/steam/src/steam-plugin.vala
@@ -12,8 +12,11 @@ private class Games.SteamPlugin : Object, Plugin {
}
public UriSource[] get_uri_sources () {
+ // Steam's installation path can be found in its registry.
+ var home = Environment.get_home_dir ();
+
try {
- var source = new SteamUriSource ();
+ var source = new SteamUriSource (home, STEAM_FILE_SCHEME);
return { source };
}
@@ -25,14 +28,18 @@ private class Games.SteamPlugin : Object, Plugin {
}
public UriGameFactory[] get_uri_game_factories () {
- var game_uri_adapter = new GenericGameUriAdapter (game_for_uri);
+ var game_uri_adapter = new GenericGameUriAdapter (game_for_steam_uri);
var factory = new GenericUriGameFactory (game_uri_adapter);
factory.add_scheme (STEAM_FILE_SCHEME);
return { factory };
}
- private static Game game_for_uri (Uri uri) throws Error {
+ private static Game game_for_steam_uri (Uri uri) throws Error {
+ return create_game (uri, "steam", "", { "steam" });
+ }
+
+ private static Game create_game (Uri uri, string app_id, string prefix, string[] command) throws
Error {
var file_uri = new Uri.from_uri_and_scheme (uri, "file");
var file = file_uri.to_file ();
var appmanifest_path = file.get_path ();
@@ -46,11 +53,15 @@ private class Games.SteamPlugin : Object, Plugin {
if (game_id == null)
throw new SteamError.NO_APPID (_("Couldn’t get Steam appid from manifest “%s”."),
appmanifest_path);
- var uid = new SteamUid (game_id);
+ var uid = new SteamUid (prefix, game_id);
var title = new SteamTitle (registry);
- var icon = new SteamIcon (game_id);
+ var icon = new SteamIcon (app_id, game_id);
var cover = new SteamCover (game_id);
- string[] args = { "steam", @"steam://rungameid/" + game_id };
+
+ string[] args = {};
+ foreach (var part in command)
+ args += part;
+ args += @"steam://rungameid/$game_id";
var runner = new CommandRunner (args, false);
var game = new GenericGame (uid, title, platform, runner);
diff --git a/plugins/steam/src/steam-uid.vala b/plugins/steam/src/steam-uid.vala
index 6bd7025a..faf66af9 100644
--- a/plugins/steam/src/steam-uid.vala
+++ b/plugins/steam/src/steam-uid.vala
@@ -2,17 +2,19 @@
private class Games.SteamUid: Object, Uid {
private string uid;
- private string app_id;
+ private string prefix;
+ private string game_id;
- public SteamUid (string app_id) {
- this.app_id = app_id;
+ public SteamUid (string prefix, string game_id) {
+ this.prefix = prefix;
+ this.game_id = game_id;
}
public string get_uid () throws Error {
if (uid != null)
return uid;
- uid = @"steam-$app_id".down ();
+ uid = @"steam-$prefix$game_id".down ();
return uid;
}
diff --git a/plugins/steam/src/steam-uri-iterator.vala b/plugins/steam/src/steam-uri-iterator.vala
index 8e505a44..35e91783 100644
--- a/plugins/steam/src/steam-uri-iterator.vala
+++ b/plugins/steam/src/steam-uri-iterator.vala
@@ -4,10 +4,12 @@ private class Games.SteamUriIterator : Object, UriIterator {
private string[] directories;
private int directory_index;
private FileEnumerator? enumerator;
+ private string uri_scheme;
private Uri? uri;
- internal SteamUriIterator (string[] directories) {
+ internal SteamUriIterator (string[] directories, string uri_scheme) {
this.directories = directories;
+ this.uri_scheme = uri_scheme;
directory_index = 0;
uri = null;
enumerator = null;
@@ -58,8 +60,8 @@ private class Games.SteamUriIterator : Object, UriIterator {
return false;
var filename = Path.build_filename (directory, info.get_name ());
- var file_uri = Filename.to_uri (filename);
- uri = new Uri (@"steam+$file_uri");
+ var file_uri = new Uri (Filename.to_uri (filename));
+ uri = new Uri.from_uri_and_scheme (file_uri, uri_scheme);
return true;
}
diff --git a/plugins/steam/src/steam-uri-source.vala b/plugins/steam/src/steam-uri-source.vala
index 209c76d8..c35568f6 100644
--- a/plugins/steam/src/steam-uri-source.vala
+++ b/plugins/steam/src/steam-uri-source.vala
@@ -14,17 +14,18 @@ private class Games.SteamUriSource : Object, UriSource {
{ "Registry", "HKLM", "Software", "Valve", "Steam", "InstallPath" };
private string[] directories;
+ private string uri_scheme;
- public SteamUriSource () throws Error {
+ public SteamUriSource (string base_dir, string uri_scheme) throws Error {
directories = {};
- // Steam's installation path can be found in its registry.
- var home = Environment.get_home_dir ();
- var registry_path = home + REGISTRY_PATH;
+ this.uri_scheme = uri_scheme;
+
+ var registry_path = base_dir + REGISTRY_PATH;
var registry = new SteamRegistry (registry_path);
var install_path = registry.get_data (INSTALL_PATH_REGISTRY_PATH);
- add_library (home + DEFAULT_INSTALL_DIR_SYMLINK);
+ add_library (base_dir + DEFAULT_INSTALL_DIR_SYMLINK);
add_library (install_path);
// `/LibraryFolders/$NUMBER` entries in the libraryfolders.vdf registry
@@ -44,7 +45,7 @@ private class Games.SteamUriSource : Object, UriSource {
}
public UriIterator iterator () {
- return new SteamUriIterator (directories);
+ return new SteamUriIterator (directories, uri_scheme);
}
private void add_library (string library) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]