diff options
Diffstat (limited to 'src/generators.c')
| -rw-r--r-- | src/generators.c | 98 |
1 files changed, 40 insertions, 58 deletions
diff --git a/src/generators.c b/src/generators.c index 992370a..66ade6c 100644 --- a/src/generators.c +++ b/src/generators.c @@ -882,6 +882,44 @@ write_html_image (TGallerySetup *setup, } + +static void +mirror_files (TGallerySetup *setup, char **files, const char *src_tree, const char *dst_dir, const char *label) +{ + char **extra; + char *s1, *s2, *s3; + + if (files && g_strv_length (files) > 0) { + extra = files; + if (setup->verbose) printf ("%s", label); + while (*extra) { + s1 = g_strstrip (*extra); + if (strlen (s1) > 0) { + /* First create target directory if it doesn't exist */ + s2 = g_strconcat (dst_dir, "/", s1, NULL); + s3 = g_path_get_dirname (s2); + g_free (s2); + if (g_mkdir_with_parents (s3, DEFAULT_DATA_DIR_MODE)) { + fprintf (stderr, "error making target extra directory '%s': %s\n", s3, strerror (errno)); + g_free (s3); + continue; + } + g_free (s3); + + /* Copy the file */ + if (setup->verbose) printf (" %s", s1); + s2 = g_strconcat (src_tree, "/", s1, NULL); + s3 = g_strconcat (dst_dir, "/", s1, NULL); + copy_file (s2, s3); + g_free (s2); + g_free (s3); + } + extra++; + } + if (setup->verbose) printf ("\n"); + } +} + /* * build_tree: generate complete gallery tree based on source xml files * @@ -908,7 +946,6 @@ build_tree (TGallerySetup *setup, char *imgname; gboolean res; int i; - char **extra; printf ("*** Entering directory '%s'\n", src_tree); #ifdef __DEBUG_ALL__ @@ -948,36 +985,8 @@ build_tree (TGallerySetup *setup, items->parent_index = parent_index; items->parent_item_index = parent_item_index; - /* Copy support files */ - if (setup->verbose) printf ("Writing '%s' ...", setup->styles); - s1 = g_strconcat (setup->real_templates_dir, "/", setup->styles, NULL); - s2 = g_strconcat (dst_dir, "/", setup->styles, NULL); - copy_file (s1, s2); - g_free (s1); - g_free (s2); - if (setup->verbose) printf (" done.\n"); - - if (setup->verbose) printf ("Writing '%s' ...", setup->scripts); - s1 = g_strconcat (setup->real_templates_dir, "/", setup->scripts, NULL); - s2 = g_strconcat (dst_dir, "/", setup->scripts, NULL); - copy_file (s1, s2); - g_free (s1); - g_free (s2); - if (setup->verbose) printf (" done.\n"); - - if (setup->favicon_file && strlen (setup->favicon_file) > 0) { - if (setup->verbose) printf ("Writing '%s' ...", setup->favicon_file); - s3 = g_path_get_dirname (setup->setup_xml_path); - s1 = g_strconcat (s3, "/", setup->favicon_file, NULL); - s2 = g_strconcat (dst_dir, "/", setup->favicon_file, NULL); - copy_file (s1, s2); - g_free (s1); - g_free (s2); - g_free (s3); - if (setup->verbose) printf (" done.\n"); - } - + mirror_files (setup, setup->template_files, setup->real_templates_dir, dst_dir, "Copying template files: "); /* Prepare target thumbnail directory */ thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); @@ -1090,34 +1099,7 @@ build_tree (TGallerySetup *setup, } /* Copy extra files */ - if (items->extra_files && g_strv_length (items->extra_files) > 0) { - extra = items->extra_files; - while (*extra) { - s1 = g_strstrip (*extra); - if (strlen (s1) > 0) { - /* First create target directory if it doesn't exist */ - s2 = g_strconcat (dst_dir, "/", s1, NULL); - s3 = g_path_get_dirname (s2); - g_free (s2); - if (g_mkdir_with_parents (s3, DEFAULT_DATA_DIR_MODE)) { - fprintf (stderr, "error making target extra directory '%s': %s\n", s3, strerror (errno)); - g_free (s3); - continue; - } - g_free (s3); - - /* Copy the file */ - if (setup->verbose) printf ("Copying extra file '%s' ...", s1); - s2 = g_strconcat (src_tree, "/", s1, NULL); - s3 = g_strconcat (dst_dir, "/", s1, NULL); - copy_file (s2, s3); - g_free (s2); - g_free (s3); - if (setup->verbose) printf (" done.\n"); - } - extra++; - } - } + mirror_files (setup, items->extra_files, src_tree, dst_dir, "Copying extra files: "); printf ("*** Leaving directory '%s'\n", src_tree); free_album_data (items); |
