[gnome-games] libretro: Use LibretroUriSource and a generic game factory



commit 05e110c94007c08a92dbed8b789ce1ab64dcbff2
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun May 7 12:19:30 2017 +0200

    libretro: Use LibretroUriSource and a generic game factory
    
    Replace usage of LibretroGameSource by a LibretroUriSource and a
    GenericUriGameFactory accepting the libretro+file URI scheme.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781334

 plugins/libretro/src/libretro-plugin.vala |   36 +++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/plugins/libretro/src/libretro-plugin.vala b/plugins/libretro/src/libretro-plugin.vala
index f6f66bd..5f45708 100644
--- a/plugins/libretro/src/libretro-plugin.vala
+++ b/plugins/libretro/src/libretro-plugin.vala
@@ -1,8 +1,40 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 private class Games.LibretroPlugin : Object, Plugin {
-       public GameSource? get_game_source () throws Error {
-               return new LibretroGameSource ();
+       private const string LIBRETRO_FILE_SCHEME = "libretro+file";
+
+       public UriSource[] get_uri_sources () {
+               var source = new LibretroUriSource ();
+
+               return { source };
+       }
+
+       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 (LIBRETRO_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 ();
+               if (!file.query_exists ())
+                       throw new LibretroError.NOT_A_LIBRETRO_DESCRIPTOR ("This isn’t a Libretro core 
descriptor: %s", uri.to_string ());
+
+               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.to_string ());
+
+               var uid = new LibretroUid (core_descriptor);
+               var title = new LibretroTitle (core_descriptor);
+               var icon = new LibretroIcon (core_descriptor);
+               var cover = new DummyCover ();
+               var runner = new RetroRunner.for_core_descriptor (core_descriptor, uid, title);
+
+               return new GenericGame (title, icon, cover, runner);
        }
 }
 


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