From c243914070240335e846a1a39e9c1855d43568be Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 13 Jun 2014 16:54:35 +0100 Subject: Allow dumping .desktop, .appdata.xml and .metainfo.xml files in appstream-util --- client/as-util.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/client/as-util.c b/client/as-util.c index 76c56c5..e44a0c7 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -240,31 +240,41 @@ as_util_convert (AsUtilPrivate *priv, gchar **values, GError **error) } /** - * as_util_dump: + * as_util_dump_filename: **/ static gboolean -as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error) +as_util_dump_filename (AsUtilPrivate *priv, const gchar *filename, GError **error) { + _cleanup_object_unref_ AsApp *app = NULL; _cleanup_object_unref_ AsStore *store = NULL; _cleanup_object_unref_ GFile *file_input = NULL; _cleanup_string_free_ GString *xml = NULL; - /* check args */ - if (g_strv_length (values) != 1) { + store = as_store_new (); + switch (as_app_guess_source_kind (filename)) { + case AS_APP_SOURCE_KIND_APPDATA: + case AS_APP_SOURCE_KIND_METAINFO: + case AS_APP_SOURCE_KIND_DESKTOP: + app = as_app_new (); + if (!as_app_parse_file (app, filename, + AS_APP_PARSE_FLAG_USE_HEURISTICS, error)) + return FALSE; + as_store_add_app (store, app); + break; + case AS_APP_SOURCE_KIND_APPSTREAM: + /* load file */ + file_input = g_file_new_for_path (filename); + if (!as_store_from_file (store, file_input, NULL, NULL, error)) + return FALSE; + break; + default: g_set_error_literal (error, AS_ERROR, AS_ERROR_INVALID_ARGUMENTS, - "Not enough arguments, " - "expected data.xml"); + "Format not recognised"); return FALSE; } - /* load file */ - store = as_store_new (); - file_input = g_file_new_for_path (values[0]); - if (!as_store_from_file (store, file_input, NULL, NULL, error)) - return FALSE; - /* dump to screen */ as_store_set_api_version (store, 1.0); xml = as_store_to_xml (store, @@ -275,6 +285,30 @@ as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error) return TRUE; } +/** + * as_util_dump: + **/ +static gboolean +as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error) +{ + guint i; + + /* check args */ + if (g_strv_length (values) < 1) { + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + "Not enough arguments, " + "expected data.xml"); + return FALSE; + } + for (i = 0; values[i] != NULL; i++) { + if (!as_util_dump_filename (priv, values[0], error)) + return FALSE; + } + return TRUE; +} + /** * as_util_install_icons: **/ -- cgit v1.2.1