[gnome-games/wip/aplazas/781334-refactor-game-sources: 9/9] libretro: Add LibretroGameSource.game_for_uri()



commit ef638d6a184562cfbb6e4d13832ae425554d9825
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Apr 13 16:11:55 2017 +0200

    libretro: Add LibretroGameSource.game_for_uri()
    
    This will be used in a subsequent commit to make a game from an URI.

 plugins/libretro/src/Makefile.am               |    1 +
 plugins/libretro/src/libretro-error.vala       |    6 ++++++
 plugins/libretro/src/libretro-game-source.vala |   16 ++++++++++++++++
 3 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/plugins/libretro/src/Makefile.am b/plugins/libretro/src/Makefile.am
index a5dbff0..6bbb3f6 100644
--- a/plugins/libretro/src/Makefile.am
+++ b/plugins/libretro/src/Makefile.am
@@ -6,6 +6,7 @@ libgames_libretro_plugin_la_DEPENDENCIES = \
        $(NULL)
 
 libgames_libretro_plugin_la_SOURCES = \
+       libretro-error.vala \
        libretro-game-source.vala \
        libretro-icon.vala \
        libretro-plugin.vala \
diff --git a/plugins/libretro/src/libretro-error.vala b/plugins/libretro/src/libretro-error.vala
new file mode 100644
index 0000000..a106ac7
--- /dev/null
+++ b/plugins/libretro/src/libretro-error.vala
@@ -0,0 +1,6 @@
+// This file is part of GNOME Games. License: GPLv3
+
+errordomain Games.LibretroError {
+       NOT_A_LIBRETRO_DESCRIPTOR,
+       NOT_A_GAME,
+}
diff --git a/plugins/libretro/src/libretro-game-source.vala b/plugins/libretro/src/libretro-game-source.vala
index 8432cd0..0c6774d 100644
--- a/plugins/libretro/src/libretro-game-source.vala
+++ b/plugins/libretro/src/libretro-game-source.vala
@@ -3,6 +3,22 @@
 public class Games.LibretroGameSource : Object, GameSource {
        private Game[] games;
 
+       public async Game game_for_uri (string uri) throws Error {
+               if (!uri.has_prefix ("file:") || !uri.has_suffix (".libretro"))
+                       throw new LibretroError.NOT_A_LIBRETRO_DESCRIPTOR ("This isn’t a Libretro core 
descriptor: %s", uri);
+
+               var file = File.new_for_uri (uri);
+               if (!file.query_exists ())
+                       throw new LibretroError.NOT_A_LIBRETRO_DESCRIPTOR ("This isn’t a Libretro core 
descriptor: %s", uri);
+
+               var path = file.get_path ();
+               var core_descriptor = new Retro.CoreDescriptor (path);
+               if (!core_descriptor.get_is_game ())
+                       throw new LibretroError.NOT_A_GAME ("This Libretro core descriptor doesn't isn’t a 
game: %s", uri);
+
+               return game_for_core_descriptor (core_descriptor);
+       }
+
        public async void each_game (GameCallback callback) {
                if (games == null)
                        yield fetch_games ();


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