Revision: 41303
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41303
Author:   campbellbarton
Date:     2011-10-27 01:25:07 +0000 (Thu, 27 Oct 2011)
Log Message:
-----------
- remove bpath iterator and replace all uses with visitor.
- added flag to optionally receive all paths as absolute. 

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/blender.c
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/blenlib/BLI_bpath.h
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/editors/space_info/info_ops.c
    trunk/blender/source/blender/python/intern/bpy.c

Modified: trunk/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/blender.c    2011-10-27 
01:05:55 UTC (rev 41302)
+++ trunk/blender/source/blender/blenkernel/intern/blender.c    2011-10-27 
01:25:07 UTC (rev 41303)
@@ -160,23 +160,20 @@
        G.main= NULL;
 }
 
+static int clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const 
char *path_src)
+{
+       strcpy(path_dst, path_src);
+       BLI_clean(path_dst);
+       return (strcmp(path_dst, path_src) == 0) ? FALSE : TRUE;
+}
+
 /* make sure path names are correct for OS */
 static void clean_paths(Main *main)
 {
-       struct BPathIterator *bpi;
-       char filepath_expanded[1024];
        Scene *scene;
 
-       for(BLI_bpathIterator_init(&bpi, main, main->name, BPATH_USE_PACKED); 
!BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
-               BLI_bpathIterator_getPath(bpi, filepath_expanded);
+       bpath_traverse_main(main, clean_paths_visit_cb, 0, NULL);
 
-               BLI_clean(filepath_expanded);
-
-               BLI_bpathIterator_setPath(bpi, filepath_expanded);
-       }
-
-       BLI_bpathIterator_free(bpi);
-
        for(scene= main->scene.first; scene; scene= scene->id.next) {
                BLI_clean(scene->r.pic);
        }

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c      2011-10-27 
01:05:55 UTC (rev 41302)
+++ trunk/blender/source/blender/blenkernel/intern/image.c      2011-10-27 
01:25:07 UTC (rev 41303)
@@ -391,7 +391,7 @@
                iman->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(&iman->id, bpath_relocate_visitor, user_data);
+               bpath_traverse_id(bmain, &iman->id, bpath_relocate_visitor, 0, 
user_data);
 
                tex= bmain->tex.first;
                while(tex) {

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c    2011-10-27 
01:05:55 UTC (rev 41302)
+++ trunk/blender/source/blender/blenkernel/intern/library.c    2011-10-27 
01:25:07 UTC (rev 41303)
@@ -1253,7 +1253,7 @@
 void id_clear_lib_data(Main *bmain, ID *id)
 {
        char *user_data[2]= {bmain->name, id->lib->filepath};
-       bpath_traverse_id(id, bpath_relocate_visitor, user_data);
+       bpath_traverse_id(bmain, id, bpath_relocate_visitor, 0, user_data);
        id->lib= NULL;
        id->flag= LIB_LOCAL;
        new_id(which_libbase(bmain, GS(id->name)), id, NULL);

Modified: trunk/blender/source/blender/blenlib/BLI_bpath.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_bpath.h    2011-10-27 01:05:55 UTC 
(rev 41302)
+++ trunk/blender/source/blender/blenlib/BLI_bpath.h    2011-10-27 01:25:07 UTC 
(rev 41303)
@@ -34,38 +34,28 @@
 #ifndef BLI_BPATH_H
 #define BLI_BPATH_H
 
-struct BPathIterator;
 struct ReportList;
 struct Main;
 struct ID;
 
-void                   BLI_bpathIterator_init                          (struct 
BPathIterator **bpi, struct Main *bmain, const char *basedir, const int flag);
-void                   BLI_bpathIterator_free                          (struct 
BPathIterator *bpi);
-const char*            BLI_bpathIterator_getLib                        (struct 
BPathIterator *bpi);
-const char*            BLI_bpathIterator_getName                       (struct 
BPathIterator *bpi);
-int                            BLI_bpathIterator_getType                       
(struct BPathIterator *bpi);
-unsigned int   BLI_bpathIterator_getPathMaxLen         (struct BPathIterator 
*bpi);
-const char*            BLI_bpathIterator_getBasePath           (struct 
BPathIterator *bpi);
-void                   BLI_bpathIterator_step                          (struct 
BPathIterator *bpi);
-int                            BLI_bpathIterator_isDone                        
(struct BPathIterator *bpi);
-void                   BLI_bpathIterator_getPath                       (struct 
BPathIterator *bpi, char *path);
-void                   BLI_bpathIterator_getPathExpanded       (struct 
BPathIterator *bpi, char *path_expanded);
-void                   BLI_bpathIterator_setPath                       (struct 
BPathIterator *bpi, const char *path);
-
 /* Function that does something with an ID's file path. Should return 1 if the
    path has changed, and in that case, should write the result to pathOut. */
 typedef int (*BPathVisitor)(void *userdata, char *path_dst, const char 
*path_src);
 /* Executes 'visit' for each path associated with 'id'. */
-void bpath_traverse_id(struct ID *id, BPathVisitor visit, void *userdata);
+void bpath_traverse_id(struct Main *bmain, struct ID *id, BPathVisitor 
visit_cb, int flag, void *userdata);
+void bpath_traverse_id_list(struct Main *bmain, struct ListBase *lb, 
BPathVisitor visit_cb, int flag, void *userdata);
+void bpath_traverse_main(struct Main *bmain, BPathVisitor visit_cb, int flag, 
void *userdata);
 int bpath_relocate_visitor(void *oldbasepath, char *path_dst, const char 
*path_src);
 
+#define BPATH_TRAVERSE_ABS 1 /* convert paths to absolute */
+
 /* high level funcs */
 
 /* creates a text file with missing files if there are any */
 void checkMissingFiles(struct Main *bmain, struct ReportList *reports);
 void makeFilesRelative(struct Main *bmain, const char *basedir, struct 
ReportList *reports);
 void makeFilesAbsolute(struct Main *bmain, const char *basedir, struct 
ReportList *reports);
-void findMissingFiles(struct Main *bmain, const char *str);
+void findMissingFiles(struct Main *bmain, const char *searchpath, struct 
ReportList *reports);
 
 #define BPATH_USE_PACKED 1
 

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c 2011-10-27 01:05:55 UTC 
(rev 41302)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c 2011-10-27 01:25:07 UTC 
(rev 41303)
@@ -54,7 +54,6 @@
 #include "DNA_sound_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_vfont_types.h"
-#include "DNA_windowmanager_types.h"
 #include "DNA_object_types.h"
 #include "DNA_object_fluidsim.h"
 
@@ -62,7 +61,6 @@
 #include "BLI_bpath.h"
 #include "BLI_utildefines.h"
 
-#include "BKE_global.h"
 #include "BKE_image.h" /* so we can check the image's type */
 #include "BKE_sequencer.h"
 #include "BKE_main.h"
@@ -70,768 +68,116 @@
 #include "BKE_report.h"
 #include "BKE_library.h"
 
-typedef struct BPathIteratorSeqData
+static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), 
const char *path_src)
 {
-       int totseq;
-       int seq;
-       struct Sequence **seqar;        /* Sequence */
-       struct Scene *scene;            /* Current scene */
-} BPathIteratorSeqData;
+       ReportList *reports= (ReportList *)userdata;
 
-typedef struct BPathIterator
-{
-       char*   _path; /* never access directly, use BLI_bpathIterator_getPath 
*/
-       const char*     _lib;
-       const char*     _name;
-       void*   data;
-       int             len;
-       int             type;
-       int             flag; /* iterator options */
-
-       void (*setpath_callback)(struct BPathIterator *, const char *);
-       void (*getpath_callback)(struct BPathIterator *, char *);
-
-       const char*     base_path; /* base path, the directory the blend file 
is in - normally bmain->name */
-
-       Main *bmain;
-
-       /* only for seq data */
-       struct BPathIteratorSeqData seqdata;
-} BPathIterator;
-
-#define FILE_MAX                       240
-
-
-/* TODO - BPATH_PLUGIN, BPATH_SEQ */
-enum BPathTypes {
-       BPATH_IMAGE= 0,
-       BPATH_TEXTURE,
-       BPATH_TEXT,
-       BPATH_SOUND,
-       BPATH_FONT,
-       BPATH_LIB,
-       BPATH_SEQ,
-       BPATH_CDATA,
-
-       BPATH_DONE
-};
-
-void BLI_bpathIterator_init(struct BPathIterator **bpi_pt, Main *bmain, const 
char *basedir, const int flag)
-{
-       BPathIterator *bpi;
-
-       bpi= MEM_mallocN(sizeof(BPathIterator), "BLI_bpathIterator_init");
-       *bpi_pt= bpi;
-
-       bpi->type= BPATH_IMAGE;
-       bpi->data= NULL;
-
-       bpi->getpath_callback= NULL;
-       bpi->setpath_callback= NULL;
-
-       /* Sequencer specific */
-       bpi->seqdata.totseq= 0;
-       bpi->seqdata.seq= 0;
-       bpi->seqdata.seqar= NULL;
-       bpi->seqdata.scene= NULL;
-
-       bpi->flag= flag;
-
-       bpi->base_path= basedir; /* normally bmain->name */
-       bpi->bmain= bmain;
-
-       BLI_bpathIterator_step(bpi);
-}
-
-#if 0
-static void BLI_bpathIterator_alloc(struct BPathIterator **bpi)
-{
-       *bpi= MEM_mallocN(sizeof(BPathIterator), "BLI_bpathIterator_alloc");
-}
-#endif
-
-void BLI_bpathIterator_free(struct BPathIterator *bpi)
-{
-       if (bpi->seqdata.seqar)
-               MEM_freeN((void *)bpi->seqdata.seqar);
-       bpi->seqdata.seqar= NULL;
-       bpi->seqdata.scene= NULL;
-
-       MEM_freeN(bpi);
-}
-
-void BLI_bpathIterator_getPath(struct BPathIterator *bpi, char *path)
-{
-       if (bpi->getpath_callback) {
-               bpi->getpath_callback(bpi, path);
+       if (!BLI_exists(path_src)) {
+               BKE_reportf(reports, RPT_WARNING, "Path Not Found \"%s\"", 
path_src);
        }
-       else {
-               strcpy(path, bpi->_path); /* warning, we assume 'path' are long 
enough */
-       }
-}
 
-void BLI_bpathIterator_setPath(struct BPathIterator *bpi, const char *path)
-{
-       if (bpi->setpath_callback) {
-               bpi->setpath_callback(bpi, path);
-       }
-       else {
-               strcpy(bpi->_path, path); /* warning, we assume 'path' are long 
enough */
-       }
+       return FALSE;
 }
 
-void BLI_bpathIterator_getPathExpanded(struct BPathIterator *bpi, char 
*path_expanded)
+/* high level function */
+void checkMissingFiles(Main *bmain, ReportList *reports)
 {
-       const char *libpath;
-
-       BLI_bpathIterator_getPath(bpi, path_expanded);
-       libpath= BLI_bpathIterator_getLib(bpi);
-
-       if (libpath) { /* check the files location relative to its library path 
*/
-               BLI_path_abs(path_expanded, libpath);
-       }
-       else { /* local data, use the blend files path */
-               BLI_path_abs(path_expanded, bpi->base_path);
-       }
-       BLI_cleanup_file(NULL, path_expanded);
+       bpath_traverse_main(bmain, checkMissingFiles_visit_cb, 
BPATH_TRAVERSE_ABS, reports);
 }
-const char* BLI_bpathIterator_getLib(struct BPathIterator *bpi)
-{
-       return bpi->_lib;
-}
-const char* BLI_bpathIterator_getName(struct BPathIterator *bpi)
-{
-       return bpi->_name;
-}
-int    BLI_bpathIterator_getType(struct BPathIterator *bpi)
-{
-       return bpi->type;
-}
-unsigned int   BLI_bpathIterator_getPathMaxLen(struct BPathIterator *bpi)
-{
-       return bpi->len;
-}
-const char* BLI_bpathIterator_getBasePath(struct BPathIterator *bpi)
-{
-       return bpi->base_path;
-}
 
-/* gets the first or the next image that has a path - not a viewer node or 
generated image */
-static struct Image *ima_stepdata__internal(struct Image *ima, const int 
step_next, const int flag)
+typedef struct BPathRemap_Data
 {
-       if (ima==NULL)
-               return NULL;
+       const char *basedir;
+       ReportList *reports;
 
-       if (step_next)
-               ima= ima->id.next;
+       int count_tot;
+       int count_changed;
+       int count_failed;
+} BPathRemap_Data;
 
-       while (ima) {
-               if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, 
IMA_SRC_SEQUENCE)) {
-                       if(ima->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
-                               break;
-                       }
-               }

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to