From a9fbc74b0b3ab2eee9981688755fabceb06520d7 Mon Sep 17 00:00:00 2001 From: Hiro Date: Fri, 23 Jun 2006 14:20:27 +0000 Subject: win32: optimized scanning of directory. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1084 ee746299-78ed-0310-b773-934348b2243d --- libsylph/mh.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'libsylph/mh.c') diff --git a/libsylph/mh.c b/libsylph/mh.c index 99e87cb6..67c87595 100644 --- a/libsylph/mh.c +++ b/libsylph/mh.c @@ -32,6 +32,10 @@ #include #include +#ifdef G_OS_WIN32 +# include +#endif + #undef MEASURE_TIME #include "folder.h" @@ -740,8 +744,9 @@ static gint mh_scan_folder_full(Folder *folder, FolderItem *item, { gchar *path; #ifdef G_OS_WIN32 - GDir *dir; - const gchar *dir_name; + WIN32_FIND_DATAW wfd; + HANDLE hfind; + gchar *dir_name; #else DIR *dp; struct dirent *d; @@ -763,7 +768,7 @@ static gint mh_scan_folder_full(Folder *folder, FolderItem *item, g_free(path); #ifdef G_OS_WIN32 - if ((dir = g_dir_open(".", 0, NULL)) == NULL) { + if ((hfind = FindFirstFileW(L"*", &wfd)) == INVALID_HANDLE_VALUE) { g_warning("failed to open directory\n"); #else if ((dp = opendir(".")) == NULL) { @@ -776,16 +781,23 @@ static gint mh_scan_folder_full(Folder *folder, FolderItem *item, folder->ui_func(folder, item, folder->ui_func_data); #ifdef G_OS_WIN32 - while ((dir_name = g_dir_read_name(dir)) != NULL) { - if ((num = to_number(dir_name)) > 0 && - g_file_test(dir_name, G_FILE_TEST_IS_REGULAR)) { - n_msg++; - if (max < num) - max = num; + do { + if ((wfd.dwFileAttributes & + (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0) { + dir_name = g_utf16_to_utf8(wfd.cFileName, -1, + NULL, NULL, NULL); + if (dir_name) { + if ((num = to_number(dir_name)) > 0) { + n_msg++; + if (max < num) + max = num; + } + g_free(dir_name); + } } - } + } while (FindNextFileW(hfind, &wfd)); - g_dir_close(dir); + FindClose(hfind); #else while ((d = readdir(dp)) != NULL) { if ((num = to_number(d->d_name)) > 0 && @@ -821,7 +833,7 @@ static gint mh_scan_folder_full(Folder *folder, FolderItem *item, item->updated = TRUE; item->mtime = 0; - debug_print(_("Last number in dir %s = %d\n"), item->path, max); + debug_print("Last number in dir %s = %d\n", item->path, max); item->last_num = max; return 0; -- cgit v1.2.3