[gnome-games/wip/exalm/platform-preferences] retro: Add RetroCoreManager



commit c82a664b78020830731810aa4a52485e323462c3
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Sep 27 21:59:15 2018 +0500

    retro: Add RetroCoreManager

 src/meson.build                   |  1 +
 src/retro/retro-core-manager.vala | 58 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 29887433..904e1020 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -108,6 +108,7 @@ vala_sources = [
   'keyboard/keyboard-mapping-builder.vala',
   'keyboard/keyboard-mapping-manager.vala',
 
+  'retro/retro-core-manager.vala',
   'retro/retro-core-source.vala',
   'retro/retro-error.vala',
   'retro/retro-gamepad.vala',
diff --git a/src/retro/retro-core-manager.vala b/src/retro/retro-core-manager.vala
new file mode 100644
index 00000000..d8b44fbc
--- /dev/null
+++ b/src/retro/retro-core-manager.vala
@@ -0,0 +1,58 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.RetroCoreManager : Object {
+       private Retro.CoreDescriptor[] core_descriptors;
+       private bool searched;
+
+       public RetroCoreManager () {
+               searched = false;
+               core_descriptors = {};
+       }
+
+       private void search_modules () {
+               var modules = new Retro.ModuleQuery (true);
+               foreach (var core_descriptor in modules) {
+                       try {
+                               if (!core_descriptor.get_is_emulator ())
+                                       continue;
+
+                               if (core_descriptor.get_module_file () == null)
+                                       continue;
+
+                               core_descriptors += core_descriptor;
+                       }
+                       catch (Error e) {
+                               debug (e.message);
+                       }
+               }
+       }
+
+       public Retro.CoreDescriptor[] get_cores_for_platform (RetroPlatform platform) {
+               if (!searched) {
+                       searched = true;
+                       search_modules ();
+               }
+
+               Retro.CoreDescriptor[] result = {};
+
+               foreach (var core_descriptor in core_descriptors) {
+                       try {
+                               var platform_id = platform.get_id ();
+                               var mime_types = platform.get_mime_types ();
+
+                               if (!core_descriptor.has_platform (platform_id))
+                                       continue;
+
+                               if (!core_descriptor.get_platform_supports_mime_types (platform_id, 
mime_types))
+                                       continue;
+
+                               result += core_descriptor;
+                       }
+                       catch (Error e) {
+                               debug (e.message);
+                       }
+               }
+
+               return result;
+       }
+}


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