void checkdms(GtkListStore *store) { PM_DB *db; GtkTreeIter iter; if(pacman_initialize(TARGETDIR)==-1) return; if(!(db = pacman_db_register("local"))) { pacman_release(); return; } gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, "XDM", 1, _(" X Window Display Manager"), -1); if(pacman_db_readpkg(db, "kdebase")) { gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, "KDM", 1, _(" KDE Display Manager"), -1); } if(pacman_db_readpkg(db, "gdm")) { gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, "GDM", 1, _(" Gnome Display Manager"), -1); } if(pacman_db_readpkg(db, "slim")) { gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, "Slim", 1, _(" Simple Login Manager"), -1); } pacman_db_unregister(db); pacman_release(); return; }
int gfpm_db_populate_repolist (void) { if (dblist != NULL) { /* if the dblist is already populated, the repos are already registered. Hence, to repopulate the dblist, we need to release and re-initialize libpacman or else it won't work */ pacman_release (); pacman_initialize ("/"); dblist = NULL; } /* get the list of usable repositories */ if (pacman_parse_config (CFG_FILE, _db_callback, "") == -1) { return 1; } return 0; }
int main (int argc, char *argv[]) { gchar *path; char *tmp = NULL; int opt; int longopt_index; int arg = 0; GError *error = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* parse command-line arguments */ static struct option long_options[] = { {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'v'}, {"add", 1, NULL, 'A'}, {NULL, 0, NULL, 0} }; while ((opt = getopt_long(argc, argv, "hvA:", long_options, &longopt_index)) > 0) { switch (opt) { case 'v': tmp = g_strdup_printf ("%s version %s (%s)\n", g_ascii_strdown(PACKAGE,strlen(PACKAGE)), VERSION, GFPM_RELEASE_NAME); fprintf (stdout, tmp); g_free (tmp); return 0; case 'A': if (optarg) { tmp = g_strdup (optarg); arg |= ARG_ADD; } break; case 'h': default: fprintf(stderr, "usage: %s [options]\n", basename(argv[0])); fprintf(stderr, " -A, --add <file> install a package from file\n"); fprintf(stderr, " -h, --help display this help\n"); fprintf(stderr, " -v, --version version information\n"); return 1; } } /* invite trouble */ g_thread_init (NULL); /* initialize internal gdk threads mutex */ gdk_threads_init (); gtk_init (&argc, &argv); gdk_threads_enter (); path = g_strdup_printf ("%s%s", PREFIX, UI_FILE); gb = gtk_builder_new (); if (!gtk_builder_add_from_file(gb, path, &error)) { gchar *msg = g_strdup_printf ("%s\n\n%s", _("Failed to initialize interface due to the following error(s) in gfpm.ui:"), error->message); gfpm_error (_("Interface initialization Failed"), msg); g_free (msg); return 1; } g_free (path); gtk_builder_connect_signals (gb, NULL); if (pacman_initialize ("/") == -1) { gfpm_error (_("Error initializing libpacman"), _("Failed to initialize libpacman")); return 1; } /* initialize configuration subsystem */ gfpm_config_init (); /* initialize everything else */ gfpm_interface_init (arg, (void*)tmp); /* the main loop */ gtk_main (); /* phew */ gdk_threads_leave (); gfpm_db_cleanup (); gfpm_config_free (); gfpm_prefs_cleanup (); pacman_release (); return 0; }
int install_pkgs(GList *pkgs) { int i = 0, questret; PM_LIST *pdata = NULL, *pkgsl; char *ptr, *file; /* nothing to install */ if(pkgs == NULL) return 0; if(pacman_initialize(TARGETDIR) == -1) { LOG("Failed to initialize pacman library (%s)\n", pacman_strerror(pm_errno)); return -1; } if (pacman_parse_config("/etc/pacman-g2.conf", NULL, "") == -1) { LOG("Failed to parse pacman-g2 configuration file (%s)", pacman_strerror(pm_errno)); pacman_release(); return(-1); } //* Set pacman options *// #ifndef NDEBUG pacman_set_option(PM_OPT_LOGMASK, -1); #else pacman_set_option(PM_OPT_LOGMASK, PM_LOG_ERROR | PM_LOG_WARNING); #endif pacman_set_option(PM_OPT_LOGCB, (long)cb_log); pacman_set_option (PM_OPT_DLCB, (long)progress_update); pacman_set_option (PM_OPT_DLOFFSET, (long)&offset); pacman_set_option (PM_OPT_DLRATE, (long)&rate); pacman_set_option (PM_OPT_DLFNM, (long)reponame); pacman_set_option (PM_OPT_DLHOWMANY, (long)&howmany); pacman_set_option (PM_OPT_DLREMAIN, (long)&remains); pacman_set_option (PM_OPT_DLT0, (long)&t0); pacman_set_option (PM_OPT_DLT0, (long)&t); pacman_set_option (PM_OPT_DLXFERED1, (long)&xferred1); PM_DB *db_local = pacman_db_register("local"); if(db_local == NULL) { LOG("Could not register 'local' database (%s)\n", pacman_strerror(pm_errno)); pacman_release(); return -1; } retry: if(pacman_trans_init(PM_TRANS_TYPE_SYNC, PM_TRANS_FLAG_FORCE|PM_TRANS_FLAG_NODEPS, progress_event, progress_conv, progress_install) == -1) { if (pm_errno == PM_ERR_HANDLE_LOCK) { file = g_strdup_printf("%s/tmp/pacman-g2.lck", TARGETDIR); g_remove (file); free(file); goto retry; } LOG("Failed to initialize transaction %s\n", pacman_strerror (pm_errno)); pacman_release(); return -1; } for (i = 0; i<g_list_length(pkgs); i++) { ptr = strdup((char*)g_list_nth_data(pkgs, i)); if(pacman_trans_addtarget(strdup(drop_version(ptr))) == -1) LOG("Error adding packet %s", pacman_strerror (pm_errno)); free(ptr); } //* prepare transaction *// if(pacman_trans_prepare(&pdata) == -1) { LOG("Failed to prepare transaction (%s)", pacman_strerror (pm_errno)); pacman_list_free(pdata); pacman_trans_release(); pacman_release(); return -1; } pkgsl = pacman_trans_getinfo (PM_TRANS_PACKAGES); if (pkgsl == NULL) { LOG("Error getting transaction info %s\n", pacman_strerror (pm_errno)); pacman_trans_release(); pacman_release(); return -1; } /* commit transaction */ if (pacman_trans_commit(&pdata) == -1) { switch(pm_errno) { case PM_ERR_DISK_FULL: fwife_error(_("Disk full, cannot install more packages")); break; case PM_ERR_PKG_CORRUPTED: questret = fwife_question(_("Some packages seems corrupted, do you want to download them again?")); if(questret == GTK_RESPONSE_YES) { pacman_list_free(pdata); pacman_trans_release(); goto retry; } break; case PM_ERR_RETRIEVE: fwife_error(_("Failed to retrieve packages")); break; default: break; } LOG("Failed to commit transaction (%s)\n", pacman_strerror (pm_errno)); pacman_list_free(pdata); pacman_trans_release(); pacman_release(); return -1; } /* release the transaction */ pacman_trans_release(); pacman_release(); return 0; }