Merged changes in the trunk up to revision 51718.
[blender.git] / source / blender / blenlib / intern / bpath.c
index f90bb4d61520f7695613d31e2b891272142a86d4..2f335b557fe33d63a709261bed2d0a3735c787ac 100644 (file)
 #include "DNA_vfont_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_smoke_types.h"
+#include "DNA_freestyle_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_bpath.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_font.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_sequencer.h"
-#include "BKE_utildefines.h"
 #include "BKE_image.h" /* so we can check the image's type */
 
 static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
@@ -85,7 +86,7 @@ static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), co
        ReportList *reports = (ReportList *)userdata;
 
        if (!BLI_exists(path_src)) {
-               BKE_reportf(reports, RPT_WARNING, "Path Not Found \"%s\"", path_src);
+               BKE_reportf(reports, RPT_WARNING, "Path '%s' not found", path_src);
        }
 
        return FALSE;
@@ -112,17 +113,17 @@ static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char
 
        data->count_tot++;
 
-       if (strncmp(path_src, "//", 2) == 0) {
+       if (BLI_path_is_rel(path_src)) {
                return FALSE; /* already relative */
        }
        else {
                strcpy(path_dst, path_src);
                BLI_path_rel(path_dst, data->basedir);
-               if (strncmp(path_dst, "//", 2) == 0) {
+               if (BLI_path_is_rel(path_dst)) {
                        data->count_changed++;
                }
                else {
-                       BKE_reportf(data->reports, RPT_WARNING, "Path cant be made relative \"%s\"", path_src);
+                       BKE_reportf(data->reports, RPT_WARNING, "Path '%s' cannot be made relative", path_src);
                        data->count_failed++;
                }
                return TRUE;
@@ -144,7 +145,7 @@ void BLI_bpath_relative_convert(Main *bmain, const char *basedir, ReportList *re
        BLI_bpath_traverse_main(bmain, makeFilesRelative_visit_cb, 0, (void *)&data);
 
        BKE_reportf(reports, data.count_failed ? RPT_WARNING : RPT_INFO,
-                   "Total files %d|Changed %d|Failed %d",
+                   "Total files %d | Changed %d | Failed %d",
                    data.count_tot, data.count_changed, data.count_failed);
 }
 
@@ -154,17 +155,17 @@ static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char
 
        data->count_tot++;
 
-       if (strncmp(path_src, "//", 2) != 0) {
+       if (BLI_path_is_rel(path_src) == FALSE) {
                return FALSE; /* already absolute */
        }
        else {
                strcpy(path_dst, path_src);
                BLI_path_abs(path_dst, data->basedir);
-               if (strncmp(path_dst, "//", 2) != 0) {
+               if (BLI_path_is_rel(path_dst) == FALSE) {
                        data->count_changed++;
                }
                else {
-                       BKE_reportf(data->reports, RPT_WARNING, "Path cant be made absolute \"%s\"", path_src);
+                       BKE_reportf(data->reports, RPT_WARNING, "Path '%s' cannot be made absolute", path_src);
                        data->count_failed++;
                }
                return TRUE;
@@ -187,16 +188,18 @@ void BLI_bpath_absolute_convert(Main *bmain, const char *basedir, ReportList *re
        BLI_bpath_traverse_main(bmain, makeFilesAbsolute_visit_cb, 0, (void *)&data);
 
        BKE_reportf(reports, data.count_failed ? RPT_WARNING : RPT_INFO,
-                   "Total files %d|Changed %d|Failed %d",
+                   "Total files %d | Changed %d | Failed %d",
                    data.count_tot, data.count_changed, data.count_failed);
 }
 
-/* find this file recursively, use the biggest file so thumbnails don't get used by mistake
- * - dir: subdir to search
- * - filename: set this filename
- * - filesize: filesize for the file
+/**
+ * find this file recursively, use the biggest file so thumbnails don't get used by mistake
+ * \param filename_new: the path will be copied here, caller must initialize as empty string.
+ * \param dirname: subdir to search
+ * \param filename: set this filename
+ * \param filesize: filesize for the file
  *
- * return found: 1/0.
+ * \returns found: 1/0.
  */
 #define MAX_RECUR 16
 static int findFileRecursive(char *filename_new,
@@ -213,8 +216,6 @@ static int findFileRecursive(char *filename_new,
        int size;
        int found = FALSE;
 
-       filename_new[0] = '\0';
-
        dir = opendir(dirname);
 
        if (dir == NULL)
@@ -271,19 +272,21 @@ static int findMissingFiles_visit_cb(void *userdata, char *path_dst, const char
        int recur_depth = 0;
        int found;
 
+       filename_new[0] = '\0';
+
        found = findFileRecursive(filename_new,
                                  data->searchdir, BLI_path_basename((char *)path_src),
                                  &filesize, &recur_depth);
 
        if (filesize == -1) { /* could not open dir */
                BKE_reportf(data->reports, RPT_WARNING,
-                           "Could open directory \"%s\"",
+                           "Could not open directory '%s'",
                            BLI_path_basename(data->searchdir));
                return FALSE;
        }
        else if (found == FALSE) {
                BKE_reportf(data->reports, RPT_WARNING,
-                           "Could not find \"%s\" in \"%s\"",
+                           "Could not find '%s' in '%s'",
                            BLI_path_basename((char *)path_src), data->searchdir);
                return FALSE;
        }
@@ -482,9 +485,9 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
                        break;
                case ID_VF:
                {
-                       VFont *vf = (VFont *)id;
-                       if (vf->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
-                               if (strcmp(vf->name, FO_BUILTIN_NAME) != 0) {
+                       VFont *vfont = (VFont *)id;
+                       if (vfont->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
+                               if (BKE_vfont_is_builtin(vfont) == FALSE) {
                                        rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, bpath_user_data);
                                }
                        }
@@ -493,11 +496,6 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
                case ID_TE:
                {
                        Tex *tex = (Tex *)id;
-                       if (tex->plugin) {
-                               /* FIXME: rewrite_path assumes path length of FILE_MAX, but
-                                * tex->plugin->name is 160. ... is this field even a path? */
-                               //rewrite_path(tex->plugin->name, visit_cb, bpath_user_data);
-                       }
                        if (tex->type == TEX_VOXELDATA && TEX_VD_IS_SOURCE_PATH(tex->vd->file_format)) {
                                rewrite_path_fixed(tex->vd->source_path, visit_cb, absbase, bpath_user_data);
                        }
@@ -507,17 +505,18 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
                case ID_SCE:
                {
                        Scene *scene = (Scene *)id;
+                       SceneRenderLayer *srl= scene->r.layers.first;
                        if (scene->ed) {
                                Sequence *seq;
 
                                SEQ_BEGIN(scene->ed, seq)
                                {
                                        if (SEQ_HAS_PATH(seq)) {
-                                               if (ELEM(seq->type, SEQ_MOVIE, SEQ_SOUND)) {
+                                               if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM)) {
                                                        rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name,
                                                                                   visit_cb, absbase, bpath_user_data);
                                                }
-                                               else if (seq->type == SEQ_IMAGE) {
+                                               else if (seq->type == SEQ_TYPE_IMAGE) {
                                                        /* might want an option not to loop over all strips */
                                                        StripElem *se = seq->strip->stripdata;
                                                        int len = MEM_allocN_len(se) / sizeof(*se);
@@ -538,20 +537,23 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
                                                        rewrite_path_fixed(seq->strip->dir, visit_cb, absbase, bpath_user_data);
                                                }
                                        }
-                                       else if (seq->plugin) {
-                                               rewrite_path_fixed(seq->plugin->name, visit_cb, absbase, bpath_user_data);
-                                       }
 
                                }
                                SEQ_END
                        }
+                       for(; srl; srl= srl->next) {
+                               FreestyleModuleConfig* module= srl->freestyleConfig.modules.first;
+                               for (; module; module= module->next) {
+                                       rewrite_path_fixed(module->module_path, visit_cb, absbase, bpath_user_data);
+                               }
+                       }
                }
                break;
                case ID_ME:
                {
                        Mesh *me = (Mesh *)id;
-                       if (me->fdata.external) {
-                               rewrite_path_fixed(me->fdata.external->filename, visit_cb, absbase, bpath_user_data);
+                       if (me->ldata.external) {
+                               rewrite_path_fixed(me->ldata.external->filename, visit_cb, absbase, bpath_user_data);
                        }
                }
                break;
@@ -601,7 +603,7 @@ int BLI_bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *pat
        const char *base_new = ((char **)pathbase_v)[0];
        const char *base_old = ((char **)pathbase_v)[1];
 
-       if (strncmp(base_old, "//", 2) == 0) {
+       if (BLI_path_is_rel(base_old)) {
                printf("%s: error, old base path '%s' is not absolute.\n",
                       __func__, base_old);
                return FALSE;