+static int export(struct upkg *pkg, GObject *obj, unsigned idx)
+{
+ char name[256];
+ FILE *of;
+
+ if (uobject_deserialize(obj, pkg, idx) != 0) {
+ return -1;
+ }
+
+ if (UOBJECT_IS_LOADABLE(obj) && uobject_load(obj) != 0) {
+ return -1;
+ }
+
+ uobject_export_name(obj, name, sizeof name);
+
+ printf("exporting %s to %s\n", upkg_export_name(pkg, idx), name);
+ of = fopen(name, "wb");
+ if (!of) {
+ perror(name);
+ return -1;
+ }
+
+ uobject_export(obj, of);
+
+ if (fclose(of) != 0) {
+ perror(name);
+ return -1;
+ }
+
+ if (UOBJECT_IS_LOADABLE(obj)) {
+ uobject_unload(obj);
+ }
+
+ return 0;
+}
+
+int package_export(struct upkg *pkg)
+{
+ const char *class, *package;
+ GObject *obj;
+ GType type;
+ int rc = EXIT_SUCCESS;
+
+ for (unsigned i = 0; i < pkg->export_count; i++) {
+ class = upkg_export_class(pkg, i, &package);
+ if (!class) {
+ fprintf(stderr, "error getting class information.\n");
+ return EXIT_FAILURE;
+ }
+
+ type = uobject_module_get_class(package, class);
+ if (!type) continue;
+
+ obj = g_object_new(type, NULL);
+ if (UOBJECT_IS_EXPORTABLE(obj)) {
+ if (export(pkg, obj, i) != 0) {
+ rc = EXIT_FAILURE;
+ }
+ }
+ g_object_unref(obj);
+ }
+
+ return rc;
+}
+