[retro-gtk] lol



commit c8f079c44b111bf11bf073bc90912f27dde54816
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Aug 9 15:25:20 2016 +0200

    lol

 retro-gobject/Makefile.am             |    2 +
 retro-gobject/retro-module-query.vala |   86 +++++++++++++++++++++++++++++++++
 retro-gobject/retro.vala              |    2 +
 retro-gobject/vapi/config.vapi        |    2 +
 4 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/retro-gobject/Makefile.am b/retro-gobject/Makefile.am
index 21e81e2..0dd583e 100644
--- a/retro-gobject/Makefile.am
+++ b/retro-gobject/Makefile.am
@@ -10,6 +10,7 @@ AM_CPPFLAGS = \
        -DPROJECT_API_VERSION=\""0.6"\" \
        -DPROJECT_DIR_NAME=\""retro-1.0"\" \
        -DPROJECT_PLUGINS_DIR=\""$(libdir)/retro-1.0/plugins"\" \
+       -DRETRO_PLUGIN_PATH=\""$(libdir)/retro-1.0/plugins:$(libdir)/libretro:$(libdir)"\" \
        $(RETRO_GOBJECT_CFLAGS) \
        $(NULL)
 
@@ -56,6 +57,7 @@ libretro_gobject_la_SOURCES = \
        performance.vala \
        region.vala \
        retro.vala \
+       retro-module-query.vala \
        rumble.vala \
        sensor.vala \
        subsystem.vala \
diff --git a/retro-gobject/retro-module-query.vala b/retro-gobject/retro-module-query.vala
new file mode 100644
index 0000000..6239bc5
--- /dev/null
+++ b/retro-gobject/retro-module-query.vala
@@ -0,0 +1,86 @@
+// This file is part of Retro. License: GPLv3
+
+[CCode (gir_namespace = "Retro", gir_version = "0.6")]
+namespace Retro.ModuleQuery {
+       public delegate bool ModuleInfoQueryCallback (HashTable<string, string> module_info);
+
+       private const string ENV_PLUGIN_PATH = "RETRO_PLUGIN_PATH_1_0";
+
+       private string[] get_plugin_lookup_paths () {
+               var envp = Environ.@get ();
+               var env_plugin_path = Environ.get_variable (envp, ENV_PLUGIN_PATH);
+               if (env_plugin_path == null)
+                       return Config.RETRO_PLUGIN_PATH.split (":");
+
+               return @"$env_plugin_path:$(Config.RETRO_PLUGIN_PATH)".split (":");
+       }
+
+       private static string? lookup_module_for_basename (string basename) throws Error {
+               foreach (var path in get_plugin_lookup_paths ()) {
+                       var directory = File.new_for_path (path);
+                       var file = directory.get_child (basename);
+                       if (!file.query_exists ())
+                               continue;
+
+                       return file.get_path ();
+               }
+
+               return null;
+       }
+
+       public string? lookup_module_for_info (ModuleInfoQueryCallback callback) throws Error {
+               foreach (var path in get_plugin_lookup_paths ()) {
+                       print ("cherche dans %s\n", path);
+
+                       var directory = File.new_for_path (path);
+                       var enumerator = directory.enumerate_children ("", 
FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
+                       for (var info = enumerator.next_file () ; info != null ; info = enumerator.next_file 
()) {
+                               var module_info_basename = info.get_name ();
+                               print ("test %s\n", module_info_basename);
+                               if (!module_info_basename.has_suffix ("_libretro.info"))
+                                       continue;
+
+                               print ("test %s\n", module_info_basename);
+                               // Replace the "info" extension by "so".
+                               var module_basename = module_info_basename[0:module_info_basename.length - 4] 
+ "so";
+                               var module_file = directory.get_child (module_basename);
+                               if (!module_file.query_exists ())
+                                       continue;
+
+                               if (info.get_file_type () == FileType.DIRECTORY)
+                                       continue;
+
+                               var module_info_file = directory.get_child (module_info_basename);
+                               var module_info = get_module_info (module_info_file);
+                               if (!callback (module_info))
+                                       continue;
+
+                               return module_file.get_path ();
+                       }
+               }
+
+               return null;
+       }
+
+       private HashTable<string, string> get_module_info (File module_info_file) {
+               var module_info = new HashTable<string, string> (str_hash, str_equal);
+
+               var dis = new DataInputStream (module_info_file.read ());
+               for (var line = dis.read_line (null) ; line != null ; line = dis.read_line (null)) {
+                       var splitted_line = line.split ("=", 2);
+                       if (splitted_line.length != 2)
+                               continue;
+
+                       var key = splitted_line[0].strip ();
+                       var value = splitted_line[1].strip ();
+                       if (value.has_prefix ("\"") && value.has_suffix ("\"") && value.length >= 2)
+                               // Remove the quotes.
+                               module_info[key] = value[1:value.length - 1];
+                       else
+                               module_info[key] = value;
+               }
+
+               return module_info;
+       }
+}
+
diff --git a/retro-gobject/retro.vala b/retro-gobject/retro.vala
index 8c6976d..93643d7 100644
--- a/retro-gobject/retro.vala
+++ b/retro-gobject/retro.vala
@@ -40,10 +40,12 @@ public SystemInfo? get_system_info (string module_name) {
        return info;
 }
 
+[Version (deprecated = true, deprecated_since = "0.8")]
 public static string get_plugins_dir () {
        return Config.PROJECT_PLUGINS_DIR;
 }
 
+[Version (deprecated = true, deprecated_since = "0.8", replacement = 
"Retro.ModuleQuery.lookup_module_for_basename")]
 public string? search_module (string module_basename) {
        var envp = Environ.@get ();
        var retro_plugin_path = Environ.get_variable (envp, ENV_PLUGIN_PATH) ?? "";
diff --git a/retro-gobject/vapi/config.vapi b/retro-gobject/vapi/config.vapi
index cfd00b2..2fec407 100644
--- a/retro-gobject/vapi/config.vapi
+++ b/retro-gobject/vapi/config.vapi
@@ -8,7 +8,9 @@ namespace Config {
        public const string PROJECT_NAME;
        public const string PROJECT_API_VERSION;
        public const string PROJECT_DIR_NAME;
+       [Version (deprecated = true, deprecated_since = "0.8", replacement = "Config.RETRO_PLUGIN_PATH")]
        public const string PROJECT_PLUGINS_DIR;
+       public const string RETRO_PLUGIN_PATH;
        public const string PACKAGE;
        public const string VERSION;
 }


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