[aisleriot] guile: Also look for compiled scheme files when listing the games



commit 29797a6343a9f8cf3f950a853085f532bdd99cfb
Author: Christian Persch <chpe gnome org>
Date:   Sat Dec 3 17:04:02 2011 +0100

    guile: Also look for compiled scheme files when listing the games

 src/game.c |   55 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/src/game.c b/src/game.c
index 87f2b48..eb8d5ba 100644
--- a/src/game.c
+++ b/src/game.c
@@ -2629,6 +2629,28 @@ aisleriot_game_reset_old_cards (ArSlot *slot)
 
 #endif /* HAVE_CLUTTER */
 
+static void
+append_games_from_path (GHashTable *hash_table,
+                        const char *path,
+                        const char *suffix)
+{
+  GDir *dir;
+  const char *filename;
+
+  dir = g_dir_open (path, 0, NULL);
+  if (dir == NULL)
+    return;
+
+  while ((filename = g_dir_read_name (dir)) != NULL) {
+    if (!g_str_has_suffix (filename, suffix))
+      continue;
+
+    g_hash_table_insert (hash_table, 
+                         ar_filename_to_game_module (filename),
+                         NULL);
+  }
+}
+
 /**
  * ar_get_game_modules:
  * 
@@ -2637,29 +2659,38 @@ aisleriot_game_reset_old_cards (ArSlot *slot)
 char **
 ar_get_game_modules (void)
 {
+  GHashTable *hash_table;
   char *path;
-  const char *filename;
-  GDir *dir;
   GPtrArray *array;
+  GHashTableIter iter;
+  gpointer key;
 
-  path = g_build_filename (ar_runtime_get_directory (AR_RUNTIME_PKG_DATA_DIRECTORY),
+  hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+#if SCM_MAJOR_VERSION >= 2
+  path = g_build_filename (ar_runtime_get_directory (AR_RUNTIME_PKG_LIBRARY_DIRECTORY),
                            "guile",
                            SCM_EFFECTIVE_VERSION,
                            NULL);
-  dir = g_dir_open (path, 0, NULL);
+  append_games_from_path (hash_table, path, ".go");
   g_free (path);
-  if (dir == NULL)
-    return NULL;
+#endif
 
-  array = g_ptr_array_new ();
+  path = g_build_filename (ar_runtime_get_directory (AR_RUNTIME_PKG_DATA_DIRECTORY),
+                           "guile",
+                           SCM_EFFECTIVE_VERSION,
+                           NULL);
+  append_games_from_path (hash_table, path, ".scm");
+  g_free (path);
 
-  while ((filename = g_dir_read_name (dir)) != NULL) {
-    if (!g_str_has_suffix (filename, ".scm") ||
-        strcmp (filename, "api.scm") == 0)
-      continue;
+  array = g_ptr_array_sized_new (g_hash_table_size (hash_table));
 
-    g_ptr_array_add (array, ar_filename_to_game_module (filename));
+  g_hash_table_iter_init (&iter, hash_table);
+  while (g_hash_table_iter_next (&iter, &key, NULL)) {
+    g_hash_table_iter_steal (&iter);
+    g_ptr_array_add (array, key);
   }
+  g_hash_table_unref (hash_table);
 
   g_ptr_array_sort (array, (GCompareFunc) strcmp);
   g_ptr_array_add (array, NULL);



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