diff --git a/app/file/file-open.c b/app/file/file-open.c index 9f6a5b6ee2..365abcb41e 100644 --- a/app/file/file-open.c +++ b/app/file/file-open.c @@ -87,6 +87,7 @@ static gboolean file_open_valid_permissions (GFile *file, GError **error); static gboolean file_open_pre_check (Gimp *gimp, GFile *file, + GimpImage *dest_image, gboolean as_link, GimpProgress *progress, GimpPlugInProcedure **file_proc, @@ -125,7 +126,7 @@ file_open_image (Gimp *gimp, g_return_val_if_fail (status != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - if (! file_open_pre_check (gimp, file, FALSE, progress, + if (! file_open_pre_check (gimp, file, NULL, FALSE, progress, &file_proc, &local_file, status, error)) return NULL; @@ -727,9 +728,8 @@ file_open_link_image (Gimp *gimp, const gchar **mime_type, GError **error) { - GimpImage *image = NULL; - GFile *dest_file = dest_image ? gimp_image_get_file (dest_image) : NULL; - gboolean loop_found = FALSE; + GimpImage *image = NULL; + GimpLink *link; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); @@ -738,86 +738,45 @@ file_open_link_image (Gimp *gimp, g_return_val_if_fail (status != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - if (! file_open_pre_check (gimp, file, TRUE, progress, + if (! file_open_pre_check (gimp, file, dest_image, TRUE, progress, &file_proc, NULL, status, error)) return NULL; - if (dest_file && gimp_plug_in_procedure_is_xcf_load (file_proc)) + link = gimp_link_new (gimp, file, + vector_width, vector_height, vector_keep_ratio, + progress, error); + + if (gimp_link_is_broken (link)) { - loop_found = xcf_load_file_equal (dest_file, file); - - if (! loop_found) - { - GInputStream *input; - GList *parent_files; - GList *loop_files = NULL; - XcfInfo info = { 0, }; - gint width; - gint height; - gint type; - GimpPrecision precision; - - parent_files = g_list_prepend (NULL, dest_file); - - input = G_INPUT_STREAM (g_file_read (file, NULL, NULL)); - if (input && xcf_load_magic_version (gimp, input, file, NULL, &info)) - xcf_load_image_header (gimp, &info, &width, &height, &type, &precision, - parent_files, &loop_files, &loop_found, NULL); - - g_clear_object (&input); - g_list_free (parent_files); - g_list_free_full (loop_files, g_object_unref); - } - } - - if (loop_found) - { - if (error && ! *error) - g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, - /* TODO: localize after string freeze ends. */ - "Cycling link detected with %s.", - g_file_peek_path (file)); + *status = GIMP_PDB_EXECUTION_ERROR; } else { - GimpLink *link; + GimpLayer *layer; + gint width; + gint height; - link = gimp_link_new (gimp, file, - vector_width, vector_height, vector_keep_ratio, - progress, error); + gimp_link_get_size (link, &width, &height); + image = gimp_image_new (gimp, width, height, + gimp_link_get_base_type (link), + gimp_link_get_precision (link)); + layer = gimp_link_layer_new (image, link); + gimp_image_add_layer (image, layer, NULL, 0, FALSE); - if (gimp_link_is_broken (link)) - { - *status = GIMP_PDB_EXECUTION_ERROR; - } - else - { - GimpLayer *layer; - gint width; - gint height; + if (! gimp_image_get_load_proc (image)) + gimp_image_set_load_proc (image, gimp_link_get_load_proc (link)); - gimp_link_get_size (link, &width, &height); - image = gimp_image_new (gimp, width, height, - gimp_link_get_base_type (link), - gimp_link_get_precision (link)); - layer = gimp_link_layer_new (image, link); - gimp_image_add_layer (image, layer, NULL, 0, FALSE); + file_proc = gimp_image_get_load_proc (image); + if (mime_type) + *mime_type = g_slist_nth_data (file_proc->mime_types_list, 0); + if (file_proc_handles_vector) + *file_proc_handles_vector = file_proc->handles_vector; - if (! gimp_image_get_load_proc (image)) - gimp_image_set_load_proc (image, gimp_link_get_load_proc (link)); - - file_proc = gimp_image_get_load_proc (image); - if (mime_type) - *mime_type = g_slist_nth_data (file_proc->mime_types_list, 0); - if (file_proc_handles_vector) - *file_proc_handles_vector = file_proc->handles_vector; - - *status = GIMP_PDB_SUCCESS; - } - - g_clear_object (&link); + *status = GIMP_PDB_SUCCESS; } + g_clear_object (&link); + return image; } @@ -968,6 +927,7 @@ file_open_valid_permissions (GFile *file, static gboolean file_open_pre_check (Gimp *gimp, GFile *file, + GimpImage *dest_image, gboolean as_link, GimpProgress *progress, GimpPlugInProcedure **file_proc, @@ -975,8 +935,8 @@ file_open_pre_check (Gimp *gimp, GimpPDBStatusType *status, GError **error) { - gboolean mounted = TRUE; - GError *my_error = NULL; + gboolean mounted = TRUE; + GError *my_error = NULL; g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (file_proc != NULL, FALSE); @@ -997,6 +957,8 @@ file_open_pre_check (Gimp *gimp, if (as_link) { + GFile *dest_file = dest_image ? gimp_image_get_file (dest_image) : NULL; + if (! g_file_is_native (file)) { gchar *uri = g_file_get_uri (file); @@ -1013,6 +975,46 @@ file_open_pre_check (Gimp *gimp, return FALSE; } + if (dest_file && gimp_plug_in_procedure_is_xcf_load (*file_proc)) + { + gboolean loop_found = xcf_load_file_equal (dest_file, file); + + if (! loop_found) + { + GInputStream *input; + GList *parent_files; + GList *loop_files = NULL; + XcfInfo info = { 0, }; + gint width; + gint height; + gint type; + GimpPrecision precision; + + parent_files = g_list_prepend (NULL, dest_file); + + input = G_INPUT_STREAM (g_file_read (file, NULL, NULL)); + if (input && xcf_load_magic_version (gimp, input, file, NULL, &info)) + xcf_load_image_header (gimp, &info, &width, &height, &type, &precision, + parent_files, &loop_files, &loop_found, NULL); + + g_clear_object (&input); + g_list_free (parent_files); + g_list_free_full (loop_files, g_object_unref); + } + + if (loop_found) + { + g_clear_error (error); + if (error && ! *error) + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + /* TODO: localize after string freeze ends. */ + "Cycling link detected with %s.", + g_file_peek_path (file)); + + return FALSE; + } + } + return (*file_proc != NULL); }