diff -r 000000000000 -r 2b9f54d14cc2 app-manager/update.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app-manager/update.c Sat Nov 15 19:04:45 2014 +0000 @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 J. Ali Harlow + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "app-manager.h" + +gboolean update(PloverPackageSet *installed,const char *base) +{ + gchar *s; + const char *prefix; + GError *error=NULL; + static PloverTransactionHelper *helper=NULL; + if (!helper) + { + helper=plover_transaction_helper_new(ui); + plover_transaction_helper_set_installed(helper,installed); + plover_transaction_helper_set_base(helper,base); + prefix=plover_transaction_helper_get_prefix(helper,&error); + if (error) + g_clear_error(&error); + else + { + s=g_strconcat(prefix?prefix:"","/var/log/update",NULL); + plover_log_open(s); + g_free(s); + } + plover_transaction_helper_set_check_vendor(helper,TRUE); + g_signal_connect(helper,"close",G_CALLBACK(gtk_main_quit),NULL); + } + if (!plover_transaction_helper_get_visible(helper)) + { + if (!plover_transaction_helper_update(helper,&error)) + { + if (g_error_matches(error,PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_NO_WORK)) + { + g_error_free(error); + error=g_error_new_literal(PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_NO_WORK, + "All relevant updates already applied"); + plover_transaction_helper_set_error(helper,error, + "Software update"); + } + else if (g_error_matches(error,PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET)) + { + g_error_free(error); + error=g_error_new_literal(PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET, + "Updates cannot be applied because some earlier updates are " + "missing. Installing updates in sequence should resolve this " + "problem"); + plover_transaction_helper_set_error(helper,error, + "Software update failed"); + } + else + plover_transaction_helper_set_error(helper,error, + "Software update failed"); + g_error_free(error); + } + } + plover_transaction_helper_present(helper); + return TRUE; +}