Return all update descriptions newer than the installed version

Fixes: https://github.com/hughsie/fwupd/issues/45
This commit is contained in:
Richard Hughes 2016-04-25 12:29:48 +01:00
parent 3c694baf2d
commit 654f6b82f3

View File

@ -1071,37 +1071,31 @@ fu_main_store_changed_cb (AsStore *store, FuMainPrivate *priv)
} }
/** /**
* fu_main_get_updates: * fu_main_get_updates_item_update:
**/ **/
static GPtrArray * static gboolean
fu_main_get_updates (FuMainPrivate *priv, GError **error) fu_main_get_updates_item_update (FuMainPrivate *priv, FuDeviceItem *item)
{ {
AsApp *app; AsApp *app;
AsRelease *rel;
FuDeviceItem *item;
GPtrArray *updates;
guint i;
const gchar *tmp;
/* find any updates using the AppStream metadata */
updates = g_ptr_array_new ();
for (i = 0; i < priv->devices->len; i++) {
const gchar *version;
AsChecksum *csum; AsChecksum *csum;
AsRelease *rel;
item = g_ptr_array_index (priv->devices, i); GPtrArray *releases;
const gchar *tmp;
const gchar *version;
guint i;
g_autoptr(GPtrArray) updates_list = NULL;
/* get device version */ /* get device version */
version = fu_device_get_version (item->device); version = fu_device_get_version (item->device);
if (version == NULL) if (version == NULL)
continue; return FALSE;
/* match the GUID in the XML */ /* match the GUID in the XML */
app = as_store_get_app_by_provide (priv->store, app = as_store_get_app_by_provide (priv->store,
AS_PROVIDE_KIND_FIRMWARE_FLASHED, AS_PROVIDE_KIND_FIRMWARE_FLASHED,
fu_device_get_guid (item->device)); fu_device_get_guid (item->device));
if (app == NULL) if (app == NULL)
continue; return FALSE;
/* possibly convert the version from 0x to dotted */ /* possibly convert the version from 0x to dotted */
fu_main_vendor_quirk_release_version (app); fu_main_vendor_quirk_release_version (app);
@ -1111,14 +1105,14 @@ fu_main_get_updates (FuMainPrivate *priv, GError **error)
if (rel == NULL) { if (rel == NULL) {
g_debug ("%s has no firmware update metadata", g_debug ("%s has no firmware update metadata",
fu_device_get_id (item->device)); fu_device_get_id (item->device));
continue; return FALSE;
} }
/* check if actually newer than what we have installed */ /* check if actually newer than what we have installed */
if (as_utils_vercmp (as_release_get_version (rel), version) <= 0) { if (as_utils_vercmp (as_release_get_version (rel), version) <= 0) {
g_debug ("%s has no firmware updates", g_debug ("%s has no firmware updates",
fu_device_get_id (item->device)); fu_device_get_id (item->device));
continue; return FALSE;
} }
/* can we only do this on AC power */ /* can we only do this on AC power */
@ -1126,7 +1120,7 @@ fu_main_get_updates (FuMainPrivate *priv, GError **error)
fu_main_on_battery (priv)) { fu_main_on_battery (priv)) {
g_debug ("ignoring update for %s as not on AC power", g_debug ("ignoring update for %s as not on AC power",
fu_device_get_id (item->device)); fu_device_get_id (item->device));
continue; return FALSE;
} }
/* add application metadata */ /* add application metadata */
@ -1162,12 +1156,62 @@ fu_main_get_updates (FuMainPrivate *priv, GError **error)
tmp = as_release_get_location_default (rel); tmp = as_release_get_location_default (rel);
if (tmp != NULL) if (tmp != NULL)
fu_device_set_update_uri (item->device, tmp); fu_device_set_update_uri (item->device, tmp);
/* get the list of releases newer than the one installed */
updates_list = g_ptr_array_new ();
releases = as_app_get_releases (app);
for (i = 0; i < releases->len; i++) {
rel = g_ptr_array_index (releases, i);
if (as_utils_vercmp (as_release_get_version (rel), version) < 0)
continue;
tmp = as_release_get_description (rel, NULL); tmp = as_release_get_description (rel, NULL);
if (tmp != NULL) if (tmp == NULL)
fu_device_set_update_description (item->device, tmp); continue;
g_ptr_array_add (updates, item); g_ptr_array_add (updates_list, rel);
} }
/* no prefix on each release */
if (updates_list->len == 1) {
rel = g_ptr_array_index (updates_list, 0);
fu_device_set_update_description (item->device,
as_release_get_description (rel, NULL));
} else {
g_autoptr(GString) update_desc = NULL;
update_desc = g_string_new ("");
/* get the descriptions with a version prefix */
for (i = 0; i < updates_list->len; i++) {
rel = g_ptr_array_index (updates_list, i);
g_string_append_printf (update_desc,
"<p>%s:</p>%s",
as_release_get_version (rel),
as_release_get_description (rel, NULL));
}
if (update_desc->len > 0)
fu_device_set_update_description (item->device, update_desc->str);
}
/* success */
return TRUE;
}
/**
* fu_main_get_updates:
**/
static GPtrArray *
fu_main_get_updates (FuMainPrivate *priv, GError **error)
{
GPtrArray *updates;
FuDeviceItem *item;
guint i;
/* find any updates using the AppStream metadata */
updates = g_ptr_array_new ();
for (i = 0; i < priv->devices->len; i++) {
item = g_ptr_array_index (priv->devices, i);
if (fu_main_get_updates_item_update (priv, item))
g_ptr_array_add (updates, item);
}
return updates; return updates;
} }