summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-06-13 16:54:35 +0100
committerRichard Hughes <richard@hughsie.com>2014-06-13 17:05:11 +0100
commitc243914070240335e846a1a39e9c1855d43568be (patch)
tree3b2e22d0450dfbb8b98c571572589be301a3f2a9
parent385018aac2573a1f63aa9014ed36923b21e081d7 (diff)
downloadappstream-glib-c243914070240335e846a1a39e9c1855d43568be.tar.gz
Allow dumping .desktop, .appdata.xml and .metainfo.xml files in appstream-util
-rw-r--r--client/as-util.c58
1 files 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,
@@ -276,6 +286,30 @@ as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error)
}
/**
+ * 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:
**/
static gboolean