static char * fileinfo_recursive_get_image (const char * path, const SearchParams * params, int depth) { DIR * d = opendir (path); if (! d) return NULL; struct dirent * entry; if (get_bool (NULL, "use_file_cover") && ! depth) { /* Look for images matching file name */ while ((entry = readdir (d))) { if (entry->d_name[0] == '.') continue; char * newpath = filename_build (path, entry->d_name); if (! g_file_test (newpath, G_FILE_TEST_IS_DIR) && has_front_cover_extension (entry->d_name) && is_file_image (entry->d_name, params->basename)) { closedir (d); return newpath; } str_unref (newpath); } rewinddir (d); } /* Search for files using filter */ while ((entry = readdir (d))) { if (entry->d_name[0] == '.') continue; char * newpath = filename_build (path, entry->d_name); if (! g_file_test (newpath, G_FILE_TEST_IS_DIR) && has_front_cover_extension (entry->d_name) && cover_name_filter (entry->d_name, params->include, TRUE) && ! cover_name_filter (entry->d_name, params->exclude, FALSE)) { closedir (d); return newpath; } str_unref (newpath); } rewinddir (d); if (get_bool (NULL, "recurse_for_cover") && depth < get_int (NULL, "recurse_for_cover_depth")) { /* Descend into directories recursively. */ while ((entry = readdir (d))) { if (entry->d_name[0] == '.') continue; char * newpath = filename_build (path, entry->d_name); if (g_file_test (newpath, G_FILE_TEST_IS_DIR)) { char * tmp = fileinfo_recursive_get_image (newpath, params, depth + 1); if (tmp) { str_unref (newpath); closedir (d); return tmp; } } str_unref (newpath); } } closedir (d); return NULL; }
static gchar * fileinfo_recursive_get_image (const gchar * path, const gchar * file_name, gint depth) { GDir *d; if (get_bool (NULL, "recurse_for_cover") && depth > get_int (NULL, "recurse_for_cover_depth")) return NULL; d = g_dir_open(path, 0, NULL); if (d) { const gchar *f; if (get_bool (NULL, "use_file_cover") && file_name) { /* Look for images matching file name */ while((f = g_dir_read_name(d))) { gchar *newpath = g_strconcat(path, "/", f, NULL); if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) && has_front_cover_extension(f) && is_file_image(f, file_name)) { g_dir_close(d); return newpath; } g_free(newpath); } g_dir_rewind(d); } /* Search for files using filter */ while ((f = g_dir_read_name(d))) { gchar *newpath = g_strconcat(path, "/", f, NULL); if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) && has_front_cover_extension(f) && is_front_cover_image(f)) { g_dir_close(d); return newpath; } g_free(newpath); } g_dir_rewind(d); /* checks whether recursive or not. */ if (! get_bool (NULL, "recurse_for_cover")) { g_dir_close(d); return NULL; } /* Descend into directories recursively. */ while ((f = g_dir_read_name(d))) { gchar *newpath = g_strconcat(path, "/", f, NULL); if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) { gchar *tmp = fileinfo_recursive_get_image(newpath, NULL, depth + 1); if(tmp) { g_free(newpath); g_dir_close(d); return tmp; } } g_free(newpath); } g_dir_close(d); } return NULL; }