static GFileEnumerator * _g_resource_file_enumerator_new (GResourceFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GResourceFileEnumerator *resource; char **children; gboolean res; children = g_resources_enumerate_children (file->path, 0, NULL); if (children == NULL && strcmp ("/", file->path) != 0) { res = g_resources_get_info (file->path, 0, NULL, NULL, NULL); if (res) g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The resource at '%s' is not a directory"), file->path); else g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), file->path); return NULL; } resource = g_object_new (G_TYPE_RESOURCE_FILE_ENUMERATOR, "container", file, NULL); resource->children = children; resource->path = g_strdup (file->path); resource->attributes = g_strdup (attributes); resource->flags = flags; return G_FILE_ENUMERATOR (resource); }
static void fr_application_register_archive_manager_service (FrApplication *self) { gsize size; guchar *buffer; GInputStream *stream; gsize bytes_read; GError *error = NULL; g_application_hold (G_APPLICATION (self)); g_resources_get_info (ORG_GNOME_ARCHIVEMANAGER_XML, 0, &size, NULL, NULL); buffer = g_new (guchar, size + 1); stream = g_resources_open_stream (ORG_GNOME_ARCHIVEMANAGER_XML, 0, NULL); if (g_input_stream_read_all (stream, buffer, size, &bytes_read, NULL, NULL)) { buffer[bytes_read] = '\0'; self->introspection_data = g_dbus_node_info_new_for_xml ((gchar *) buffer, &error); if (self->introspection_data != NULL) { self->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.gnome.ArchiveManager1", G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired_for_archive_manager, NULL /*on_name_acquired*/, NULL /*on_name_lost*/, self, NULL); } else { g_warning ("%s", error->message); g_clear_error (&error); } } g_timeout_add_seconds (SERVICE_TIMEOUT, service_timeout_cb, self); g_free (buffer); }
gboolean seed_file_test(const gchar* path, GFileTest test) { // XXX: This is a nasty hack. what we should do is probably // to check for GResource children in a given path and // then return TRUE if any children exists for that path gboolean exists = FALSE; gboolean isdir = FALSE; if (g_str_has_prefix(path, "/org/seed")) { if (g_strcmp0(path, "/org/seed") == 0 || g_strcmp0(path, "/org/seed/extensions") == 0 || g_strcmp0(path, "/org/seed/extensions/gjs") == 0) { isdir = TRUE; exists = TRUE; } else if (g_resources_get_info(path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL)) { isdir = FALSE; exists = TRUE; } // Return only if file is in GResource. // Otherwise fallback to g_file_test if (exists) { if (test & G_FILE_TEST_EXISTS) return TRUE; if (test & G_FILE_TEST_IS_REGULAR) if (!isdir) return !isdir; if (test & G_FILE_TEST_IS_DIR) if (isdir) return isdir; } } return g_file_test(path, test); }
static void ephy_resource_request_cb (WebKitURISchemeRequest *request) { const char *path; GInputStream *stream; gsize size; GError *error = NULL; path = webkit_uri_scheme_request_get_path (request); if (!g_resources_get_info (path, 0, &size, NULL, &error)) { webkit_uri_scheme_request_finish_error (request, error); g_error_free (error); return; } stream = g_resources_open_stream (path, 0, &error); if (stream) { webkit_uri_scheme_request_finish (request, stream, size, NULL); g_object_unref (stream); } else { webkit_uri_scheme_request_finish_error (request, error); g_error_free (error); } }
static GFileInfo * g_resource_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GResourceFile *resource = G_RESOURCE_FILE (file); GError *my_error = NULL; GFileInfo *info; GFileAttributeMatcher *matcher; gboolean res; gsize size; guint32 resource_flags; char **children; gboolean is_dir; char *base; is_dir = FALSE; children = g_resources_enumerate_children (resource->path, 0, NULL); if (children != NULL) { g_strfreev (children); is_dir = TRUE; } /* root is always there */ if (strcmp ("/", resource->path) == 0) is_dir = TRUE; if (!is_dir) { res = g_resources_get_info (resource->path, 0, &size, &resource_flags, &my_error); if (!res) { if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), resource->path); } else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, my_error->message); g_clear_error (&my_error); return FALSE; } } matcher = g_file_attribute_matcher_new (attributes); info = g_file_info_new (); base = g_resource_file_get_basename (file); g_file_info_set_name (info, base); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH, FALSE); if (is_dir) { g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); } else { GBytes *bytes; char *content_type; g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); g_file_info_set_size (info, size); if ((_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) || ((~resource_flags & G_RESOURCE_FLAGS_COMPRESSED) && _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))) && (bytes = g_resources_lookup_data (resource->path, 0, NULL))) { const guchar *data; gsize data_size; data = g_bytes_get_data (bytes, &data_size); content_type = g_content_type_guess (base, data, data_size, NULL); g_bytes_unref (bytes); } else content_type = NULL; if (content_type) { _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE, content_type); _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type); g_free (content_type); } } g_free (base); g_file_attribute_matcher_unref (matcher); return info; }
/** * locate a resource * * The way GTK accesses resource files has changed greatly between * releases. This initilises the interface that hides all the * implementation details from the rest of the code. * * If the GResource is not enabled or the item cannot be found in the * compiled in resources the files will be loaded directly from disc * instead. * * \param respath A string vector containing the valid resource search paths * \param resource A resource entry to initialise */ static nserror init_resource(char **respath, struct nsgtk_resource_s *resource) { char *resname; #ifdef WITH_GRESOURCE int resnamelen; gboolean present; const gchar * const *langv; int langc = 0; langv = g_get_language_names(); while (langv[langc] != NULL) { resnamelen = snprintf(NULL, 0, "/org/netsurf/%s/%s", langv[langc], resource->name); resname = malloc(resnamelen + 1); if (resname == NULL) { return NSERROR_NOMEM; } snprintf(resname, resnamelen + 1, "/org/netsurf/%s/%s", langv[langc], resource->name); present = g_resources_get_info(resname, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL); if (present == TRUE) { /* found an entry in the resources */ resource->path = resname; resource->type = NSGTK_RESOURCE_GLIB; LOG("Found gresource path %s", resource->path); return NSERROR_OK; } /*LOG("gresource \"%s\" not found", resname);*/ free(resname); langc++; } resnamelen = snprintf(NULL, 0, "/org/netsurf/%s", resource->name); resname = malloc(resnamelen + 1); if (resname == NULL) { return NSERROR_NOMEM; } snprintf(resname, resnamelen + 1, "/org/netsurf/%s", resource->name); present = g_resources_get_info(resname, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL); if (present == TRUE) { /* found an entry in the resources */ resource->path = resname; resource->type = NSGTK_RESOURCE_GLIB; LOG("Found gresource path %s", resource->path); return NSERROR_OK; } /*LOG("gresource \"%s\" not found", resname);*/ free(resname); #endif resname = filepath_find(respath, resource->name); if (resname == NULL) { LOG("Unable to find resource %s on resource path", resource->name); return NSERROR_NOT_FOUND; } /* found an entry on the path */ resource->path = resname; resource->type = NSGTK_RESOURCE_FILE; LOG("Found file resource path %s", resource->path); return NSERROR_OK; }