run: Use the new xdg_app_list_extensions helper

tingping/wmclass
Alexander Larsson 2016-01-20 12:33:55 +01:00
parent d959ed016c
commit bc892f1745
1 changed files with 15 additions and 60 deletions

View File

@ -1227,33 +1227,6 @@ xdg_app_add_bus_filters (GPtrArray *dbus_proxy_argv,
}
}
static void
add_extension_arg (const char *directory,
gboolean is_app,
const char *extension,
const char *arch,
const char *branch,
GPtrArray *argv_array,
GCancellable *cancellable)
{
g_autofree char *extension_ref;
g_autoptr(GFile) deploy = NULL;
g_autofree char *full_directory = NULL;
full_directory = g_build_filename (is_app ? "/app" : "/usr", directory, NULL);
extension_ref = g_build_filename ("runtime", extension, arch, branch, NULL);
deploy = xdg_app_find_deploy_dir_for_ref (extension_ref, cancellable, NULL);
if (deploy != NULL)
{
g_autoptr(GFile) files = g_file_get_child (deploy, "files");
g_ptr_array_add (argv_array, g_strdup ("-b"));
g_ptr_array_add (argv_array, g_strdup_printf ("%s=%s", full_directory, gs_file_get_path_cached (files)));
}
}
gboolean
xdg_app_run_add_extension_args (GPtrArray *argv_array,
GKeyFile *metakey,
@ -1263,8 +1236,8 @@ xdg_app_run_add_extension_args (GPtrArray *argv_array,
{
g_auto(GStrv) groups = NULL;
g_auto(GStrv) parts = NULL;
int i;
gboolean is_app;
GList *extensions, *l;
parts = g_strsplit (full_ref, "/", 0);
if (g_strv_length (parts) != 4)
@ -1272,45 +1245,27 @@ xdg_app_run_add_extension_args (GPtrArray *argv_array,
is_app = strcmp (parts[0], "app") == 0;
groups = g_key_file_get_groups (metakey, NULL);
for (i = 0; groups[i] != NULL; i++)
extensions = xdg_app_list_extensions (metakey,
parts[2], parts[3]);
for (l = extensions; l != NULL; l = l->next)
{
char *extension;
XdgAppExtension *ext = l->data;
g_autoptr(GFile) deploy = NULL;
if (g_str_has_prefix (groups[i], "Extension ") &&
*(extension = (groups[i] + strlen ("Extension "))) != 0)
deploy = xdg_app_find_deploy_dir_for_ref (ext->ref, cancellable, NULL);
if (deploy != NULL)
{
g_autofree char *directory = g_key_file_get_string (metakey, groups[i], "directory", NULL);
g_autofree char *version = g_key_file_get_string (metakey, groups[i], "version", NULL);
g_autoptr(GFile) files = g_file_get_child (deploy, "files");
g_autofree char *full_directory = g_build_filename (is_app ? "/app" : "/usr", ext->directory, NULL);
if (directory == NULL)
continue;
if (g_key_file_get_boolean (metakey, groups[i],
"subdirectories", NULL))
{
g_autofree char *prefix = g_strconcat (extension, ".", NULL);
g_auto(GStrv) refs = NULL;
int i;
refs = xdg_app_list_deployed_refs ("runtime", prefix, parts[2], parts[3],
cancellable, error);
if (refs == NULL)
return FALSE;
for (i = 0; refs[i] != NULL; i++)
{
g_autofree char *extended_dir = g_build_filename (directory, refs[i] + strlen (prefix), NULL);
add_extension_arg (extended_dir, is_app, refs[i], parts[2], parts[3],
argv_array, cancellable);
}
}
else
add_extension_arg (directory, is_app, extension, parts[2], version ? version : parts[3],
argv_array, cancellable);
g_ptr_array_add (argv_array, g_strdup ("-b"));
g_ptr_array_add (argv_array, g_strdup_printf ("%s=%s", full_directory, gs_file_get_path_cached (files)));
}
}
g_list_free_full (extensions, (GDestroyNotify)xdg_app_extension_free);
return TRUE;
}