[retro-gtk] module-query: Add ModuleQuery.iterator()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] module-query: Add ModuleQuery.iterator()
- Date: Sun, 26 Feb 2017 13:19:29 +0000 (UTC)
commit 6de454d3d96883ab50a6e7bdb81298bde167ed34
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Feb 26 13:30:11 2017 +0100
module-query: Add ModuleQuery.iterator()
Turn the ModuleQuery namespace into an class itearable with the foreach
Vala keyword. this also allows to iterate the available modules in a
sync and an async way.
retro-gtk/retro-module-query.vala | 56 +++---------------------------------
1 files changed, 5 insertions(+), 51 deletions(-)
---
diff --git a/retro-gtk/retro-module-query.vala b/retro-gtk/retro-module-query.vala
index 97dbc65..8b6437b 100644
--- a/retro-gtk/retro-module-query.vala
+++ b/retro-gtk/retro-module-query.vala
@@ -1,50 +1,15 @@
// This file is part of retro-gtk. License: GPLv3
-namespace Retro.ModuleQuery {
- public delegate bool CoreDescriptorQueryCallback (CoreDescriptor core_descriptor);
-
+public class Retro.ModuleQuery {
private const string ENV_PLUGIN_PATH = "LIBRETRO_PLUGIN_PATH";
- public void foreach_core_descriptor (CoreDescriptorQueryCallback callback) {
- foreach (var path in get_plugin_lookup_paths ()) {
- var directory = File.new_for_path (path);
- if (!directory.query_exists ())
- continue;
-
- if (directory.query_file_type (FileQueryInfoFlags.NOFOLLOW_SYMLINKS) !=
FileType.DIRECTORY)
- continue;
-
- bool stop = false;
- foreach_child (directory, (info) => {
- var core_descriptor_basename = info.get_name ();
- if (!core_descriptor_basename.has_suffix (".libretro"))
- return true;
-
- var core_descriptor_file = directory.get_child (core_descriptor_basename);
- var core_descriptor_path = core_descriptor_file.get_path ();
- CoreDescriptor core_descriptor;
- try {
- core_descriptor = new CoreDescriptor (core_descriptor_path);
- }
- catch (Error e) {
- debug (e.message);
-
- return true;
- }
+ public ModuleIterator iterator () {
+ var paths = get_plugin_lookup_paths ();
- stop = callback (core_descriptor);
- if (!stop)
- return true;
-
- return false;
- });
-
- if (stop)
- break;
- }
+ return new ModuleIterator (paths);
}
- private string[] get_plugin_lookup_paths () {
+ private static 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)
@@ -52,16 +17,5 @@ namespace Retro.ModuleQuery {
return @"$env_plugin_path:$(Config.RETRO_PLUGIN_PATH)".split (":");
}
-
- private delegate bool ForeachChildFunc (FileInfo child_info);
- private void foreach_child (File file, ForeachChildFunc child_info_callback) {
- try {
- var enumerator = file.enumerate_children ("", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
- for (var info = enumerator.next_file () ; info != null && child_info_callback (info)
; info = enumerator.next_file ());
- }
- catch (Error e) {
- debug (e.message);
- }
- }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]