trivial: Refactor the update helper

No logic changes.
This commit is contained in:
Richard Hughes 2016-07-04 12:37:22 +01:00
parent 346ea88135
commit 3ab17e63dd

View File

@ -716,40 +716,20 @@ fu_main_store_get_app_by_guids (AsStore *store, FuDevice *device)
}
static gboolean
fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
fu_main_update_helper_for_device (FuMainAuthHelper *helper,
FuDevice *device,
GError **error)
{
AsApp *app;
AsChecksum *csum_tmp;
AsRelease *rel;
GBytes *blob_fw;
const gchar *tmp;
const gchar *version;
gint vercmp;
guint i;
/* load store file which also decompresses firmware */
fu_main_set_status (helper->priv, FWUPD_STATUS_DECOMPRESSING);
if (!as_store_from_bytes (helper->store, helper->blob_cab, NULL, error))
return FALSE;
/* if we've not chosen a device, try and find anything in the
* cabinet 'store' that matches any installed device */
if (helper->devices->len == 0) {
for (i = 0; i < helper->priv->devices->len; i++) {
FuDeviceItem *item;
item = g_ptr_array_index (helper->priv->devices, i);
app = fu_main_store_get_app_by_guids (helper->store, item->device);
if (app != NULL) {
g_ptr_array_add (helper->devices,
g_object_ref (item->device));
}
}
}
/* find an application from the cabinet 'store' for the device */
for (i = 0; i < helper->devices->len; i ++) {
gboolean is_downgrade;
GBytes *blob_fw;
FuDevice *device = g_ptr_array_index (helper->devices, i);
gint vercmp;
/* find from guid */
app = fu_main_store_get_app_by_guids (helper->store, device);
if (app == NULL) {
g_autofree gchar *guid = NULL;
@ -792,7 +772,6 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
"failed to get firmware blob");
return FALSE;
}
g_ptr_array_add (helper->blob_fws, g_bytes_ref (blob_fw));
/* possibly convert the version from 0x to dotted */
fu_main_vendor_quirk_release_version (app);
@ -857,6 +836,42 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
/* verify */
if (!fu_main_get_release_trust_flags (rel, &helper->trust_flags, error))
return FALSE;
/* success */
g_ptr_array_add (helper->blob_fws, g_bytes_ref (blob_fw));
return TRUE;
}
static gboolean
fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
{
AsApp *app;
guint i;
/* load store file which also decompresses firmware */
fu_main_set_status (helper->priv, FWUPD_STATUS_DECOMPRESSING);
if (!as_store_from_bytes (helper->store, helper->blob_cab, NULL, error))
return FALSE;
/* if we've not chosen a device, try and find anything in the
* cabinet 'store' that matches any installed device */
if (helper->devices->len == 0) {
for (i = 0; i < helper->priv->devices->len; i++) {
FuDeviceItem *item;
item = g_ptr_array_index (helper->priv->devices, i);
app = fu_main_store_get_app_by_guids (helper->store, item->device);
if (app != NULL) {
g_ptr_array_add (helper->devices,
g_object_ref (item->device));
}
}
}
/* find an application from the cabinet 'store' for the device */
for (i = 0; i < helper->devices->len; i ++) {
FuDevice *device = g_ptr_array_index (helper->devices, i);
if (!fu_main_update_helper_for_device (helper, device, error))
return FALSE;
}
/* still nothing found */