[gnome-games] retro: Add RetroCoreSource



commit 935cdc92cd63c8dcfcca7c3de19241e85679ef56
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Feb 10 11:51:22 2017 +0100

    retro: Add RetroCoreSource
    
    This will be used in the next commit to look for Libretro cores using
    the Libretro Core Descriptor format for Games, replacing the RetroArch
    libretro-super .info format.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778446

 src/Makefile.am                  |    1 +
 src/retro/retro-core-source.vala |   65 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d8d3d6..5405dd5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -88,6 +88,7 @@ gnome_games_SOURCES = \
        grilo/grilo-cover.vala \
        grilo/grilo-media.vala \
        \
+       retro/retro-core-source.vala \
        retro/retro-error.vala \
        retro/retro-gamepad.vala \
        retro/retro-input-manager.vala \
diff --git a/src/retro/retro-core-source.vala b/src/retro/retro-core-source.vala
new file mode 100644
index 0000000..c9a6e48
--- /dev/null
+++ b/src/retro/retro-core-source.vala
@@ -0,0 +1,65 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.RetroCoreSource : Object {
+       private string platform;
+       private string[] mime_types;
+
+       private string module_path;
+       private bool searched;
+
+       public RetroCoreSource (string platform, string[] mime_types) {
+               this.platform = platform;
+               this.mime_types = mime_types;
+               module_path = null;
+               searched = false;
+       }
+
+       public string get_platform () {
+               return platform;
+       }
+
+       public string get_module_path () throws Error {
+               ensure_module_is_found ();
+
+               return module_path;
+       }
+
+       private void ensure_module_is_found () throws Error {
+               if (!searched) {
+                       searched = true;
+                       search_module ();
+               }
+
+               if (module_path == null)
+                       throw new RetroError.MODULE_NOT_FOUND (_("No module found for platform '%s' and MIME 
types [ '%s' ]."), platform, string.joinv ("', '", mime_types));
+       }
+
+       private void search_module () throws Error {
+               Retro.ModuleQuery.foreach_core_descriptor (parse_core_descriptor);
+       }
+
+       private bool parse_core_descriptor (Retro.CoreDescriptor core_descriptor) {
+               try {
+                       if (!core_descriptor.get_is_emulator ())
+                               return false;
+
+                       if (!core_descriptor.has_platform (platform))
+                               return false;
+
+                       var supported_mime_types = core_descriptor.get_mime_type (platform);
+                       foreach (var mime_type in mime_types)
+                               if (!(mime_type in supported_mime_types))
+                                       return false;
+
+                       var module_file = core_descriptor.get_module_file ();
+                       module_path = module_file.get_path ();
+
+                       return true;
+               }
+               catch (Error e) {
+                       debug (e.message);
+
+                       return false;
+               }
+       }
+}


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