diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-02-26 14:50:59 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-02-26 14:50:59 +0300 |
commit | 878d8b44ee24e1832a33a2c3388052b505bc4524 (patch) | |
tree | d11028bd4f53c5c34f805e060c47914eeef17640 /source/blender | |
parent | 3ea627245b5a03db3010b16f2ef7edcafacbfc8e (diff) |
remove rna functions image.get_export_path() and image.get_abs_filename(), filename functions should not be spesific to images.
rename BKE_get_image_export_path() to BKE_rebase_path() and take a filename arg rather then an image.
obj export file copy was also not working because of a missing import.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 101 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 100 | ||||
-rw-r--r-- | source/blender/collada/DocumentExporter.cpp | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_image_api.c | 44 |
6 files changed, 103 insertions, 150 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 153cf3f300e..6b22b10cf24 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -130,9 +130,6 @@ void BKE_image_assign_ibuf(struct Image *ima, struct ImBuf *ibuf); /* called on frame change or before render */ void BKE_image_user_calc_frame(struct ImageUser *iuser, int cfra, int fieldnr); -/* produce image export path */ -int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs, int abs_size, char *rel, int rel_size); - /* fix things in ImageUser when new image gets assigned */ void BKE_image_user_new_image(struct Image *ima, struct ImageUser *iuser); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index d6edb068fa0..accadb3d434 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2260,104 +2260,3 @@ void BKE_image_user_calc_frame(ImageUser *iuser, int cfra, int fieldnr) if(iuser->ok==0) iuser->ok= 1; } } - -/* - Produce image export path. - - Fails returning 0 if image filename is empty or if destination path - matches image path (i.e. both are the same file). - - Trailing slash in dest_dir is optional. - - Logic: - - - if an image is "below" current .blend file directory, rebuild the - same dir structure in dest_dir - - For example //textures/foo/bar.png becomes - [dest_dir]/textures/foo/bar.png. - - - if an image is not "below" current .blend file directory, - disregard it's path and copy it in the same directory where 3D file - goes. - - For example //../foo/bar.png becomes [dest_dir]/bar.png. - - This logic will help ensure that all image paths are relative and - that a user gets his images in one place. It'll also provide - consistent behaviour across exporters. - */ -int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs, int abs_size, char *rel, int rel_size) -{ - char path[FILE_MAX]; - char dir[FILE_MAX]; - char base[FILE_MAX]; - char blend_dir[FILE_MAX]; /* directory, where current .blend file resides */ - char dest_path[FILE_MAX]; - char rel_dir[FILE_MAX]; - int len; - - if (abs) - abs[0]= 0; - - if (rel) - rel[0]= 0; - - BLI_split_dirfile_basic(G.sce, blend_dir, NULL); - - if (!strlen(im->name)) { - if (G.f & G_DEBUG) printf("Invalid image type.\n"); - return 0; - } - - BLI_strncpy(path, im->name, sizeof(path)); - - /* expand "//" in filename and get absolute path */ - BLI_convertstringcode(path, G.sce); - - /* get the directory part */ - BLI_split_dirfile_basic(path, dir, base); - - len= strlen(blend_dir); - - rel_dir[0] = 0; - - /* if image is "below" current .blend file directory */ - if (!strncmp(path, blend_dir, len)) { - - /* if image is _in_ current .blend file directory */ - if (!strcmp(dir, blend_dir)) { - BLI_join_dirfile(dest_path, dest_dir, base); - } - /* "below" */ - else { - /* rel = image_path_dir - blend_dir */ - BLI_strncpy(rel_dir, dir + len, sizeof(rel_dir)); - - BLI_join_dirfile(dest_path, dest_dir, rel_dir); - BLI_join_dirfile(dest_path, dest_path, base); - } - - } - /* image is out of current directory */ - else { - BLI_join_dirfile(dest_path, dest_dir, base); - } - - if (abs) - BLI_strncpy(abs, dest_path, abs_size); - - if (rel) { - strncat(rel, rel_dir, rel_size); - strncat(rel, base, rel_size); - } - - /* return 2 if src=dest */ - if (!strcmp(path, dest_path)) { - if (G.f & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path); - return 2; - } - - return 1; -} - diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9e494de5379..9b4084aa172 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -59,6 +59,7 @@ void BLI_make_existing_file(char *name); void BLI_split_dirfile(char *string, char *dir, char *file); void BLI_split_dirfile_basic(const char *string, char *dir, char *file); void BLI_join_dirfile(char *string, const char *dir, const char *file); +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); void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len); diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 1bf321ec1bc..fe43960b770 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1320,6 +1320,106 @@ void BLI_join_dirfile(char *string, const char *dir, const char *file) } } + +/* + Produce image export path. + + Fails returning 0 if image filename is empty or if destination path + matches image path (i.e. both are the same file). + + Trailing slash in dest_dir is optional. + + Logic: + + - if an image is "below" current .blend file directory, rebuild the + same dir structure in dest_dir + + For example //textures/foo/bar.png becomes + [dest_dir]/textures/foo/bar.png. + + - if an image is not "below" current .blend file directory, + disregard it's path and copy it in the same directory where 3D file + goes. + + For example //../foo/bar.png becomes [dest_dir]/bar.png. + + This logic will help ensure that all image paths are relative and + that a user gets his images in one place. It'll also provide + consistent behaviour across exporters. + */ +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) +{ + char path[FILE_MAX]; + char dir[FILE_MAX]; + char base[FILE_MAX]; + char blend_dir[FILE_MAX]; /* directory, where current .blend file resides */ + char dest_path[FILE_MAX]; + char rel_dir[FILE_MAX]; + int len; + + if (abs) + abs[0]= 0; + + if (rel) + rel[0]= 0; + + BLI_split_dirfile_basic(base_dir, blend_dir, NULL); + + if (src_dir[0]=='\0') + return 0; + + BLI_strncpy(path, src_dir, sizeof(path)); + + /* expand "//" in filename and get absolute path */ + BLI_convertstringcode(path, base_dir); + + /* get the directory part */ + BLI_split_dirfile_basic(path, dir, base); + + len= strlen(blend_dir); + + rel_dir[0] = 0; + + /* if image is "below" current .blend file directory */ + if (!strncmp(path, blend_dir, len)) { + + /* if image is _in_ current .blend file directory */ + if (!strcmp(dir, blend_dir)) { + BLI_join_dirfile(dest_path, dest_dir, base); + } + /* "below" */ + else { + /* rel = image_path_dir - blend_dir */ + BLI_strncpy(rel_dir, dir + len, sizeof(rel_dir)); + + BLI_join_dirfile(dest_path, dest_dir, rel_dir); + BLI_join_dirfile(dest_path, dest_path, base); + } + + } + /* image is out of current directory */ + else { + BLI_join_dirfile(dest_path, dest_dir, base); + } + + if (abs) + BLI_strncpy(abs, dest_path, abs_size); + + if (rel) { + strncat(rel, rel_dir, rel_size); + strncat(rel, base, rel_size); + } + + /* return 2 if src=dest */ + if (!strcmp(path, dest_path)) { + // if (G.f & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path); + return 2; + } + + return 1; +} + + static int add_win32_extension(char *name) { int retval = 0; diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index 4b35499fb62..3e1898a64d9 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -1435,9 +1435,9 @@ public: BLI_split_dirfile_basic(mfilename, dir, NULL); - BKE_get_image_export_path(image, dir, abs, sizeof(abs), rel, sizeof(rel)); + BKE_rebase_path(abs, sizeof(abs), rel, sizeof(rel), G.sce, image->name, dir); - if (strlen(abs)) { + if (abs[0] != '\0') { // make absolute source path BLI_strncpy(src, image->name, sizeof(src)); diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index e394fd4f710..e87ec02daea 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -45,24 +45,6 @@ #include "MEM_guardedalloc.h" -/* - User should check if returned path exists before copying a file there. - - TODO: it would be better to return a (abs, rel) tuple. -*/ -static char *rna_Image_get_export_path(Image *image, char *dest_dir, int rel) -{ - int length = FILE_MAX; - char *path= MEM_callocN(length, "image file path"); - - if (!BKE_get_image_export_path(image, dest_dir, rel ? NULL : path, length, rel ? path : NULL, length )) { - MEM_freeN(path); - return NULL; - } - - return path; -} - static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char *path, Scene *scene) { ImBuf *ibuf; @@ -92,17 +74,6 @@ static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char } } -char *rna_Image_get_abs_filename(Image *image, bContext *C) -{ - char *filename= MEM_callocN(FILE_MAX, "Image.get_abs_filename()"); - - BLI_strncpy(filename, image->name, FILE_MAXDIR + FILE_MAXFILE); - BLI_convertstringcode(filename, CTX_data_main(C)->name); - BLI_convertstringframe(filename, CTX_data_scene(C)->r.cfra, 0); - - return filename; -} - #else void RNA_api_image(StructRNA *srna) @@ -110,21 +81,6 @@ void RNA_api_image(StructRNA *srna) FunctionRNA *func; PropertyRNA *parm; - func= RNA_def_function(srna, "get_export_path", "rna_Image_get_export_path"); - RNA_def_function_ui_description(func, "Produce image export path."); - parm= RNA_def_string(func, "dest_dir", "", 0, "", "Destination directory."); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_boolean(func, "get_rel_path", 1, "", "Return relative path if True."); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_string(func, "path", "", 0, "", "Absolute export path."); - RNA_def_function_return(func, parm); - - func= RNA_def_function(srna, "get_abs_filename", "rna_Image_get_abs_filename"); - RNA_def_function_ui_description(func, "Get absolute filename."); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); - parm= RNA_def_string_file_path(func, "abs_filename", NULL, 0, "", "Image/movie absolute filename."); - RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "save", "rna_Image_save"); RNA_def_function_ui_description(func, "Save image to a specific path."); RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); |