diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-06-06 01:19:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-06-06 01:19:59 +0400 |
commit | 4da179749eb8d6b53f5c2eba4b3e4132656c3d4f (patch) | |
tree | 59b4dbfac1c894687f022efb72a9c010c93e555f | |
parent | c12068920391c006cf5e72c1fafb4ebf8f807a55 (diff) |
- [#22492] [29159] commit breaks importing of script file that has a reload to self in it
broke when including the blend path in the modules filename.
- new function BLI_path_basename(), matches pythons os.path.basename().
replace a number of cases where BLI_split_dirfile was being used to get the filename only.
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_add.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 11 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 5 |
9 files changed, 20 insertions, 25 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index f860f579930..ef95139abda 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -440,10 +440,8 @@ Image *BKE_add_image_imbuf(ImBuf *ibuf) { /* on save, type is changed to FILE in editsima.c */ Image *ima; - char filename[sizeof(ibuf->name)]; - BLI_split_dirfile(ibuf->name, NULL, filename); - ima= image_alloc(filename, IMA_SRC_FILE, IMA_TYPE_IMAGE); + ima= image_alloc(BLI_path_basename(ibuf->name), IMA_SRC_FILE, IMA_TYPE_IMAGE); if (ima) { BLI_strncpy(ima->name, ibuf->name, FILE_MAX); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index f1036b66f69..e8328d0e622 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -232,7 +232,6 @@ int reopen_text(Text *text) int i, llen, len, res; unsigned char *buffer; TextLine *tmp; - char sfile[FILE_MAXFILE]; char str[FILE_MAXDIR+FILE_MAXFILE]; struct stat st; @@ -240,7 +239,6 @@ int reopen_text(Text *text) BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE); BLI_path_abs(str, G.sce); - BLI_split_dirfile(str, NULL, sfile); fp= fopen(str, "r"); if(fp==NULL) return 0; @@ -331,19 +329,17 @@ Text *add_text(char *file, const char *relpath) unsigned char *buffer; TextLine *tmp; Text *ta; - char sfile[FILE_MAXFILE]; char str[FILE_MAXDIR+FILE_MAXFILE]; struct stat st; BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE); if (relpath) /* can be NULL (bg mode) */ BLI_path_abs(str, relpath); - BLI_split_dirfile(str, NULL, sfile); fp= fopen(str, "r"); if(fp==NULL) return NULL; - ta= alloc_libblock(&G.main->text, ID_TXT, sfile); + ta= alloc_libblock(&G.main->text, ID_TXT, BLI_path_basename(str)); ta->id.us= 1; ta->lines.first= ta->lines.last= NULL; diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9bdc6c431e8..fb30e991200 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -53,6 +53,7 @@ void BLI_make_exist(char *dir); void BLI_make_existing_file(char *name); void BLI_split_dirfile(const char *string, char *dir, char *file); void BLI_join_dirfile(char *string, const char *dir, const char *file); +char *BLI_path_basename(char *path); int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir); void BLI_getlastdir(const char* dir, char *last, int maxlen); int BLI_testextensie(const char *str, const char *ext); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 9b1d29e6e12..a56cbb65538 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -661,7 +661,7 @@ void findMissingFiles(char *basepath, char *str) { char filepath[FILE_MAX], *libpath; int filesize, recur_depth; - char dirname[FILE_MAX], filename[FILE_MAX], filename_new[FILE_MAX]; + char dirname[FILE_MAX], filename_new[FILE_MAX]; //XXX waitcursor( 1 ); @@ -686,9 +686,8 @@ void findMissingFiles(char *basepath, char *str) { /* can the dir be opened? */ filesize = -1; recur_depth = 0; - BLI_split_dirfile(filepath, NULL, filename); /* the file to find */ - findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth); + findFileRecursive(filename_new, dirname, BLI_path_basename(filepath), &filesize, &recur_depth); if (filesize == -1) { /* could not open dir */ printf("Could not open dir \"%s\"\n", dirname); return; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 301b981cdc7..f91c38b8271 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1172,6 +1172,12 @@ void BLI_join_dirfile(char *string, const char *dir, const char *file) } } +/* like pythons os.path.basename( ) */ +char *BLI_path_basename(char *path) +{ + const char *filename= BLI_last_slash(path); + return filename ? filename + 1 : path; +} /* Produce image export path. diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 8b8b3b11324..33adc11caa0 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -862,7 +862,6 @@ static void save_image_doit(bContext *C, SpaceImage *sima, Scene *scene, wmOpera BKE_image_release_renderresult(scene, ima); } else if (BKE_write_ibuf(scene, ibuf, path, sima->imtypenr, scene->r.subimtype, scene->r.quality)) { - char *name; if(relative) BLI_path_rel(path, G.sce); /* only after saving */ @@ -895,10 +894,8 @@ static void save_image_doit(bContext *C, SpaceImage *sima, Scene *scene, wmOpera ima->type= IMA_TYPE_IMAGE; } - name = BLI_last_slash(path); - /* name image as how we saved it */ - rename_id(&ima->id, name ? name + 1 : path); + rename_id(&ima->id, BLI_path_basename(path)); } } else diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index c1b30ab155a..f36461ab7e0 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -421,7 +421,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) RNA_END; } else { - BLI_split_dirfile(seq_load.path, NULL, se->name); + BLI_strncpy(se->name, BLI_path_basename(seq_load.path), sizeof(se->name)); if(seq_load.start_frame < seq_load.end_frame) { seq->endstill= seq_load.end_frame - seq_load.start_frame; } diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 6ac63499988..01d0f56bf1b 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -34,6 +34,7 @@ #include "BKE_main.h" #include "BKE_global.h" /* grr, only for G.sce */ #include "BLI_listbase.h" +#include "BLI_path_util.h" #include <stddef.h> static Main *bpy_import_main= NULL; @@ -129,8 +130,8 @@ PyObject *bpy_text_import_name( char *name, int *found ) PyObject *bpy_text_reimport( PyObject *module, int *found ) { Text *text; - const char *txtname; const char *name; + char *filepath; char *buf = NULL; //XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; Main *maggie= bpy_import_main; @@ -143,14 +144,14 @@ PyObject *bpy_text_reimport( PyObject *module, int *found ) *found= 0; /* get name, filename from the module itself */ + if((name= PyModule_GetName(module)) == NULL) + return NULL; - txtname = PyModule_GetFilename( module ); - name = PyModule_GetName( module ); - if( !txtname || !name) + if((filepath= (char *)PyModule_GetFilename(module)) == NULL) return NULL; /* look up the text object */ - text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2); + text= BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2); /* uh-oh.... didn't find it */ if( !text ) diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 842e43b98cf..4ab110cc275 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1212,10 +1212,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *arg_unuse col = uiLayoutColumn(split, 0); uiItemL(col, "Recent", 0); for(recent = G.recent_files.first, i=0; (i<5) && (recent); recent = recent->next, i++) { - char *display_name= BLI_last_slash(recent->filename); - if(display_name) display_name++; /* skip the slash */ - else display_name= recent->filename; - uiItemStringO(col, display_name, ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename); + uiItemStringO(col, BLI_path_basename(recent->filename), ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename); } uiItemS(col); uiItemO(col, NULL, ICON_RECOVER_LAST, "WM_OT_recover_last_session"); |