[gnome-games] steam: Replace SteamGame by GenericGame



commit b4f02ec320ac176174d9f3e74d7f91e8ffc36ac4
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue May 10 15:17:34 2016 +0200

    steam: Replace SteamGame by GenericGame
    
    This is needed to remove custom game types and to simplify the code
    base.
    
    Fixes #292

 plugins/steam/src/Makefile.am            |    2 +-
 plugins/steam/src/steam-error.vala       |    6 ++++
 plugins/steam/src/steam-game-source.vala |   22 +++++++++++++++-
 plugins/steam/src/steam-game.vala        |   41 ------------------------------
 plugins/steam/src/steam-title.vala       |    2 +-
 5 files changed, 29 insertions(+), 44 deletions(-)
---
diff --git a/plugins/steam/src/Makefile.am b/plugins/steam/src/Makefile.am
index 104913b..3f916be 100644
--- a/plugins/steam/src/Makefile.am
+++ b/plugins/steam/src/Makefile.am
@@ -6,7 +6,7 @@ libgames_steam_plugin_la_DEPENDENCIES = \
        $(NULL)
 
 libgames_steam_plugin_la_SOURCES = \
-       steam-game.vala \
+       steam-error.vala \
        steam-game-source.vala \
        steam-icon.vala \
        steam-plugin.vala \
diff --git a/plugins/steam/src/steam-error.vala b/plugins/steam/src/steam-error.vala
new file mode 100644
index 0000000..a69173c
--- /dev/null
+++ b/plugins/steam/src/steam-error.vala
@@ -0,0 +1,6 @@
+// This file is part of GNOME Games. License: GPLv3
+
+errordomain Games.SteamError {
+       NO_APPID,
+       NO_NAME,
+}
diff --git a/plugins/steam/src/steam-game-source.vala b/plugins/steam/src/steam-game-source.vala
index f338276..53a030e 100644
--- a/plugins/steam/src/steam-game-source.vala
+++ b/plugins/steam/src/steam-game-source.vala
@@ -66,7 +66,7 @@ private class Games.SteamGameSource : Object, GameSource {
                var name = info.get_name ();
                if (appmanifest_regex.match (name)) {
                        try {
-                               var game = new SteamGame (@"$directory/$name");
+                               var game = game_for_appmanifest_path (@"$directory/$name");
                                game_callback (game);
 
                                Idle.add (this.game_for_file_info.callback);
@@ -77,4 +77,24 @@ private class Games.SteamGameSource : Object, GameSource {
                        }
                }
        }
+
+       private static Game game_for_appmanifest_path (string appmanifest_path) throws Error {
+               var registry = new SteamRegistry (appmanifest_path);
+               var game_id = registry.get_data ({"AppState", "appid"});
+               /* The game_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 
'$appmanifest_path'");
+
+               var title = new SteamTitle (registry);
+               var icon = new SteamIcon (game_id);
+               var cover = new DummyCover ();
+               string[] args = { "steam", @"steam://rungameid/" + game_id };
+               var runner = new CommandRunner (args, false);
+
+               return new GenericGame (title, icon, cover, runner);
+       }
 }
diff --git a/plugins/steam/src/steam-title.vala b/plugins/steam/src/steam-title.vala
index 5a5c3f8..0a04540 100644
--- a/plugins/steam/src/steam-title.vala
+++ b/plugins/steam/src/steam-title.vala
@@ -14,7 +14,7 @@ private class Games.SteamTitle : Object, Title {
 
                name = registry.get_data ({"AppState", "name"});
                if (name == null)
-                       throw new SteamGameError.NO_NAME (@"Couldn't get name from Steam registry.");
+                       throw new SteamError.NO_NAME (@"Couldn't get name from Steam registry.");
 
                return name;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]