+void print_upkg_exports(struct upkg *pkg)
+{
+ for (unsigned i = 0; i < pkg->export_count; i++) {
+ const char *name, *package, *class;
+
+ name = upkg_export_name(pkg, i);
+ class = upkg_export_class(pkg, i, &package);
+
+ if (!name || !class)
+ continue;
+
+ printf("%u - %s (%s.%s)\n", i+1, name, package, class);
+ }
+}
+
+int package_info(struct upkg *pkg)
+{
+ printf("Version: %u\n", pkg->version);
+ printf("License: %u\n", pkg->license);
+ printf("GUID: ");
+ print_guid(pkg->guid);
+
+ printf("Flags: %lx\n", pkg->flags);
+ if (verbose >= 1) {
+ print_upkg_flags("\t", pkg->flags);
+ }
+
+ if (verbose >= 1) {
+ printf("Names: %lu\n", pkg->name_count);
+ if (verbose >= 2) {
+ for (unsigned long i = 0; i < pkg->name_count; i++) {
+ printf("\t%s\n", upkg_get_name(pkg, i));
+ }
+ }
+ }
+
+ printf("Exports: %lu\n", pkg->export_count);
+ if (verbose >= 1) print_upkg_exports(pkg);
+ printf("Imports: %lu\n", pkg->import_count);
+
+ return EXIT_SUCCESS;
+}
+
+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;
+}
+