[gnome-games/wip/aplazas/781334-refactor-game-sources] libretro: Fixes
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/781334-refactor-game-sources] libretro: Fixes
- Date: Sun, 7 May 2017 06:59:50 +0000 (UTC)
commit 3fd5eaad4f504e9e2bd7674703e80cfecce1c73e
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun May 7 08:59:14 2017 +0200
libretro: Fixes
plugins/libretro/src/Makefile.am | 3 +-
plugins/libretro/src/libretro-game-source.vala | 60 -----------------------
plugins/libretro/src/libretro-plugin.vala | 43 +++++++++++++++-
plugins/libretro/src/libretro-uri-iterator.vala | 33 ++++++++++++
plugins/libretro/src/libretro-uri-source.vala | 7 +++
5 files changed, 83 insertions(+), 63 deletions(-)
---
diff --git a/plugins/libretro/src/Makefile.am b/plugins/libretro/src/Makefile.am
index 6bbb3f6..4438341 100644
--- a/plugins/libretro/src/Makefile.am
+++ b/plugins/libretro/src/Makefile.am
@@ -7,11 +7,12 @@ libgames_libretro_plugin_la_DEPENDENCIES = \
libgames_libretro_plugin_la_SOURCES = \
libretro-error.vala \
- libretro-game-source.vala \
libretro-icon.vala \
libretro-plugin.vala \
libretro-title.vala \
libretro-uid.vala \
+ libretro-uri-iterator.vala \
+ libretro-uri-source.vala \
$(NULL)
libgames_libretro_plugin_la_VALAFLAGS = \
diff --git a/plugins/libretro/src/libretro-plugin.vala b/plugins/libretro/src/libretro-plugin.vala
index f6f66bd..eed563a 100644
--- a/plugins/libretro/src/libretro-plugin.vala
+++ b/plugins/libretro/src/libretro-plugin.vala
@@ -1,8 +1,47 @@
// 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 () {
+ try {
+ var source = new LibretroUriSource ();
+
+ 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 (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);
}
}
diff --git a/plugins/libretro/src/libretro-uri-iterator.vala b/plugins/libretro/src/libretro-uri-iterator.vala
new file mode 100644
index 0000000..b499677
--- /dev/null
+++ b/plugins/libretro/src/libretro-uri-iterator.vala
@@ -0,0 +1,33 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.LibretroUriIterator : Object, UriIterator {
+ private Retro.ModuleIterator iterator;
+ private Uri? uri;
+
+ construct {
+ var modules = new Retro.ModuleQuery (true);
+ iterator = modules.iterator ();
+ uri = null;
+ }
+
+ public new Uri? get () {
+ return uri;
+ }
+
+ public bool next () {
+ while (iterator.next ()) {
+ var core_descriptor = iterator.get ();
+ if (!core_descriptor.get_is_game ())
+ continue;
+
+ var string_uri = core_descriptor.get_uri ();
+ uri = new Uri (@"libretro+$string_uri");
+
+ return true;
+ }
+
+ uri = null;
+
+ return false;
+ }
+}
diff --git a/plugins/libretro/src/libretro-uri-source.vala b/plugins/libretro/src/libretro-uri-source.vala
new file mode 100644
index 0000000..a2f62ba
--- /dev/null
+++ b/plugins/libretro/src/libretro-uri-source.vala
@@ -0,0 +1,7 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.LibretroUriSource : Object, UriSource {
+ public UriIterator iterator () {
+ return new LibretroUriIterator ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]