[gnome-games] steam: Use SteamUriSource and a generic game factory
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] steam: Use SteamUriSource and a generic game factory
- Date: Sun, 7 May 2017 05:02:32 +0000 (UTC)
commit 6ec89ca6230836aa3c8a506c58f04238ce4b3def
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sat May 6 10:52:54 2017 +0200
steam: Use SteamUriSource and a generic game factory
Replace usage of SteamGameSource by a SteamUriSource and a
GenericUriGameFactory accepting the steam+file URI scheme.
https://bugzilla.gnome.org/show_bug.cgi?id=781334
plugins/steam/src/steam-plugin.vala | 61 +++++++++++++++++++++++++++++++++-
1 files changed, 59 insertions(+), 2 deletions(-)
---
diff --git a/plugins/steam/src/steam-plugin.vala b/plugins/steam/src/steam-plugin.vala
index e9a682f..8043877 100644
--- a/plugins/steam/src/steam-plugin.vala
+++ b/plugins/steam/src/steam-plugin.vala
@@ -1,8 +1,65 @@
// This file is part of GNOME Games. License: GPL-3.0+.
private class Games.SteamPlugin : Object, Plugin {
- public GameSource? get_game_source () throws Error {
- return new SteamGameSource ();
+ private const string STEAM_FILE_SCHEME = "steam+file";
+
+ private static HashTable<string, Game> game_for_id;
+
+ static construct {
+ game_for_id = new HashTable<string, Game> (str_hash, str_equal);
+ }
+
+ public UriSource[] get_uri_sources () {
+ try {
+ var source = new SteamUriSource ();
+
+ return { source };
+ }
+ catch (Error e) {
+ debug (e.message);
+ }
+
+ return {};
+ }
+
+ public UriGameFactory[] get_uri_game_factories () {
+ var game_uri_adapter = new GenericGameUriAdapter (game_for_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 {
+ var file_uri = new Uri.from_uri_and_scheme (uri, "file");
+ var file = file_uri.to_file ();
+ var appmanifest_path = file.get_path ();
+ var registry = new SteamRegistry (appmanifest_path);
+ var game_id = registry.get_data ({"AppState", "appid"});
+ /* The gamegames_id sometimes is identified by appID
+ * see issue https://github.com/Kekun/gnome-games/issues/169 */
+ if (game_id == null)
+ game_id = registry.get_data ({"AppState", "appID"});
+
+ if (game_id == null)
+ throw new SteamError.NO_APPID (_("Couldn’t get Steam appid from manifest “%s”."),
appmanifest_path);
+
+ if (game_id in game_for_id) {
+ var game = game_for_id[game_id];
+
+ return game;
+ }
+
+ var title = new SteamTitle (registry);
+ var icon = new SteamIcon (game_id);
+ var cover = new SteamCover (game_id);
+ string[] args = { "steam", @"steam://rungameid/" + game_id };
+ var runner = new CommandRunner (args, false);
+
+ var game = new GenericGame (title, icon, cover, runner);
+ game_for_id[game_id] = game;
+
+ return game;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]