[mednaffe] 08/99: Search functions rewrited for Windows. Now it uses only winapi (g_file_test was too slow)

Stephen Kitt skitt at moszumanska.debian.org
Tue Aug 2 21:00:00 UTC 2016


This is an automated email from the git hooks/post-receive script.

skitt pushed a commit to branch master
in repository mednaffe.

commit e292df53c6b74c78e7db775853dc52ce3c4b6721
Author: amatcoder <amatcoder at 44025b82-9115-564b-7d03-7f3fc60b4744>
Date:   Wed Sep 11 00:20:16 2013 +0000

    Search functions rewrited for Windows. Now it uses only winapi (g_file_test was too slow)
---
 src/list.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 78 insertions(+), 3 deletions(-)

diff --git a/src/list.c b/src/list.c
index 14c4c01..faeb9c0 100644
--- a/src/list.c
+++ b/src/list.c
@@ -23,6 +23,10 @@
 #include "common.h"
 #include <stdlib.h>
 
+#ifdef G_OS_WIN32
+  #include <windows.h>
+#endif
+
 void change_list (guidata *gui)
 {
   GtkAdjustment *adjustament;
@@ -140,7 +144,7 @@ int descend_sort(const void * a, const void * b)
   const char *c = *(const char **) a;
   const char *d = *(const char **) b;
   
-  return g_strcmp0(d, c);
+  return strcmp(d, c);
 }
 
 int ascend_sort(const void * a, const void * b)
@@ -148,9 +152,79 @@ int ascend_sort(const void * a, const void * b)
   const char *c = *(const char **) a;
   const char *d = *(const char **) b;
   
-  return g_strcmp0(c, d);
+  return strcmp(c, d);
 }
 
+#ifdef G_OS_WIN32 /* g_file_test is too slow on Windows */
+gint count_items(gchar *romdir, gint n_items, gboolean recursive)
+{
+  WIN32_FIND_DATA FindFileData;
+
+  gchar *romdir2 = g_strconcat(romdir, G_DIR_SEPARATOR_S, "*", NULL);
+  HANDLE hFind = FindFirstFile(romdir2, &FindFileData);
+  
+  while (hFind != INVALID_HANDLE_VALUE)
+  {
+    if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+    {
+      if (recursive && (0 != strcmp (FindFileData.cFileName, ".") 
+        && 0 != strcmp (FindFileData.cFileName, "..")))
+      {
+          gchar *testdir = g_strconcat(romdir, G_DIR_SEPARATOR_S, FindFileData.cFileName, NULL);
+          n_items = count_items(testdir, n_items, TRUE);
+          g_free(testdir);
+      }
+	}
+    else n_items++;
+    
+    if (!FindNextFile(hFind, &FindFileData))
+    {
+      FindClose(hFind);
+      hFind = INVALID_HANDLE_VALUE;
+    }
+  }
+  g_free(romdir2);  
+  return n_items;
+}
+
+gint scan_files(gchar *romdir, gchar **list, gint i, gboolean recursive)
+{
+  WIN32_FIND_DATA FindFileData;
+
+  gchar *romdir2 = g_strconcat(romdir, G_DIR_SEPARATOR_S, "*", NULL);
+  HANDLE hFind = FindFirstFile(romdir2, &FindFileData);
+
+  while (hFind != INVALID_HANDLE_VALUE)
+  {
+    gchar *testdir = g_strconcat(romdir, G_DIR_SEPARATOR_S, FindFileData.cFileName, NULL);
+    if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
+    {
+      if (recursive && (0 != strcmp(FindFileData.cFileName, ".") 
+        && 0 != strcmp (FindFileData.cFileName, "..")))
+      {
+        i = scan_files(testdir, list, i, TRUE);
+      }
+    }
+    else
+    {
+      list[i] = g_strconcat(FindFileData.cFileName, G_DIR_SEPARATOR_S, 
+                            testdir, NULL);    
+      i++;
+    }
+    g_free(testdir);
+    
+    if (!FindNextFile(hFind, &FindFileData))
+    {
+      FindClose(hFind);
+      hFind = INVALID_HANDLE_VALUE;
+    }
+  }
+  g_free(romdir2);
+  return i;
+}
+
+#else
+
 gint count_items(gchar *romdir, gint n_items, gboolean recursive)
 {
   GDir *dir = NULL;
@@ -177,7 +251,6 @@ gint count_items(gchar *romdir, gint n_items, gboolean recursive)
     }
   g_dir_close(dir); 
   }
-  
   return n_items;
 }
 
@@ -214,6 +287,8 @@ gint scan_files(gchar *romdir, gchar **list, gint i, gboolean recursive)
   return i;
 }
 
+#endif
+
 void populate_list(guidata *gui)
 {
   GtkTreeIter iter;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/mednaffe.git



More information about the Pkg-games-commits mailing list