int main(int argc, char *argv[]) { //GtkWidget *window, *ok_but, *fix_but, *diag, *list, *scroll; //GtkAdjustment *adj; product_component_t *component; product_option_t *option; product_file_t *file; int removed = 0, modified = 0; char productname[1024]; Res = carbon_LoadCarbonRes(OnCommandEvent, OnKeyboardEvent); // If running from an APP bundle in Carbon, it passed -p*** as the first argument // This code effectively cuts out argv[1] as though it wasn't specified if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'p') { // Move the first argument to overwite the second argv[1] = argv[0]; // Set our arguments starting point to the second argumement argv++; argv[1] = productname; //argc--; carbon_Prompt(Res, PromptType_OK, "Please enter product name you wish to check: ", productname, 1024); fprintf(stderr, "product = '%s'\n", productname); fprintf(stderr, "argv[0] = '%s'\n", argv[0]); fprintf(stderr, "argv[1] = '%s'\n", argv[1]); } goto_installpath(argv[0]); // Set the locale init_locale(); if ( argc < 2 ) { fprintf(stderr, _("Usage: %s product\n"), argv[0]); return 1; } //gtk_init(&argc,&argv); // Load resource data // Show the uninstall screen carbon_ShowInstallScreen(Res, CHECK_PAGE); argv0 = argv[0]; product = loki_openproduct(argv[1]); if ( ! product ) { carbon_Prompt(Res, PromptType_OK, _("Impossible to locate the product information.\nMaybe another user installed it?"), NULL, 0); return 1; } info = loki_getinfo_product(product); carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, ""); carbon_DisableControl(Res, CHECK_RESCUE_BUTTON_ID); // Iterate through the components for ( component = loki_getfirst_component(product); component; component = loki_getnext_component(component) ) { add_message(_("---> Checking component '%s'..."), loki_getname_component(component)); for ( option = loki_getfirst_option(component); option; option = loki_getnext_option(option) ) { add_message(_("-> Checking option '%s'..."), loki_getname_option(option)); for ( file = loki_getfirst_file(option); file; file = loki_getnext_file(file) ) { carbon_HandlePendingEvents(Res); switch ( loki_check_file(file) ) { case LOKI_REMOVED: add_message(_("%s was REMOVED"), loki_getpath_file(file)); removed ++; add_corrupt_file(product, loki_getpath_file(file), loki_getname_option(option)); break; case LOKI_CHANGED: add_message(_("%s was MODIFIED"), loki_getpath_file(file)); modified ++; add_corrupt_file(product, loki_getpath_file(file), loki_getname_option(option)); break; case LOKI_OK: add_message(_("%s is OK"), loki_getpath_file(file)); break; } } } } if ( removed || modified ) { char status[200]; snprintf(status, sizeof(status), _("Changes detected: %d files removed, %d files modified."), removed, modified); carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, status); carbon_EnableControl(Res, CHECK_RESCUE_BUTTON_ID); } else { carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("No problems were found.")); } // Wait for user input carbon_IterateForState(Res, &AppDone); return 0; }
/* Run a GUI to select and uninstall products */ int uninstall_ui(int argc, char *argv[]) { GtkWidget *window; GtkWidget *widget; GtkWidget *frame; GtkWidget *vbox; GtkWidget *button; GtkWidget *label; const char *product_name; product_t *product; product_info_t *product_info; product_component_t *component; component_list *component_list, *addon_list; char text[1024]; #ifdef ENABLE_GTK2 // Turn off any themes setenv("GTK2_RC_FILES", "", 1); setenv("GTK_DATA_PREFIX", "", 1); #endif gtk_init(&argc,&argv); /* Disable GLib warnings that may be triggered by libglade */ g_log_set_handler ("libglade", G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION, log_handler, NULL); /* Initialize Glade */ glade_init(); uninstall_glade = GLADE_XML_NEW(DATADIR "/" UNINSTALL_GLADE, "loki_uninstall"); /* Add all signal handlers defined in glade file */ glade_xml_signal_autoconnect(uninstall_glade); /* Make sure the window is visible */ widget = glade_xml_get_widget(uninstall_glade, "uninstall_button"); if ( widget ) { gtk_button_set_sensitive(widget, FALSE); } window = glade_xml_get_widget(uninstall_glade, "loki_uninstall"); gtk_widget_realize(window); while( gtk_events_pending() ) { gtk_main_iteration(); } /* Add emergency signal handlers */ signal(SIGHUP, main_signal_abort); signal(SIGINT, main_signal_abort); signal(SIGQUIT, main_signal_abort); signal(SIGTERM, main_signal_abort); /* Fill in the list of products and components */ widget = glade_xml_get_widget(uninstall_glade, "uninstall_vbox"); if ( ! widget ) { fprintf(stderr, _("No uninstall_vbox in glade file!\n")); return(-1); } gtk_container_foreach(GTK_CONTAINER(widget), empty_container, widget); for ( product_name=loki_getfirstproduct(); product_name; product_name=loki_getnextproduct() ) { /* See if we can open the product */ product = loki_openproduct(product_name); if ( ! product ) { continue; } /* See if we have permissions to remove the product */ product_info = loki_getinfo_product(product); if ( ! check_permissions(product_info, 0) ) { loki_closeproduct(product); continue; } /* Add the product and components to our list */ strncpy(text, product_info->description, sizeof(text)); frame = gtk_frame_new(text); gtk_container_set_border_width(GTK_CONTAINER(frame), 4); gtk_box_pack_start(GTK_BOX(widget), frame, FALSE, TRUE, 0); gtk_widget_show(frame); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show(vbox); component = loki_getdefault_component(product); component_list = NULL; if ( component ) { component_list = create_component_list(product, product_info, component); strncpy(text, _("Complete uninstall"), sizeof(text)); button = gtk_check_button_new_with_label(text); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(component_toggled_slot), (gpointer)component_list); gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)component_list); gtk_widget_show(button); } for ( component = loki_getfirst_component(product); component; component = loki_getnext_component(component) ) { if ( loki_isdefault_component(component) ) { continue; } addon_list = create_component_list(product, product_info, component); strncpy(text, loki_getname_component(component), sizeof(text)); button = gtk_check_button_new_with_label(text); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(component_toggled_slot), (gpointer)addon_list); gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)addon_list); gtk_widget_show(button); add_component_list(component_list, button); } /* Add this product to our list of open products */ add_product(product); } /* Check to make sure there's something to uninstall */ if ( ! product_list ) { label = gtk_label_new( _("No products were installed by this user.\n" "You may need to run this tool as an administrator.")); gtk_box_pack_start(GTK_BOX(widget), label, FALSE, TRUE, 0); gtk_widget_show(label); } /* Run the UI.. */ gtk_main(); /* Close all the products and return */ close_products(0); return 0; }
int main(int argc, char *argv[]) { GtkWidget *window, *ok_but, *fix_but, *diag, *list, *scroll; GtkAdjustment *adj; product_component_t *component; product_option_t *option; product_file_t *file; int removed = 0, modified = 0; goto_installpath(argv[0]); /* Set the locale */ init_locale(); if ( argc < 2 ) { fprintf(stderr, _("Usage: %s product\n"), argv[0]); return 1; } gtk_init(&argc,&argv); argv0 = argv[0]; /* Initialize Glade */ glade_init(); check_glade = glade_xml_new("check.glade", "check_dialog"); /* Add all signal handlers defined in glade file */ glade_xml_signal_autoconnect(check_glade); window = glade_xml_get_widget(check_glade, "check_dialog"); gtk_widget_realize(window); while( gtk_events_pending() ) { gtk_main_iteration(); } diag = glade_xml_get_widget(check_glade, "diagnostic_label"); ok_but = glade_xml_get_widget(check_glade, "dismiss_button"); fix_but = glade_xml_get_widget(check_glade, "rescue_button"); list = glade_xml_get_widget(check_glade, "main_list"); scroll = glade_xml_get_widget(check_glade, "scrolledwindow"); product = loki_openproduct(argv[1]); if ( ! product ) { message_dialog(_("Impossible to locate the product information.\nMaybe another user installed it?"), _("Error")); return 1; } info = loki_getinfo_product(product); gtk_label_set_text(GTK_LABEL(diag), ""); gtk_widget_set_sensitive(fix_but, FALSE); adj = GTK_ADJUSTMENT(gtk_adjustment_new(100.0, 1.0, 100.0, 1.0, 10.0, 10.0)); gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scroll), adj); /* Iterate through the components */ for ( component = loki_getfirst_component(product); component; component = loki_getnext_component(component) ) { add_message(list, _("---> Checking component '%s'..."), loki_getname_component(component)); for ( option = loki_getfirst_option(component); option; option = loki_getnext_option(option) ) { add_message(list, _("-> Checking option '%s'..."), loki_getname_option(option)); for ( file = loki_getfirst_file(option); file; file = loki_getnext_file(file) ) { gtk_main_iteration(); switch ( loki_check_file(file) ) { case LOKI_REMOVED: add_message(list, _("%s was REMOVED"), loki_getpath_file(file)); removed ++; add_corrupt_file(product, loki_getpath_file(file), loki_getname_option(option)); break; case LOKI_CHANGED: add_message(list, _("%s was MODIFIED"), loki_getpath_file(file)); modified ++; add_corrupt_file(product, loki_getpath_file(file), loki_getname_option(option)); break; case LOKI_OK: add_message(list, _("%s is OK"), loki_getpath_file(file)); break; } } } } if ( removed || modified ) { char status[200]; snprintf(status, sizeof(status), _("Changes detected: %d files removed, %d files modified."), removed, modified); gtk_label_set_text(GTK_LABEL(diag), status); gtk_widget_set_sensitive(fix_but, TRUE); } else { gtk_label_set_text(GTK_LABEL(diag), _("No problems were found.")); } /* Run the UI.. */ gtk_main(); return 0; }
void perform_uninstall_slot(GtkWidget* w, gpointer data) { GtkWidget *notebook; GtkWidget *progress; GtkWidget *widget; GList *list, *poopy, *clist; GtkWidget *button; component_list *component; size_t size, total; char text[1024]; const char *message; /* Set through environment to hide questions, and assume Yes */ int show_messages; const char *env; show_messages = 1; env = getenv("SETUP_NO_PROMPT"); if ( env && atoi(env) ) show_messages = 0; /* First switch to the next notebook page */ notebook = glade_xml_get_widget(uninstall_glade, "uninstall_notebook"); gtk_notebook_set_page(GTK_NOTEBOOK(notebook), 1); widget = glade_xml_get_widget(uninstall_glade, "finished_button"); if ( widget ) { gtk_button_set_sensitive(widget, FALSE); } /* Now uninstall all the selected components */ progress = glade_xml_get_widget(uninstall_glade, "uninstall_progress"); size = 0; total = calculate_recovered_space(); widget = glade_xml_get_widget(uninstall_glade, "uninstall_vbox"); list = gtk_container_children(GTK_CONTAINER(widget)); while ( list && ! uninstall_cancelled ) { widget = GTK_WIDGET(list->data); poopy = gtk_container_children(GTK_CONTAINER(widget)); widget = GTK_WIDGET(poopy->data); /* First do the addon components */ clist = gtk_container_children(GTK_CONTAINER(widget)); while ( clist && ! uninstall_cancelled ) { button = GTK_WIDGET(clist->data); if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) { component = gtk_object_get_data(GTK_OBJECT(button), "data"); if ( loki_isdefault_component(component->component) ) { clist = clist->next; continue; } /* Put up the status */ snprintf(text, sizeof(text), "%s: %s", component->info->description, loki_getname_component(component->component)); set_status_text(text); /* See if the user wants to cancel the uninstall */ while( gtk_events_pending() ) { gtk_main_iteration(); } /* Display an optional message to the user */ message = loki_getmessage_component(component->component); if (show_messages && message && !display_message(message, BUTTON_OK|BUTTON_ABORT) ) { clist = clist->next; uninstall_cancelled = 1; break; } /* Remove the component */ if ( ! uninstall_component(component->component, component->info) ) { uninstall_cancelled = 2; snprintf(text, sizeof(text), _("Uninstallation of component %s has failed!\n" "The whole uninstallation may be incomplete.\n"), loki_getname_component(component->component)); display_message(text, BUTTON_ABORT); break; } /* Update the progress bar */ if ( total && progress ) { size += component->size/1024; gtk_progress_set_percentage(GTK_PROGRESS(progress), (float)size/total); } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); /* See if the user wants to cancel the uninstall */ while( gtk_events_pending() ) { gtk_main_iteration(); } } clist = clist->next; } /* Now do the primary components */ clist = gtk_container_children(GTK_CONTAINER(widget)); while ( clist && ! uninstall_cancelled ) { button = GTK_WIDGET(clist->data); if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) { component = gtk_object_get_data(GTK_OBJECT(button), "data"); if ( ! loki_isdefault_component(component->component) ) { clist = clist->next; continue; } /* Put up the status */ strncpy(text, component->info->description, sizeof(text)); set_status_text(text); /* See if the user wants to cancel the uninstall */ while( gtk_events_pending() ) { gtk_main_iteration(); } /* Display an optional message to the user */ message = loki_getmessage_component(component->component); if ( message && !display_message(message, BUTTON_OK|BUTTON_ABORT) ) { clist = clist->next; uninstall_cancelled = 1; break; } /* Remove the component */ if ( ! perform_uninstall(component->product, component->info, 0) ) { uninstall_cancelled = 2; snprintf(text, sizeof(text), _("Uninstallation of product %s has failed!\n" "Aborting the rest of the uninstallation.\n"), component->info->description); display_message(text, BUTTON_ABORT); break; } remove_product(component->product); /* Update the progress bar */ if ( total && progress ) { size += component->size/1024; gtk_progress_set_percentage(GTK_PROGRESS(progress), (float)size/total); } /* See if the user wants to cancel the uninstall */ while( gtk_events_pending() ) { gtk_main_iteration(); } break; } clist = clist->next; } list = list->next; } switch ( uninstall_cancelled ) { case 1: set_status_text(_("Uninstall cancelled")); break; case 2: set_status_text(_("Uninstall aborted")); break; default: set_status_text(_("Uninstall complete")); gtk_progress_set_percentage(GTK_PROGRESS(progress), 1.0f); break; } widget = glade_xml_get_widget(uninstall_glade, "cancel_button"); if ( widget ) { gtk_button_set_sensitive(widget, FALSE); } widget = glade_xml_get_widget(uninstall_glade, "finished_button"); if ( widget ) { gtk_button_set_sensitive(widget, TRUE); } }