gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *tmp; /* not required */ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME) == 0) return TRUE; if (gs_app_get_origin_hostname (app) != NULL) return TRUE; /* ensure valid */ if (!gs_plugin_repos_setup (plugin, cancellable, error)) return FALSE; /* find hostname */ if (gs_app_get_origin (app) == NULL) return TRUE; tmp = g_hash_table_lookup (priv->urls, gs_app_get_origin (app)); if (tmp != NULL) gs_app_set_origin_hostname (app, tmp); return TRUE; }
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"); }
gboolean gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { const gchar *gameid; const gchar *tmp; g_autofree gchar *manifest_basename = NULL; g_autofree gchar *fn = NULL; g_autoptr(GHashTable) manifest = NULL; /* check is us */ gameid = gs_app_get_metadata_item (app, "X-Steam-GameID"); if (gameid == NULL) return TRUE; /* is this true? */ gs_app_set_kind (app, AS_ID_KIND_DESKTOP); /* no way of knowing */ if (gs_app_get_size_download (app) == 0) gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE); /* hardcoded */ if (gs_app_get_origin_hostname (app) == NULL) gs_app_set_origin_hostname (app, "steampowered.com"); /* size */ tmp = gs_app_get_metadata_item (app, "X-Steam-Size"); if (tmp != NULL) { guint64 sz; sz = g_ascii_strtoull (tmp, NULL, 10); if (sz > 0) gs_app_set_size_installed (app, sz); } /* check manifest */ manifest_basename = g_strdup_printf ("appmanifest_%s.acf", gameid); fn = g_build_filename (g_get_user_data_dir (), "Steam", "steamapps", manifest_basename, NULL); if (!g_file_test (fn, G_FILE_TEST_EXISTS)) { /* can never have been installed */ gs_app_set_state (app, AS_APP_STATE_AVAILABLE); return TRUE; } manifest = gs_plugin_steam_load_app_manifest (fn, error); if (manifest == NULL) return FALSE; /* this is better than the download size */ tmp = g_hash_table_lookup (manifest, "SizeOnDisk"); if (tmp != NULL) { guint64 sz; sz = g_ascii_strtoull (tmp, NULL, 10); if (sz > 0) gs_app_set_size_installed (app, sz); } /* set state */ tmp = g_hash_table_lookup (manifest, "StateFlags"); if (tmp != NULL) { guint64 state_flags; /* set state */ state_flags = g_ascii_strtoull (tmp, NULL, 10); if (state_flags & GS_STEAM_STATE_FLAG_DOWNLOADING || state_flags & GS_STEAM_STATE_FLAG_PREALLOCATING || state_flags & GS_STEAM_STATE_FLAG_ADDING_FILES || state_flags & GS_STEAM_STATE_FLAG_COMMITTING || state_flags & GS_STEAM_STATE_FLAG_STAGING) gs_app_set_state (app, AS_APP_STATE_INSTALLING); else if (state_flags & GS_STEAM_STATE_FLAG_UNINSTALLING) gs_app_set_state (app, AS_APP_STATE_REMOVING); else if (state_flags & GS_STEAM_STATE_FLAG_FULLY_INSTALLED) gs_app_set_state (app, AS_APP_STATE_INSTALLED); else if (state_flags & GS_STEAM_STATE_FLAG_UNINSTALLED) gs_app_set_state (app, AS_APP_STATE_AVAILABLE); } /* set install date */ tmp = g_hash_table_lookup (manifest, "LastUpdated"); if (tmp != NULL) { guint64 ts; ts = g_ascii_strtoull (tmp, NULL, 10); if (ts > 0) gs_app_set_install_date (app, ts); } return TRUE; }
gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *verstr = NULL; gchar *endptr = NULL; g_autoptr(GFile) file = NULL; g_autoptr(GsOsRelease) os_release = NULL; /* get the file to cache */ priv->cachefn = gs_utils_get_cache_filename ("upgrades", "fedora.json", GS_UTILS_CACHE_FLAG_WRITEABLE, error); if (priv->cachefn == NULL) return FALSE; /* watch this in case it is changed by the user */ file = g_file_new_for_path (priv->cachefn); priv->cachefn_monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, cancellable, error); if (priv->cachefn_monitor == NULL) return FALSE; g_signal_connect (priv->cachefn_monitor, "changed", G_CALLBACK (gs_plugin_fedora_distro_upgrades_changed_cb), plugin); /* read os-release for the current versions */ os_release = gs_os_release_new (error); if (os_release == NULL) return FALSE; priv->os_name = g_strdup (gs_os_release_get_name (os_release)); if (priv->os_name == NULL) return FALSE; verstr = gs_os_release_get_version_id (os_release); if (verstr == NULL) return FALSE; /* parse the version */ priv->os_version = g_ascii_strtoull (verstr, &endptr, 10); if (endptr == verstr || priv->os_version > G_MAXUINT) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "Failed parse VERSION_ID: %s", verstr); return FALSE; } /* 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_ui (priv->cached_origin, "Fedora Project PkgDb"); gs_app_set_origin_hostname (priv->cached_origin, FEDORA_PKGDB_COLLECTIONS_API_URI); /* 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); /* success */ return TRUE; }