static void list_resource (GResource *resource, const gchar *path, const gchar *section, const gchar *prefix, gboolean details) { gchar **children; gsize size; guint32 flags; gint i; gchar *child; GError *error = NULL; gint len; children = g_resource_enumerate_children (resource, path, 0, &error); if (error) { g_printerr ("%s\n", error->message); g_error_free (error); return; } for (i = 0; children[i]; i++) { child = g_strconcat (path, children[i], NULL); len = MIN (strlen (child), strlen (prefix)); if (strncmp (child, prefix, len) != 0) { g_free (child); continue; } if (g_resource_get_info (resource, child, 0, &size, &flags, NULL)) { if (details) g_print ("%s%s%6"G_GSIZE_FORMAT " %s %s\n", section, section[0] ? " " : "", size, flags & G_RESOURCE_FLAGS_COMPRESSED ? "c" : "u", child); else g_print ("%s\n", child); } else list_resource (resource, child, section, prefix, details); g_free (child); } g_strfreev (children); }
/** * g_resources_get_info: * @path: A pathname inside the resource * @lookup_flags: A #GResourceLookupFlags * @size: (out) (allow-none): a location to place the length of the contents of the file, * or %NULL if the length is not needed * @flags: (out) (allow-none): a location to place the flags about the file, * or %NULL if the length is not needed * @error: return location for a #GError, or %NULL * * Looks for a file at the specified @path in the set of * globally registered resources and if found returns information about it. * * @lookup_flags controls the behaviour of the lookup. * * Returns: %TRUE if the file was found. %FALSE if there were errors * * Since: 2.32 **/ gboolean g_resources_get_info (const gchar *path, GResourceLookupFlags lookup_flags, gsize *size, guint32 *flags, GError **error) { gboolean res = FALSE; GList *l; gboolean r_res; register_lazy_static_resources (); g_rw_lock_reader_lock (&resources_lock); for (l = registered_resources; l != NULL; l = l->next) { GResource *r = l->data; GError *my_error = NULL; r_res = g_resource_get_info (r, path, lookup_flags, size, flags, &my_error); if (!r_res && g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND)) { g_clear_error (&my_error); } else { if (!r_res) g_propagate_error (error, my_error); res = r_res; break; } } if (l == NULL) g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), path); g_rw_lock_reader_unlock (&resources_lock); return res; }