- converted path cleaning on file load to use bPath Iterator functions - image &...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 6 Dec 2010 00:52:30 +0000 (00:52 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 6 Dec 2010 00:52:30 +0000 (00:52 +0000)
- skip fixing file paths on undo.
- simplify bpath alloc and free functions, also pass Main structure so as not to rely on G.main, (needed for file load).

source/blender/blenkernel/intern/blender.c
source/blender/blenlib/BLI_bpath.h
source/blender/blenlib/intern/bpath.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/space_info/info_ops.c
source/blender/python/intern/bpy.c

index 6911e7f..6ceb75f 100644 (file)
@@ -55,6 +55,7 @@
 #include "DNA_sound_types.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_bpath.h"
 #include "BLI_dynstr.h"
 #include "BLI_path_util.h"
 
@@ -154,49 +155,32 @@ static void clear_global(void)
 /* make sure path names are correct for OS */
 static void clean_paths(Main *main)
 {
-       Image *image= main->image.first;
-       bSound *sound= main->sound.first;
-       Scene *scene= main->scene.first;
-       Editing *ed;
-       Sequence *seq;
-       Strip *strip;
-       
-       while(image) {
-               BLI_clean(image->name);
-               image= image->id.next;
-       }
-       
-       while(sound) {
-               BLI_clean(sound->name);
-               sound= sound->id.next;
+       struct BPathIterator *bpi;
+       char filepath_expanded[1024];
+       Scene *scene;
+
+       for(BLI_bpathIterator_init(&bpi, main, main->name); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
+               BLI_bpathIterator_getPath(bpi, filepath_expanded);
+
+               BLI_clean(filepath_expanded);
+
+               BLI_bpathIterator_setPath(bpi, filepath_expanded);
        }
-       
-       while(scene) {
-               ed= seq_give_editing(scene, 0);
-               if(ed) {
-                       seq= ed->seqbasep->first;
-                       while(seq) {
-                               if(seq->plugin) {
-                                       BLI_clean(seq->plugin->name);
-                               }
-                               strip= seq->strip;
-                               while(strip) {
-                                       BLI_clean(strip->dir);
-                                       strip= strip->next;
-                               }
-                               seq= seq->next;
-                       }
-               }
+
+       BLI_bpathIterator_free(bpi);
+
+       for(scene= main->scene.first; scene; scene= scene->id.next) {
                BLI_clean(scene->r.backbuf);
                BLI_clean(scene->r.pic);
-               
-               scene= scene->id.next;
        }
 }
 
 /* context matching */
 /* handle no-ui case */
 
+/* note, this is called on Undo so any slow conversion functions here
+ * should be avoided or check (mode!='u') */
+
 static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filename) 
 {
        bScreen *curscreen= NULL;
@@ -210,9 +194,12 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filename
        else mode= 0;
 
        recover= (G.fileflags & G_FILE_RECOVER);
-       
-       clean_paths(bfd->main);
-       
+
+       /* Only make filepaths compatible when loading for real (not undo) */
+       if(mode != 'u') {
+               clean_paths(bfd->main);
+       }
+
        /* XXX here the complex windowmanager matching */
        
        /* no load screens? */
index 34ccb0c..ff00506 100644 (file)
 #define BLI_BPATH_H
 
 struct BPathIterator;
+struct ReportList;
+struct Main;
 
-
-void                   BLI_bpathIterator_init                          (struct BPathIterator *bpi, const char *base_path);
-void                   BLI_bpathIterator_alloc                         (struct BPathIterator **bpi);
+void                   BLI_bpathIterator_init                          (struct BPathIterator **bpi, struct Main *bmain, const char *basedir);
 void                   BLI_bpathIterator_free                          (struct BPathIterator *bpi);
 const char*            BLI_bpathIterator_getLib                        (struct BPathIterator *bpi);
 const char*            BLI_bpathIterator_getName                       (struct BPathIterator *bpi);
@@ -52,9 +52,9 @@ void                  BLI_bpathIterator_setPath                       (struct BPathIterator *bpi, const char *path)
 /* high level funcs */
 
 /* creates a text file with missing files if there are any */
-void checkMissingFiles(const char *basepath, ReportList *reports);
-void makeFilesRelative(const char *basepath, ReportList *reports);
-void makeFilesAbsolute(const char *basepath, ReportList *reports);
-void findMissingFiles(const char *basepath, const char *str);
+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);
 
 #endif // BLI_BPATH_H
index ab25f9f..f8421fa 100644 (file)
@@ -57,8 +57,8 @@
 
 #include "BKE_global.h"
 #include "BKE_image.h" /* so we can check the image's type */
-#include "BKE_main.h" /* so we can access G.main->*.first */
 #include "BKE_sequencer.h"
+#include "BKE_main.h"
 #include "BKE_utildefines.h"
 #include "BKE_report.h"
 
@@ -87,7 +87,9 @@ typedef struct BPathIterator {
        void (*setpath_callback)(struct BPathIterator *, const char *);
        void (*getpath_callback)(struct BPathIterator *, char *);
 
-       const char*     base_path; /* base path, the directry the blend file is in - normally G.main->name */
+       const char*     base_path; /* base path, the directry the blend file is in - normally bmain->name */
+
+       Main *bmain;
 
        /* only for seq data */
        struct BPathIteratorSeqData seqdata;
@@ -110,7 +112,12 @@ enum BPathTypes {
         BPATH_DONE
 };
 
-void BLI_bpathIterator_init( struct BPathIterator *bpi, const char *base_path ) {
+void BLI_bpathIterator_init(struct BPathIterator **bpi_pt, Main *bmain, const char *basedir) {
+       BPathIterator *bpi;
+
+       bpi= MEM_mallocN(sizeof(BPathIterator), "BLI_bpathIterator_init");
+       *bpi_pt= bpi;
+
        bpi->type= BPATH_IMAGE;
        bpi->data= NULL;
        
@@ -123,7 +130,8 @@ void BLI_bpathIterator_init( struct BPathIterator *bpi, const char *base_path )
        bpi->seqdata.seqar= NULL;
        bpi->seqdata.scene= NULL;
        
-       bpi->base_path= base_path ? base_path : G.main->name;
+       bpi->base_path= basedir; /* normally bmain->name */
+       bpi->bmain= bmain;
 
        BLI_bpathIterator_step(bpi);
 }
@@ -132,30 +140,32 @@ void BLI_bpathIterator_alloc(struct BPathIterator **bpi) {
        *bpi= MEM_mallocN(sizeof(BPathIterator), "BLI_bpathIterator_alloc");
 }
 
-void BLI_bpathIterator_free( struct BPathIterator *bpi ) {
+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) {
+void BLI_bpathIterator_getPath(struct BPathIterator *bpi, char *path) {
        if (bpi->getpath_callback) {
-               bpi->getpath_callback( bpi, path );
+               bpi->getpath_callback(bpi, path);
        } else {
                strcpy(path, bpi->_path); /* warning, we assume 'path' are long enough */
        }
 }
 
-void BLI_bpathIterator_setPath( struct BPathIterator *bpi, const char *path) {
+void BLI_bpathIterator_setPath(struct BPathIterator *bpi, const char *path) {
        if (bpi->setpath_callback) {
-               bpi->setpath_callback( bpi, path );
+               bpi->setpath_callback(bpi, path);
        } else {
                strcpy(bpi->_path, path); /* warning, we assume 'path' are long enough */
        }
 }
 
-void BLI_bpathIterator_getPathExpanded( struct BPathIterator *bpi, char *path_expanded) {
+void BLI_bpathIterator_getPathExpanded(struct BPathIterator *bpi, char *path_expanded) {
        const char *libpath;
        
        BLI_bpathIterator_getPath(bpi, path_expanded);
@@ -168,19 +178,19 @@ void BLI_bpathIterator_getPathExpanded( struct BPathIterator *bpi, char *path_ex
        }
        BLI_cleanup_file(NULL, path_expanded);
 }
-const char* BLI_bpathIterator_getLib( struct BPathIterator *bpi) {
+const char* BLI_bpathIterator_getLib(struct BPathIterator *bpi) {
        return bpi->_lib;
 }
-const char* BLI_bpathIterator_getName( struct BPathIterator *bpi) {
+const char* BLI_bpathIterator_getName(struct BPathIterator *bpi) {
        return bpi->_name;
 }
-int    BLI_bpathIterator_getType( struct BPathIterator *bpi) {
+int    BLI_bpathIterator_getType(struct BPathIterator *bpi) {
        return bpi->type;
 }
-int    BLI_bpathIterator_getPathMaxLen( struct BPathIterator *bpi) {
+int    BLI_bpathIterator_getPathMaxLen(struct BPathIterator *bpi) {
        return bpi->len;
 }
-const char* BLI_bpathIterator_getBasePath( struct BPathIterator *bpi) {
+const char* BLI_bpathIterator_getBasePath(struct BPathIterator *bpi) {
        return bpi->base_path;
 }
 
@@ -276,7 +286,7 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
        
        /* Initializing */
        if (bpi->seqdata.scene==NULL) {
-               bpi->seqdata.scene= G.main->scene.first;
+               bpi->seqdata.scene= bpi->bmain->scene.first;
        }
        
        if (step_next) {
@@ -403,7 +413,7 @@ static struct Mesh *cdata_stepdata__internal(struct Mesh *me, int step_next) {
        return me;
 }
 
-static void bpi_type_step__internal( struct BPathIterator *bpi) {
+static void bpi_type_step__internal(struct BPathIterator *bpi) {
        bpi->type++; /* advance to the next type */
        bpi->data= NULL;
        
@@ -423,13 +433,13 @@ static void bpi_type_step__internal( struct BPathIterator *bpi) {
        }
 }
 
-void BLI_bpathIterator_step( struct BPathIterator *bpi) {
+void BLI_bpathIterator_step(struct BPathIterator *bpi) {
        while (bpi->type != BPATH_DONE) {
                
                if  ((bpi->type) == BPATH_IMAGE) {
                        /*if (bpi->data)        bpi->data= ((ID *)bpi->data)->next;*/
                        if (bpi->data)  bpi->data= ima_stepdata__internal( (Image *)bpi->data, 1 ); /* must skip images that have no path */
-                       else                    bpi->data= ima_stepdata__internal(G.main->image.first, 0);
+                       else                    bpi->data= ima_stepdata__internal(bpi->bmain->image.first, 0);
                        
                        if (bpi->data) {
                                /* get the path info from this datatype */
@@ -451,7 +461,7 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
                if  ((bpi->type) == BPATH_TEXTURE) {
                        /*if (bpi->data)        bpi->data= ((ID *)bpi->data)->next;*/
                        if (bpi->data)  bpi->data= tex_stepdata__internal( (Tex *)bpi->data, 1 ); /* must skip images that have no path */
-                       else                    bpi->data= tex_stepdata__internal(G.main->tex.first, 0);
+                       else                    bpi->data= tex_stepdata__internal(bpi->bmain->tex.first, 0);
 
                        if (bpi->data) {
                                /* get the path info from this datatype */
@@ -478,7 +488,7 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
                if  ((bpi->type) == BPATH_TEXT) {
                        /*if (bpi->data)        bpi->data= ((ID *)bpi->data)->next;*/
                        if (bpi->data)  bpi->data= text_stepdata__internal( (Text *)bpi->data, 1 ); /* must skip images that have no path */
-                       else                    bpi->data= text_stepdata__internal(G.main->text.first, 0);
+                       else                    bpi->data= text_stepdata__internal(bpi->bmain->text.first, 0);
 
                        if (bpi->data) {
                                /* get the path info from this datatype */
@@ -499,7 +509,7 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
 
                else if  ((bpi->type) == BPATH_SOUND) {
                        if (bpi->data)  bpi->data= snd_stepdata__internal( (bSound *)bpi->data, 1 ); /* must skip images that have no path */
-                       else                    bpi->data= snd_stepdata__internal(G.main->sound.first, 0);
+                       else                    bpi->data= snd_stepdata__internal(bpi->bmain->sound.first, 0);
 
                        if (bpi->data) {
                                /* get the path info from this datatype */
@@ -520,7 +530,7 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
                } else if  ((bpi->type) == BPATH_FONT) {
                        
                        if (bpi->data)  bpi->data= vf_stepdata__internal( (VFont *)bpi->data, 1 );
-                       else                    bpi->data= vf_stepdata__internal( G.main->vfont.first, 0 );
+                       else                    bpi->data= vf_stepdata__internal( bpi->bmain->vfont.first, 0 );
                        
                        if (bpi->data) {
                                /* get the path info from this datatype */
@@ -539,7 +549,7 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
 
                } else if  ((bpi->type) == BPATH_LIB) {
                        if (bpi->data)  bpi->data= ((ID *)bpi->data)->next;
-                       else                    bpi->data= G.main->library.first;
+                       else                    bpi->data= bpi->bmain->library.first;
                        
                        if (bpi->data) {
                                /* get the path info from this datatype */
@@ -569,7 +579,7 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
                        }
                } else if  ((bpi->type) == BPATH_CDATA) {
                        if (bpi->data)  bpi->data= cdata_stepdata__internal( bpi->data, 1 );
-                       else                    bpi->data= cdata_stepdata__internal( G.main->mesh.first, 0 );
+                       else                    bpi->data= cdata_stepdata__internal( bpi->bmain->mesh.first, 0 );
 
                        if (bpi->data) {
                                Mesh *me= (Mesh *)bpi->data;
@@ -640,38 +650,38 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
 }
 
 /* high level function */
-void checkMissingFiles(const char *basepath, ReportList *reports) {
-       struct BPathIterator bpi;
+void checkMissingFiles(Main *bmain, ReportList *reports) {
+       struct BPathIterator *bpi;
        
        /* be sure there is low chance of the path being too short */
        char filepath_expanded[FILE_MAXDIR*2]; 
        
-       BLI_bpathIterator_init(&bpi, basepath);
-       while (!BLI_bpathIterator_isDone(&bpi)) {
-               BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded );
+       BLI_bpathIterator_init(&bpi, bmain, bmain->name);
+       while (!BLI_bpathIterator_isDone(bpi)) {
+               BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
                
                if (!BLI_exists(filepath_expanded))
-                       bpath_as_report(&bpi, "file not found", reports);
+                       bpath_as_report(bpi, "file not found", reports);
 
-               BLI_bpathIterator_step(&bpi);
+               BLI_bpathIterator_step(bpi);
        }
-       BLI_bpathIterator_free(&bpi);
+       BLI_bpathIterator_free(bpi);
 }
 
 /* dont log any errors at the moment, should probably do this */
-void makeFilesRelative(const char *basepath, ReportList *reports) {
+void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) {
        int tot= 0, changed= 0, failed= 0, linked= 0;
-       struct BPathIterator bpi;
+       struct BPathIterator *bpi;
        char filepath[FILE_MAX];
        const char *libpath;
        
        /* be sure there is low chance of the path being too short */
        char filepath_relative[(FILE_MAXDIR * 2) + FILE_MAXFILE];
        
-       BLI_bpathIterator_init(&bpi, basepath);
-       while (!BLI_bpathIterator_isDone(&bpi)) {
-               BLI_bpathIterator_getPath(&bpi, filepath);
-               libpath= BLI_bpathIterator_getLib(&bpi);
+       BLI_bpathIterator_init(&bpi, bmain, basedir);
+       while (!BLI_bpathIterator_isDone(bpi)) {
+               BLI_bpathIterator_getPath(bpi, filepath);
+               libpath= BLI_bpathIterator_getLib(bpi);
                
                if(strncmp(filepath, "//", 2)) {
                        if (libpath) { /* cant make relative if we are library - TODO, LOG THIS */
@@ -680,27 +690,27 @@ void makeFilesRelative(const char *basepath, ReportList *reports) {
                                BLI_strncpy(filepath_relative, filepath, sizeof(filepath_relative));
                                /* Important BLI_cleanup_dir runs before the path is made relative
                                 * because it wont work for paths that start with "//../" */ 
-                               BLI_cleanup_file(bpi.base_path, filepath_relative); /* fix any /foo/../foo/ */
-                               BLI_path_rel(filepath_relative, bpi.base_path);
+                               BLI_cleanup_file(bpi->base_path, filepath_relative); /* fix any /foo/../foo/ */
+                               BLI_path_rel(filepath_relative, bpi->base_path);
                                /* be safe and check the length */
-                               if (BLI_bpathIterator_getPathMaxLen(&bpi) <= strlen(filepath_relative)) {
-                                       bpath_as_report(&bpi, "couldn't make path relative (too long)", reports);
+                               if (BLI_bpathIterator_getPathMaxLen(bpi) <= strlen(filepath_relative)) {
+                                       bpath_as_report(bpi, "couldn't make path relative (too long)", reports);
                                        failed++;
                                } else {
                                        if(strncmp(filepath_relative, "//", 2)==0) {
-                                               BLI_bpathIterator_setPath(&bpi, filepath_relative);
+                                               BLI_bpathIterator_setPath(bpi, filepath_relative);
                                                changed++;
                                        } else {
-                                               bpath_as_report(&bpi, "couldn't make path relative", reports);
+                                               bpath_as_report(bpi, "couldn't make path relative", reports);
                                                failed++;
                                        }
                                }
                        }
                }
-               BLI_bpathIterator_step(&bpi);
+               BLI_bpathIterator_step(bpi);
                tot++;
        }
-       BLI_bpathIterator_free(&bpi);
+       BLI_bpathIterator_free(bpi);
 
        if(reports)
                BKE_reportf(reports, failed ? RPT_ERROR : RPT_INFO, "Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
@@ -708,47 +718,47 @@ void makeFilesRelative(const char *basepath, ReportList *reports) {
 
 /* dont log any errors at the moment, should probably do this -
  * Verry similar to makeFilesRelative - keep in sync! */
-void makeFilesAbsolute(const char *basepath, ReportList *reports)
+void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports)
 {
        int tot= 0, changed= 0, failed= 0, linked= 0;
 
-       struct BPathIterator bpi;
+       struct BPathIterator *bpi;
        char filepath[FILE_MAX];
        const char *libpath;
        
        /* be sure there is low chance of the path being too short */
        char filepath_absolute[(FILE_MAXDIR * 2) + FILE_MAXFILE];
        
-       BLI_bpathIterator_init(&bpi, basepath);
-       while (!BLI_bpathIterator_isDone(&bpi)) {
-               BLI_bpathIterator_getPath(&bpi, filepath);
-               libpath= BLI_bpathIterator_getLib(&bpi);
+       BLI_bpathIterator_init(&bpi, bmain, basedir);
+       while (!BLI_bpathIterator_isDone(bpi)) {
+               BLI_bpathIterator_getPath(bpi, filepath);
+               libpath= BLI_bpathIterator_getLib(bpi);
                
                if(strncmp(filepath, "//", 2)==0) {
                        if (libpath) { /* cant make absolute if we are library - TODO, LOG THIS */
                                linked++;
                        } else { /* get the expanded path and check it is relative or too long */
-                               BLI_bpathIterator_getPathExpanded( &bpi, filepath_absolute );
-                               BLI_cleanup_file(bpi.base_path, filepath_absolute); /* fix any /foo/../foo/ */
+                               BLI_bpathIterator_getPathExpanded(bpi, filepath_absolute);
+                               BLI_cleanup_file(bpi->base_path, filepath_absolute); /* fix any /foo/../foo/ */
                                /* to be safe, check the length */
-                               if (BLI_bpathIterator_getPathMaxLen(&bpi) <= strlen(filepath_absolute)) {
-                                       bpath_as_report(&bpi, "couldn't make absolute (too long)", reports);
+                               if (BLI_bpathIterator_getPathMaxLen(bpi) <= strlen(filepath_absolute)) {
+                                       bpath_as_report(bpi, "couldn't make absolute (too long)", reports);
                                        failed++;
                                } else {
                                        if(strncmp(filepath_absolute, "//", 2)) {
-                                               BLI_bpathIterator_setPath(&bpi, filepath_absolute);
+                                               BLI_bpathIterator_setPath(bpi, filepath_absolute);
                                                changed++;
                                        } else {
-                                               bpath_as_report(&bpi, "couldn't make absolute", reports);
+                                               bpath_as_report(bpi, "couldn't make absolute", reports);
                                                failed++;
                                        }
                                }
                        }
                }
-               BLI_bpathIterator_step(&bpi);
+               BLI_bpathIterator_step(bpi);
                tot++;
        }
-       BLI_bpathIterator_free(&bpi);
+       BLI_bpathIterator_free(bpi);
 
        if(reports)
                BKE_reportf(reports, failed ? RPT_ERROR : RPT_INFO, "Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
@@ -810,8 +820,8 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
 }
 
 /* high level function - call from fileselector */
-void findMissingFiles(const char *basepath, const char *str) {
-       struct BPathIterator bpi;
+void findMissingFiles(Main *bmain, const char *str) {
+       struct BPathIterator *bpi;
        
        /* be sure there is low chance of the path being too short */
        char filepath_expanded[FILE_MAXDIR*2]; 
@@ -825,11 +835,11 @@ void findMissingFiles(const char *basepath, const char *str) {
        
        BLI_split_dirfile(str, dirname, NULL);
        
-       BLI_bpathIterator_init(&bpi, basepath);
+       BLI_bpathIterator_init(&bpi, bmain, bmain->name);
        
-       while (!BLI_bpathIterator_isDone(&bpi)) {
-               BLI_bpathIterator_getPath(&bpi, filepath);
-               libpath= BLI_bpathIterator_getLib(&bpi);
+       while (!BLI_bpathIterator_isDone(bpi)) {
+               BLI_bpathIterator_getPath(bpi, filepath);
+               libpath= BLI_bpathIterator_getLib(bpi);
                
                /* Check if esc was pressed because searching files can be slow */
                /*XXX if (blender_test_break()) {
@@ -838,7 +848,7 @@ void findMissingFiles(const char *basepath, const char *str) {
                
                if (libpath==NULL) {
                        
-                       BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded );
+                       BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
                        
                        if (!BLI_exists(filepath_expanded)) {
                                /* can the dir be opened? */
@@ -853,21 +863,21 @@ void findMissingFiles(const char *basepath, const char *str) {
                                
                                if (filesize > 0) {
                                        
-                                       if (BLI_bpathIterator_getPathMaxLen( &bpi ) < strlen(filename_new)) { 
+                                       if (BLI_bpathIterator_getPathMaxLen(bpi) < strlen(filename_new)) { 
                                                printf("cannot set path \"%s\" too long!", filename_new);
                                        } else {
                                                /* copy the found path into the old one */
                                                if (G.relbase_valid)
-                                                       BLI_path_rel(filename_new, bpi.base_path);
+                                                       BLI_path_rel(filename_new, bpi->base_path);
                                                
-                                               BLI_bpathIterator_setPath( &bpi, filename_new );
+                                               BLI_bpathIterator_setPath(bpi, filename_new);
                                        }
                                }
                        }
                }
-               BLI_bpathIterator_step(&bpi);
+               BLI_bpathIterator_step(bpi);
        }
-       BLI_bpathIterator_free(&bpi);
+       BLI_bpathIterator_free(bpi);
        
        //XXX waitcursor( 0 );
 }
index fd549ad..9d990d3 100644 (file)
@@ -2471,14 +2471,14 @@ int BLO_write_file(Main *mainvar, char *dir, int write_flags, ReportList *report
                if(strcmp(dir1, dir2)==0)
                        write_flags &= ~G_FILE_RELATIVE_REMAP;
                else
-                       makeFilesAbsolute(G.main->name, NULL);
+                       makeFilesAbsolute(mainvar, G.main->name, NULL);
        }
 
        BLI_make_file_string(G.main->name, userfilename, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
        write_user_block= BLI_streq(dir, userfilename);
 
        if(write_flags & G_FILE_RELATIVE_REMAP)
-               makeFilesRelative(dir, NULL); /* note, making relative to something OTHER then G.main->name */
+               makeFilesRelative(mainvar, dir, NULL); /* note, making relative to something OTHER then G.main->name */
 
        /* actual file writing */
        err= write_file_handle(mainvar, file, NULL,NULL, write_user_block, write_flags, thumb);
index c45e4d3..a5e47e7 100644 (file)
@@ -184,14 +184,16 @@ void FILE_OT_unpack_all(wmOperatorType *ot)
 
 /********************* make paths relative operator *********************/
 
-static int make_paths_relative_exec(bContext *UNUSED(C), wmOperator *op)
+static int make_paths_relative_exec(bContext *C, wmOperator *op)
 {
+       Main *bmain= CTX_data_main(C);
+
        if(!G.relbase_valid) {
                BKE_report(op->reports, RPT_WARNING, "Can't set relative paths with an unsaved blend file.");
                return OPERATOR_CANCELLED;
        }
 
-       makeFilesRelative(G.main->name, op->reports);
+       makeFilesRelative(bmain, bmain->name, op->reports);
 
        /* redraw everything so any changed paths register */
        WM_main_add_notifier(NC_WINDOW, NULL);
@@ -214,14 +216,16 @@ void FILE_OT_make_paths_relative(wmOperatorType *ot)
 
 /********************* make paths absolute operator *********************/
 
-static int make_paths_absolute_exec(bContext *UNUSED(C), wmOperator *op)
+static int make_paths_absolute_exec(bContext *C, wmOperator *op)
 {
+       Main *bmain= CTX_data_main(C);
+
        if(!G.relbase_valid) {
                BKE_report(op->reports, RPT_WARNING, "Can't set absolute paths with an unsaved blend file.");
                return OPERATOR_CANCELLED;
        }
 
-       makeFilesAbsolute(G.main->name, op->reports);
+       makeFilesAbsolute(bmain, bmain->name, op->reports);
 
        /* redraw everything so any changed paths register */
        WM_main_add_notifier(NC_WINDOW, NULL);
@@ -251,7 +255,7 @@ static int report_missing_files_exec(bContext *UNUSED(C), wmOperator *op)
        txtname[0] = '\0';
        
        /* run the missing file check */
-       checkMissingFiles(G.main->name, op->reports);
+       checkMissingFiles(G.main, op->reports);
        
        return OPERATOR_FINISHED;
 }
@@ -276,7 +280,7 @@ static int find_missing_files_exec(bContext *UNUSED(C), wmOperator *op)
        char *path;
        
        path= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
-       findMissingFiles(G.main->name, path);
+       findMissingFiles(G.main, path);
        MEM_freeN(path);
 
        return OPERATOR_FINISHED;
index 2c4ccaa..770640f 100644 (file)
@@ -37,6 +37,7 @@
 #include "BLI_bpath.h"
 
 #include "BKE_utildefines.h"
+#include "BKE_global.h" /* XXX, G.main only */
 
 #include "MEM_guardedalloc.h"
 
@@ -92,11 +93,9 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
        if (!PyArg_ParseTupleAndKeywords(args, kw, "|i:blend_paths", (char **)kwlist, &absolute))
                return NULL;
 
-       BLI_bpathIterator_alloc(&bpi);
-
        list= PyList_New(0);
 
-       for(BLI_bpathIterator_init(bpi, NULL); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
+       for(BLI_bpathIterator_init(&bpi, G.main, NULL); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
                /* build the list */
                if (absolute) {
                        BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
@@ -117,7 +116,6 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
        }
 
        BLI_bpathIterator_free(bpi);
-       MEM_freeN((void *)bpi);
 
        return list;
 }