/* Check wether it's an image we want */ static gboolean is_front_cover_image (const gchar * file) { gchar * include = get_string (NULL, "cover_name_include"); gchar * exclude = get_string (NULL, "cover_name_include"); gboolean accept = cover_name_filter (file, include, TRUE) && ! cover_name_filter (file, exclude, FALSE); g_free (include); g_free (exclude); return accept; }
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; }