/** * gs_plugin_app_remove: */ gboolean gs_plugin_app_remove (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* remove */ gs_app_set_state (app, AS_APP_STATE_REMOVING); if (!xdg_app_installation_uninstall (priv->installation, XDG_APP_REF_KIND_APP, gs_app_get_xdgapp_name (app), gs_app_get_xdgapp_arch (app), gs_app_get_xdgapp_branch (app), gs_plugin_xdg_app_progress_cb, app, cancellable, error)) { gs_app_set_state_recover (app); return FALSE; } /* state is not known: we don't know if we can re-install this app */ gs_app_set_state (app, AS_APP_STATE_UNKNOWN); return TRUE; }
gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); /* add source */ priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin)); gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE); gs_app_set_bundle_kind (priv->cached_origin, AS_BUNDLE_KIND_CABINET); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* register D-Bus errors */ fwupd_error_quark (); g_signal_connect (priv->client, "changed", G_CALLBACK (gs_plugin_fwupd_changed_cb), plugin); g_signal_connect (priv->client, "device-added", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "device-removed", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "device-changed", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "notify::percentage", G_CALLBACK (gs_plugin_fwupd_notify_percentage_cb), plugin); g_signal_connect (priv->client, "notify::status", G_CALLBACK (gs_plugin_fwupd_notify_status_cb), plugin); return TRUE; }
/** * gs_plugin_update_app: */ gboolean gs_plugin_update_app (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(XdgAppInstalledRef) xref = NULL; /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* install */ gs_app_set_state (app, AS_APP_STATE_INSTALLING); xref = xdg_app_installation_update (priv->installation, XDG_APP_UPDATE_FLAGS_NONE, gs_app_get_xdgapp_kind (app), gs_app_get_xdgapp_name (app), gs_app_get_xdgapp_arch (app), gs_app_get_xdgapp_branch (app), gs_plugin_xdg_app_progress_cb, app, cancellable, error); if (xref == NULL) { gs_app_set_state_recover (app); return FALSE; } /* state is known */ gs_app_set_state (app, AS_APP_STATE_INSTALLED); return TRUE; }
/** * gs_plugin_launch: */ gboolean gs_plugin_launch (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *branch = NULL; /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; branch = gs_app_get_xdgapp_branch (app); if (branch == NULL) branch = "master"; return xdg_app_installation_launch (priv->installation, gs_app_get_xdgapp_name (app), NULL, branch, NULL, cancellable, error); }
/** * gs_plugin_refine_item_metadata: */ static gboolean gs_plugin_refine_item_metadata (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { g_autoptr(XdgAppRef) xref = NULL; /* already set */ if (gs_app_get_metadata_item (app, "xdg-app::kind") != NULL) return TRUE; /* AppStream sets the source to appname/arch/branch, if this isn't set * we can't break out the fields */ if (gs_app_get_source_default (app) == NULL) { g_warning ("no source set by appstream for %s", gs_plugin_get_name (plugin)); return TRUE; } /* parse the ref */ xref = xdg_app_ref_parse (gs_app_get_source_default (app), error); if (xref == NULL) { g_prefix_error (error, "failed to parse '%s': ", gs_app_get_source_default (app)); return FALSE; } gs_plugin_xdg_app_set_metadata (app, xref); /* success */ return TRUE; }
/** * gs_plugin_adopt_app: */ void gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app) { if (g_str_has_prefix (gs_app_get_id (app), "user-xdgapp:") || g_str_has_prefix (gs_app_get_id (app), "xdgapp:")) { gs_app_set_management_plugin (app, gs_plugin_get_name (plugin)); } }
gboolean gs_plugin_add_sources (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); PkBitfield filter; PkRepoDetail *rd; ProgressData data; const gchar *id; guint i; g_autoptr(GHashTable) hash = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GPtrArray) array = NULL; data.app = NULL; data.plugin = plugin; data.ptask = NULL; /* ask PK for the repo details */ filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_SOURCE, PK_FILTER_ENUM_NOT_SUPPORTED, -1); results = pk_client_get_repo_list (PK_CLIENT(priv->task), filter, cancellable, gs_plugin_packagekit_progress_cb, &data, error); if (!gs_plugin_packagekit_results_valid (results, error)) return FALSE; hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); array = pk_results_get_repo_detail_array (results); for (i = 0; i < array->len; i++) { g_autoptr(GsApp) app = NULL; rd = g_ptr_array_index (array, i); id = pk_repo_detail_get_id (rd); app = gs_app_new (id); gs_app_set_management_plugin (app, gs_plugin_get_name (plugin)); gs_app_set_kind (app, AS_APP_KIND_SOURCE); gs_app_set_state (app, pk_repo_detail_get_enabled (rd) ? AS_APP_STATE_INSTALLED : AS_APP_STATE_AVAILABLE); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, pk_repo_detail_get_description (rd)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, pk_repo_detail_get_description (rd)); gs_app_list_add (list, app); g_hash_table_insert (hash, g_strdup (id), (gpointer) app); } /* get every application on the system and add it as a related package * if it matches */ return gs_plugin_add_sources_related (plugin, hash, cancellable, error); }
void gs_plugin_initialize (GsPlugin *plugin) { if (!g_file_test (DPKG_DEB_BINARY, G_FILE_TEST_EXISTS)) { g_debug ("disabling '%s' as no %s available", gs_plugin_get_name (plugin), DPKG_DEB_BINARY); gs_plugin_set_enabled (plugin, FALSE); } }
gboolean gs_plugin_app_install (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { g_autoptr(LiInstaller) inst = NULL; GsPluginHelper helper; g_autoptr(GError) error_local = NULL; /* not us */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* create new installer and select remote package */ inst = li_installer_new (); li_installer_open_remote (inst, gs_app_get_source_default (app), &error_local); if (error_local != NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Failed to install software: %s", error_local->message); return FALSE; } /* set up progress forwarding */ helper.app = app; helper.plugin = plugin; g_signal_connect (inst, "progress", G_CALLBACK (gs_plugin_installer_progress_cb), &helper); /* install software */ gs_app_set_state (app, AS_APP_STATE_INSTALLING); li_installer_install (inst, &error_local); if (error_local != NULL) { gs_app_set_state (app, AS_APP_STATE_AVAILABLE); g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Failed to install software: %s", error_local->message); return FALSE; } gs_app_set_state (app, AS_APP_STATE_INSTALLED); return TRUE; }
void gs_plugin_initialize (GsPlugin *plugin) { gs_plugin_alloc_data (plugin, sizeof(GsPluginData)); /* check that we are running on Fedora */ if (!gs_plugin_check_distro_id (plugin, "fedora")) { gs_plugin_set_enabled (plugin, FALSE); g_debug ("disabling '%s' as we're not Fedora", gs_plugin_get_name (plugin)); return; } }
gboolean gs_plugin_app_remove (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* source -> remote */ return gs_plugin_fwupd_modify_source (plugin, app, FALSE, cancellable, error); }
void gs_plugin_initialize (GsPlugin *plugin) { GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData)); g_autoptr(GError) error = NULL; g_autoptr(GsOsRelease) os_release = NULL; priv->settings = g_settings_new ("org.gnome.software"); priv->review_server = g_settings_get_string (priv->settings, "review-server"); priv->ratings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_array_unref); /* get the machine+user ID hash value */ priv->user_hash = gs_utils_get_user_hash (&error); if (priv->user_hash == NULL) { g_warning ("Failed to get machine+user hash: %s", error->message); return; } /* get the distro name (e.g. 'Fedora') but allow a fallback */ os_release = gs_os_release_new (&error); if (os_release != NULL) { priv->distro = g_strdup (gs_os_release_get_name (os_release)); if (priv->distro == NULL) { g_warning ("no distro name specified"); priv->distro = g_strdup ("Unknown"); } } else { g_warning ("failed to get distro name: %s", error->message); priv->distro = g_strdup ("Unknown"); } /* add source */ priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin)); gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE); gs_app_set_origin_hostname (priv->cached_origin, priv->review_server); gs_app_set_origin_ui (priv->cached_origin, "Open Desktop Review Server"); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* need application IDs and version */ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak-system"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak-user"); /* set name of MetaInfo file */ gs_plugin_set_appstream_id (plugin, "org.gnome.Software.Plugin.Odrs"); }
static void gs_plugin_fedora_distro_upgrades_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { GsPlugin *plugin = GS_PLUGIN (user_data); /* only reload the update list if the plugin is NOT running itself * and the time since it ran is greater than 5 seconds (inotify FTW) */ if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_RUNNING_SELF)) { g_debug ("no notify as plugin %s active", gs_plugin_get_name (plugin)); return; } if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_RECENT)) { g_debug ("no notify as plugin %s recently active", gs_plugin_get_name (plugin)); return; } g_debug ("cache file changed, so reloading upgrades list"); gs_plugin_updates_changed (plugin); }
gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); LiPkgInfo *pki; g_autoptr(GError) error_local = NULL; g_autoptr(AsProfileTask) ptask = NULL; /* not us */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* profile */ ptask = as_profile_start (gs_plugin_get_profile (plugin), "limba::refine{%s}", gs_app_get_id (app)); /* sanity check */ if (gs_app_get_source_default (app) == NULL) return TRUE; pki = li_manager_get_software_by_pkid (priv->mgr, gs_app_get_source_default (app), &error_local); if (error_local != NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Unable to refine metadata: %s", error_local->message); return FALSE; } if (pki == NULL) return TRUE; if (li_pkg_info_has_flag (pki, LI_PACKAGE_FLAG_INSTALLED)) gs_app_set_state (app, AS_APP_STATE_INSTALLED); else gs_app_set_state (app, AS_APP_STATE_AVAILABLE); gs_app_set_version (app, li_pkg_info_get_version (pki)); return TRUE; }
/** * gs_plugin_xdg_app_refine_app: */ static gboolean gs_plugin_xdg_app_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { g_autoptr(AsProfileTask) ptask = NULL; /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* profile */ ptask = as_profile_start (gs_plugin_get_profile (plugin), "xdg-app::refine{%s}", gs_app_get_id (app)); /* AppStream sets the source to appname/arch/branch */ if (!gs_plugin_refine_item_metadata (plugin, app, cancellable, error)) return FALSE; /* check the installed state */ if (!gs_plugin_refine_item_state (plugin, app, cancellable, error)) return FALSE; /* version fallback */ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION) { if (gs_app_get_version (app) == NULL) { const gchar *branch; branch = gs_app_get_xdgapp_branch (app); gs_app_set_version (app, branch); } } /* size */ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) { if (!gs_plugin_refine_item_size (plugin, app, cancellable, error)) return FALSE; } /* origin */ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) { if (!gs_plugin_refine_item_origin_ui (plugin, app, cancellable, error)) return FALSE; } return TRUE; }
void gs_plugin_initialize (GsPlugin *plugin) { g_autoptr(GSettings) settings = NULL; /* this is opt-in, and turned off by default */ settings = g_settings_new ("org.gnome.desktop.privacy"); if (!g_settings_get_boolean (settings, "send-software-usage-stats")) { gs_plugin_set_enabled (plugin, FALSE); g_debug ("disabling '%s' as 'send-software-usage-stats' " "disabled in GSettings", gs_plugin_get_name (plugin)); return; } /* check that we are running on Fedora */ if (!gs_plugin_check_distro_id (plugin, "fedora")) { gs_plugin_set_enabled (plugin, FALSE); g_debug ("disabling '%s' as we're not Fedora", gs_plugin_get_name (plugin)); return; } /* after the install/remove has succeeded */ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit"); }
gboolean gs_plugin_add_popular (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { guint i; const gchar *apps[] = { "org.gnome.Builder.desktop", "org.gnome.Calculator.desktop", "org.gnome.clocks.desktop", "org.gnome.Dictionary.desktop", "org.gnome.Documents.desktop", "org.gnome.Evince.desktop", "org.gnome.gedit.desktop", "org.gnome.Maps.desktop", "org.gnome.Weather.desktop", NULL }; /* we've already got enough popular apps */ if (gs_app_list_length (list) >= 5) return TRUE; /* just add all */ g_debug ("using hardcoded as only %u apps", gs_app_list_length (list)); for (i = 0; apps[i] != NULL; i++) { g_autoptr(GsApp) app = NULL; /* look in the cache */ app = gs_plugin_cache_lookup (plugin, apps[i]); if (app != NULL) { gs_app_list_add (list, app); continue; } /* create new */ app = gs_app_new (apps[i]); gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX); gs_app_set_metadata (app, "GnomeSoftware::Creator", gs_plugin_get_name (plugin)); gs_app_list_add (list, app); /* save in the cache */ gs_plugin_cache_add (plugin, apps[i], app); } return TRUE; }
gboolean gs_plugin_app_remove (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { g_autoptr(LiManager) mgr = NULL; GsPluginHelper helper; g_autoptr(GError) error_local = NULL; /* not us */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; mgr = li_manager_new (); /* set up progress forwarding */ helper.app = app; helper.plugin = plugin; g_signal_connect (mgr, "progress", G_CALLBACK (gs_plugin_manager_progress_cb), &helper); gs_app_set_state (app, AS_APP_STATE_REMOVING); li_manager_remove_software (mgr, gs_app_get_source_default (app), &error_local); if (error_local != NULL) { gs_app_set_state (app, AS_APP_STATE_INSTALLED); g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "Failed to remove software: %s", error_local->message); return FALSE; } gs_app_set_state (app, AS_APP_STATE_AVAILABLE); return TRUE; }
void gs_plugin_initialize (GsPlugin *plugin) { GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData)); if (!gs_snapd_exists ()) { g_debug ("disabling '%s' as snapd not running", gs_plugin_get_name (plugin)); gs_plugin_set_enabled (plugin, FALSE); } priv->auth = gs_auth_new ("snapd"); gs_auth_set_provider_name (priv->auth, "Snap Store"); gs_auth_set_provider_schema (priv->auth, "com.ubuntu.UbuntuOne.GnomeSoftware"); gs_plugin_add_auth (plugin, priv->auth); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "desktop-categories"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "ubuntu-reviews"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_BETTER_THAN, "packagekit"); }
gboolean gs_plugin_app_install (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* source -> remote */ if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE) { return gs_plugin_fwupd_modify_source (plugin, app, TRUE, cancellable, error); } /* firmware */ return gs_plugin_fwupd_install (plugin, app, cancellable, error); }
/** * gs_plugin_add_sources: */ gboolean gs_plugin_add_sources (GsPlugin *plugin, GList **list, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autoptr(GPtrArray) xremotes = NULL; guint i; xremotes = xdg_app_installation_list_remotes (priv->installation, cancellable, error); if (xremotes == NULL) return FALSE; for (i = 0; i < xremotes->len; i++) { XdgAppRemote *xremote = g_ptr_array_index (xremotes, i); g_autoptr(GsApp) app = NULL; /* apps installed from bundles add their own remote that only * can be used for updating that app only -- so hide them */ if (xdg_app_remote_get_noenumerate (xremote)) continue; app = gs_app_new (xdg_app_remote_get_name (xremote)); gs_app_set_management_plugin (app, gs_plugin_get_name (plugin)); gs_app_set_kind (app, AS_APP_KIND_SOURCE); gs_app_set_state (app, AS_APP_STATE_INSTALLED); gs_app_set_name (app, GS_APP_QUALITY_LOWEST, xdg_app_remote_get_name (xremote)); gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, xdg_app_remote_get_title (xremote)); gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, xdg_app_remote_get_url (xremote)); gs_app_list_add (list, app); } return TRUE; }
gboolean gs_plugin_launch (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { const gchar *gameid; g_autofree gchar *cmdline = NULL; /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* this is async as steam is a different process: FIXME: use D-Bus */ gameid = gs_app_get_metadata_item (app, "X-Steam-GameID"); cmdline = g_strdup_printf ("steam steam://run/%s", gameid); if (!g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, error)) { gs_utils_error_convert_gio (error); return FALSE; } return TRUE; }
void gs_plugin_initialize (GsPlugin *plugin) { GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData)); g_autoptr(GsOsRelease) os_release = NULL; g_autoptr(GError) error = NULL; /* check that we are running on Ubuntu */ if (!gs_plugin_check_distro_id (plugin, "ubuntu")) { gs_plugin_set_enabled (plugin, FALSE); g_debug ("disabling '%s' as we're not Ubuntu", gs_plugin_get_name (plugin)); return; } priv->db_path = g_build_filename (g_get_user_data_dir (), "gnome-software", "ubuntu-reviews.db", NULL); os_release = gs_os_release_new (&error); if (os_release == NULL) { g_warning ("Failed to determine OS information: %s", error->message); priv->origin = g_strdup ("unknown"); priv->distroseries = g_strdup ("unknown"); } else { priv->origin = g_strdup (gs_os_release_get_id (os_release)); if (priv->origin == NULL) priv->origin = g_strdup ("unknown"); if (strcmp (priv->origin, "ubuntu") == 0) priv->distroseries = g_strdup (gs_os_release_get_distro_codename (os_release)); if (priv->distroseries == NULL) priv->distroseries = g_strdup ("unknown"); } /* we have more reviews than ORDS */ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "odrs"); /* need source */ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream"); }
static gboolean gs_plugin_odrs_refresh_ratings (GsPlugin *plugin, guint cache_age, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autofree gchar *fn = NULL; g_autofree gchar *uri = NULL; g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin)); /* check cache age */ fn = gs_utils_get_cache_filename ("ratings", "odrs.json", GS_UTILS_CACHE_FLAG_WRITEABLE, error); if (fn == NULL) return FALSE; if (cache_age > 0) { guint tmp; g_autoptr(GFile) file = NULL; file = g_file_new_for_path (fn); tmp = gs_utils_get_file_age (file); if (tmp < cache_age) { g_debug ("%s is only %u seconds old, so ignoring refresh", fn, tmp); return gs_plugin_odrs_load_ratings (plugin, fn, error); } } /* download the complete file */ uri = g_strdup_printf ("%s/ratings", priv->review_server); if (!gs_plugin_download_file (plugin, app_dl, uri, fn, cancellable, error)) { gs_utils_error_add_unique_id (error, priv->cached_origin); return FALSE; } return gs_plugin_odrs_load_ratings (plugin, fn, error); }
gboolean gs_plugin_update_app (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* locked devices need unlocking, rather than installing */ if (gs_fwupd_app_get_is_locked (app)) { const gchar *device_id; device_id = gs_fwupd_app_get_device_id (app); if (device_id == NULL) { g_set_error_literal (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "not enough data for fwupd unlock"); return FALSE; } if (!fwupd_client_unlock (priv->client, device_id, cancellable, error)) { gs_plugin_fwupd_error_convert (error); return FALSE; } return TRUE; } /* update means install */ if (!gs_plugin_fwupd_install (plugin, app, cancellable, error)) { gs_plugin_fwupd_error_convert (error); return FALSE; } return TRUE; }
gboolean gs_plugin_add_featured (GsPlugin *plugin, GsAppList *list, GCancellable *cancellable, GError **error) { guint i; /* we've already got enough featured apps */ if (gs_app_list_length (list) >= 5) return TRUE; /* just add all */ g_debug ("using hardcoded as only %u apps", gs_app_list_length (list)); for (i = 0; myapps[i].id != NULL; i++) { g_autoptr(GsApp) app = NULL; /* look in the cache */ app = gs_plugin_cache_lookup (plugin, myapps[i].id); if (app != NULL) { gs_app_list_add (list, app); continue; } /* create new */ app = gs_app_new (myapps[i].id); gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX); gs_app_set_metadata (app, "GnomeSoftware::Creator", gs_plugin_get_name (plugin)); gs_app_set_metadata (app, "GnomeSoftware::FeatureTile-css", myapps[i].css); gs_app_list_add (list, app); /* save in the cache */ gs_plugin_cache_add (plugin, myapps[i].id, app); } return TRUE; }
gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { const gchar *keys[] = { "GnomeSoftware::AppTile-css", "GnomeSoftware::FeatureTile-css", "GnomeSoftware::UpgradeBanner-css", NULL }; /* rewrite URIs */ for (guint i = 0; keys[i] != NULL; i++) { const gchar *css = gs_app_get_metadata_item (app, keys[i]); if (css != NULL) { g_autofree gchar *css_new = NULL; g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin)); gs_app_set_summary_missing (app_dl, /* TRANSLATORS: status text when downloading */ _("Downloading featured images…")); css_new = gs_plugin_download_rewrite_resource (plugin, app, css, cancellable, error); if (css_new == NULL) return FALSE; if (g_strcmp0 (css, css_new) != 0) { gs_app_set_metadata (app, keys[i], NULL); gs_app_set_metadata (app, keys[i], css_new); } } } return TRUE; }
gboolean gs_plugin_download_app (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GFile *local_file; g_autofree gchar *filename = NULL; /* only process this app if was created by this plugin */ if (g_strcmp0 (gs_app_get_management_plugin (app), gs_plugin_get_name (plugin)) != 0) return TRUE; /* not set */ local_file = gs_app_get_local_file (app); if (local_file == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "not enough data for fwupd %s", filename); return FALSE; } /* file does not yet exist */ filename = g_file_get_path (local_file); if (!g_file_query_exists (local_file, cancellable)) { const gchar *uri = gs_fwupd_app_get_update_uri (app); if (!gs_plugin_download_file (plugin, app, uri, filename, cancellable, error)) return FALSE; } gs_app_set_size_download (app, 0); return TRUE; }
void gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app) { if (gs_app_get_kind (app) == AS_APP_KIND_FIRMWARE) gs_app_set_management_plugin (app, gs_plugin_get_name (plugin)); }
static gboolean gs_plugin_fwupd_refresh_remote (GsPlugin *plugin, FwupdRemote *remote, guint cache_age, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); GChecksumType checksum_kind; const gchar *url_sig = NULL; const gchar *url = NULL; g_autoptr(GError) error_local = NULL; g_autofree gchar *basename = NULL; g_autofree gchar *basename_sig = NULL; g_autofree gchar *cache_id = NULL; g_autofree gchar *checksum = NULL; g_autofree gchar *filename = NULL; g_autofree gchar *filename_sig = NULL; g_autoptr(GBytes) data = NULL; g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin)); /* sanity check */ if (fwupd_remote_get_filename_cache_sig (remote) == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "remote %s has no cache signature", fwupd_remote_get_id (remote)); return FALSE; } /* check cache age */ if (cache_age > 0) { guint64 age = fwupd_remote_get_age (remote); guint tmp = age < G_MAXUINT ? (guint) age : G_MAXUINT; if (tmp < cache_age) { g_debug ("%s is only %u seconds old, so ignoring refresh", filename_sig, tmp); return TRUE; } } /* download the signature first, it's smaller */ cache_id = g_strdup_printf ("fwupd/remotes.d/%s", fwupd_remote_get_id (remote)); basename_sig = g_path_get_basename (fwupd_remote_get_filename_cache_sig (remote)); filename_sig = gs_utils_get_cache_filename (cache_id, basename_sig, GS_UTILS_CACHE_FLAG_WRITEABLE, error); /* download the signature first, it's smaller */ url_sig = fwupd_remote_get_metadata_uri_sig (remote); gs_app_set_summary_missing (app_dl, /* TRANSLATORS: status text when downloading */ _("Downloading firmware update signature…")); data = gs_plugin_download_data (plugin, app_dl, url_sig, cancellable, error); if (data == NULL) { gs_utils_error_add_origin_id (error, priv->cached_origin); return FALSE; } /* is the signature hash the same as we had before? */ checksum_kind = fwupd_checksum_guess_kind (fwupd_remote_get_checksum (remote)); checksum = g_compute_checksum_for_data (checksum_kind, (const guchar *) g_bytes_get_data (data, NULL), g_bytes_get_size (data)); if (g_strcmp0 (checksum, fwupd_remote_get_checksum (remote)) == 0) { g_debug ("signature of %s is unchanged", url_sig); return TRUE; } /* save to a file */ g_debug ("saving new remote signature to %s:", filename_sig); if (!g_file_set_contents (filename_sig, g_bytes_get_data (data, NULL), (guint) g_bytes_get_size (data), &error_local)) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_WRITE_FAILED, "Failed to save firmware signature: %s", error_local->message); return FALSE; } /* download the payload and save to file */ basename = g_path_get_basename (fwupd_remote_get_filename_cache (remote)); filename = gs_utils_get_cache_filename (cache_id, basename, GS_UTILS_CACHE_FLAG_WRITEABLE, error); if (filename == NULL) return FALSE; g_debug ("saving new firmware metadata to %s:", filename); gs_app_set_summary_missing (app_dl, /* TRANSLATORS: status text when downloading */ _("Downloading firmware update metadata…")); url = fwupd_remote_get_metadata_uri (remote); if (!gs_plugin_download_file (plugin, app_dl, url, filename, cancellable, error)) { gs_utils_error_add_origin_id (error, priv->cached_origin); return FALSE; } /* phew, lets send all this to fwupd */ if (!fwupd_client_update_metadata (priv->client, fwupd_remote_get_id (remote), filename, filename_sig, cancellable, error)) { gs_plugin_fwupd_error_convert (error); return FALSE; } return TRUE; }