[gnome-games/wip/exalm/platform-preferences: 50/65] retro: Add RetroCoreManager
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/platform-preferences: 50/65] retro: Add RetroCoreManager
- Date: Mon, 11 Feb 2019 16:29:25 +0000 (UTC)
commit 5748f5222f6589b7ed90fbaeb1db368aa0a8bd68
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Thu Sep 27 21:59:15 2018 +0500
retro: Add RetroCoreManager
Searching cores can take some time, so make it a singleton.
src/meson.build | 1 +
src/retro/retro-core-manager.vala | 76 +++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 7366e14e..b9ab1f29 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -109,6 +109,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..07c21ba1
--- /dev/null
+++ b/src/retro/retro-core-manager.vala
@@ -0,0 +1,76 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.RetroCoreManager : Object {
+ private static RetroCoreManager instance;
+
+ private Retro.CoreDescriptor[] core_descriptors;
+ private bool searched;
+
+ public static RetroCoreManager get_instance () {
+ if (instance == null)
+ instance = new RetroCoreManager ();
+
+ return instance;
+ }
+
+ private 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 ();
+ }
+
+ var result = new Array<Retro.CoreDescriptor> ();
+
+ var path = "/org/gnome/Games/platforms/%s/".printf (platform.get_id ());
+ var settings = new Settings.with_path ("org.gnome.Games.platforms", path);
+
+ var preferred_core = settings.get_string ("preferred-core");
+
+ 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;
+
+ // Insert preferred core at the start of the list
+ if (core_descriptor.get_id () == preferred_core)
+ result.prepend_val (core_descriptor);
+ else
+ result.append_val (core_descriptor);
+ }
+ catch (Error e) {
+ debug (e.message);
+ }
+ }
+
+ return result.data;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]