static void registerGResource(void) { GOwnPtr<char> resourcesPath(g_build_filename(WEBKIT_EXEC_PATH, "TestWebKitAPI", "WebKit2Gtk", "resources", "webkit2gtk-tests-resources.gresource", NULL)); GResource* resource = g_resource_load(resourcesPath.get(), 0); g_assert(resource); g_resources_register(resource); g_resource_unref(resource); }
/** \brief Intialize the GResource binary blob handling * * First tries to load from src/arch/gtk3/data and then from VICEDIR/data. * Loading from VICEDIR/data will fail, the vice.gresource file doesn't get * copied there yet with a make install, nor does the VICEDIR/data dir exist. * * \return bool */ int uidata_init(void) { GError *err = NULL; #ifdef HAVE_DEBUG_GTK3UI char **files; int i; #endif char *path; char *dir; /* try directory with VICE's data files */ dir = archdep_get_vice_datadir(); debug_gtk3("trying archdep_get_vice_datadir() (%s).", dir); path = archdep_join_paths(dir, "vice.gresource", NULL); lib_free(dir); gresource = g_resource_load(path, &err); if (gresource == NULL && err != NULL) { debug_gtk3("failed to load resource data '%s': %s.", path, err->message); g_clear_error(&err); lib_free(path); return 0; } lib_free(path); g_resources_register(gresource); /* debugging: show files in the resource blob */ #ifdef HAVE_DEBUG_GTK3UI files = g_resource_enumerate_children( gresource, UIDATA_ROOT_PATH, G_RESOURCE_LOOKUP_FLAGS_NONE, &err); if (files == NULL && err != NULL) { debug_gtk3("couldn't enumerate children: %s.", err->message); g_clear_error(&err); return 0; } debug_gtk3("Listing files in the GResource file:"); for (i = 0; files[i] != NULL; i++) { debug_gtk3("%d: %s.", i, files[i]); } #endif return 1; }
static void ide_application_plugins_load_plugin_gresources (IdeApplication *self, PeasPluginInfo *plugin_info, PeasEngine *engine) { g_autofree gchar *gresources_path = NULL; g_autofree gchar *gresources_basename = NULL; const gchar *module_dir; const gchar *module_name; g_assert (IDE_IS_APPLICATION (self)); g_assert (plugin_info != NULL); g_assert (PEAS_IS_ENGINE (engine)); module_dir = peas_plugin_info_get_module_dir (plugin_info); module_name = peas_plugin_info_get_module_name (plugin_info); gresources_basename = g_strdup_printf ("%s.gresource", module_name); gresources_path = g_build_filename (module_dir, gresources_basename, NULL); if (g_file_test (gresources_path, G_FILE_TEST_IS_REGULAR)) { g_autoptr(GError) error = NULL; GResource *resource; resource = g_resource_load (gresources_path, &error); if (resource == NULL) { g_warning ("Failed to load gresources: %s", error->message); return; } g_hash_table_insert (self->plugin_gresources, g_strdup (module_name), resource); g_resources_register (resource); } }