Commit: 9f15bcb218ef32d5f15e1e13235d2d7fa667e04a
Author: Campbell Barton
Date:   Tue Oct 6 19:40:15 2015 +1100
Branches: master
https://developer.blender.org/rB9f15bcb218ef32d5f15e1e13235d2d7fa667e04a

RNA: Add check_existing arg to other load() funcs

Note: movieclip was doing this already by default,
now split into 2 functions, matching image behavior.

===================================================================

M       source/blender/blenkernel/BKE_font.h
M       source/blender/blenkernel/BKE_movieclip.h
M       source/blender/blenkernel/BKE_sound.h
M       source/blender/blenkernel/intern/font.c
M       source/blender/blenkernel/intern/image.c
M       source/blender/blenkernel/intern/movieclip.c
M       source/blender/blenkernel/intern/sound.c
M       source/blender/editors/space_clip/clip_ops.c
M       source/blender/makesrna/intern/rna_main_api.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_font.h 
b/source/blender/blenkernel/BKE_font.h
index 1376702..f20c166 100644
--- a/source/blender/blenkernel/BKE_font.h
+++ b/source/blender/blenkernel/BKE_font.h
@@ -80,7 +80,9 @@ void BKE_vfont_builtin_register(void *mem, int size);
 void BKE_vfont_free_data(struct VFont *vfont);
 void BKE_vfont_free(struct VFont *sc); 
 struct VFont *BKE_vfont_builtin_get(void);
-struct VFont *BKE_vfont_load(struct Main *bmain, const char *name);
+struct VFont *BKE_vfont_load(struct Main *bmain, const char *filepath);
+struct VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char 
*filepath, bool *r_exists);
+struct VFont *BKE_vfont_load_exists(struct Main *bmain, const char *filepath);
 
 bool BKE_vfont_to_curve_ex(struct Main *bmain, struct Object *ob, int mode,
                            struct ListBase *r_nubase,
diff --git a/source/blender/blenkernel/BKE_movieclip.h 
b/source/blender/blenkernel/BKE_movieclip.h
index 7d76752..afca326 100644
--- a/source/blender/blenkernel/BKE_movieclip.h
+++ b/source/blender/blenkernel/BKE_movieclip.h
@@ -43,6 +43,8 @@ void BKE_movieclip_free(struct MovieClip *clip);
 void BKE_movieclip_unlink(struct Main *bmain, struct MovieClip *clip);
 
 struct MovieClip *BKE_movieclip_file_add(struct Main *bmain, const char *name);
+struct MovieClip *BKE_movieclip_file_add_exists_ex(struct Main *bmain, const 
char *name, bool *r_exists);
+struct MovieClip *BKE_movieclip_file_add_exists(struct Main *bmain, const char 
*name);
 void BKE_movieclip_reload(struct MovieClip *clip);
 void BKE_movieclip_clear_cache(struct MovieClip *clip);
 void BKE_movieclip_clear_proxy_cache(struct MovieClip *clip);
diff --git a/source/blender/blenkernel/BKE_sound.h 
b/source/blender/blenkernel/BKE_sound.h
index e68be70..67db253 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -61,7 +61,9 @@ void BKE_sound_exit(void);
 
 void BKE_sound_force_device(const char *device);
 
-struct bSound *BKE_sound_new_file(struct Main *main, const char *filename);
+struct bSound *BKE_sound_new_file(struct Main *main, const char *filepath);
+struct bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char 
*filepath, bool *r_exists);
+struct bSound *BKE_sound_new_file_exists(struct Main *bmain, const char 
*filepath);
 
 // XXX unused currently
 #if 0
diff --git a/source/blender/blenkernel/intern/font.c 
b/source/blender/blenkernel/intern/font.c
index 23261b6..e3ebb7f 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -203,7 +203,7 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
        return vfont->data;
 }
 
-VFont *BKE_vfont_load(Main *bmain, const char *name)
+VFont *BKE_vfont_load(Main *bmain, const char *filepath)
 {
        char filename[FILE_MAXFILE];
        VFont *vfont = NULL;
@@ -211,16 +211,16 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
        PackedFile *temp_pf = NULL;
        bool is_builtin;
        
-       if (STREQ(name, FO_BUILTIN_NAME)) {
-               BLI_strncpy(filename, name, sizeof(filename));
+       if (STREQ(filepath, FO_BUILTIN_NAME)) {
+               BLI_strncpy(filename, filepath, sizeof(filename));
                
                pf = get_builtin_packedfile();
                is_builtin = true;
        }
        else {
-               BLI_split_file_part(name, filename, sizeof(filename));
-               pf = newPackedFile(NULL, name, bmain->name);
-               temp_pf = newPackedFile(NULL, name, bmain->name);
+               BLI_split_file_part(filepath, filename, sizeof(filename));
+               pf = newPackedFile(NULL, filepath, bmain->name);
+               temp_pf = newPackedFile(NULL, filepath, bmain->name);
                
                is_builtin = false;
        }
@@ -237,7 +237,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
                        if (vfd->name[0] != '\0') {
                                BLI_strncpy(vfont->id.name + 2, vfd->name, 
sizeof(vfont->id.name) - 2);
                        }
-                       BLI_strncpy(vfont->name, name, sizeof(vfont->name));
+                       BLI_strncpy(vfont->name, filepath, sizeof(vfont->name));
 
                        /* if autopack is on store the packedfile in de font 
structure */
                        if (!is_builtin && (G.fileflags & G_AUTOPACK)) {
@@ -259,6 +259,37 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
        return vfont;
 }
 
+VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char *filepath, bool 
*r_exists)
+{
+       VFont *vfont;
+       char str[FILE_MAX], strtest[FILE_MAX];
+
+       BLI_strncpy(str, filepath, sizeof(str));
+       BLI_path_abs(str, bmain->name);
+
+       /* first search an identical filepath */
+       for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) {
+               BLI_strncpy(strtest, vfont->name, sizeof(vfont->name));
+               BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &vfont->id));
+
+               if (BLI_path_cmp(strtest, str) == 0) {
+                       vfont->id.us++;  /* officially should not, it doesn't 
link here! */
+                       if (r_exists)
+                               *r_exists = true;
+                       return vfont;
+               }
+       }
+
+       if (r_exists)
+               *r_exists = false;
+       return BKE_vfont_load(bmain, filepath);
+}
+
+VFont *BKE_vfont_load_exists(struct Main *bmain, const char *filepath)
+{
+       return BKE_vfont_load_exists_ex(bmain, filepath, NULL);
+}
+
 static VFont *which_vfont(Curve *cu, CharInfo *info)
 {
        switch (info->flag & (CU_CHINFO_BOLD | CU_CHINFO_ITALIC)) {
diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index 4a76c70..c314131 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -746,7 +746,7 @@ Image *BKE_image_load_exists_ex(const char *filepath, bool 
*r_exists)
        BLI_strncpy(str, filepath, sizeof(str));
        BLI_path_abs(str, G.main->name);
 
-       /* first search an identical image */
+       /* first search an identical filepath */
        for (ima = G.main->image.first; ima; ima = ima->id.next) {
                if (ima->source != IMA_SRC_VIEWER && ima->source != 
IMA_SRC_GENERATED) {
                        BLI_strncpy(strtest, ima->name, sizeof(ima->name));
diff --git a/source/blender/blenkernel/intern/movieclip.c 
b/source/blender/blenkernel/intern/movieclip.c
index 7a8c4ad..ed92c94 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -605,7 +605,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char 
*name)
        MovieClip *clip;
        int file, len;
        const char *libname;
-       char str[FILE_MAX], strtest[FILE_MAX];
+       char str[FILE_MAX];
 
        BLI_strncpy(str, name, sizeof(str));
        BLI_path_abs(str, bmain->name);
@@ -616,19 +616,6 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char 
*name)
                return NULL;
        close(file);
 
-       /* ** first search an identical clip ** */
-       for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
-               BLI_strncpy(strtest, clip->name, sizeof(clip->name));
-               BLI_path_abs(strtest, G.main->name);
-
-               if (STREQ(strtest, str)) {
-                       BLI_strncpy(clip->name, name, sizeof(clip->name));  /* 
for stringcode */
-                       clip->id.us++;  /* officially should not, it doesn't 
link here! */
-
-                       return clip;
-               }
-       }
-
        /* ** add new movieclip ** */
 
        /* create a short library name */
@@ -655,6 +642,37 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char 
*name)
        return clip;
 }
 
+MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, 
bool *r_exists)
+{
+       MovieClip *clip;
+       char str[FILE_MAX], strtest[FILE_MAX];
+
+       BLI_strncpy(str, filepath, sizeof(str));
+       BLI_path_abs(str, bmain->name);
+
+       /* first search an identical filepath */
+       for (clip = bmain->movieclip.first; clip; clip = clip->id.next) {
+               BLI_strncpy(strtest, clip->name, sizeof(clip->name));
+               BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &clip->id));
+
+               if (BLI_path_cmp(strtest, str) == 0) {
+                       clip->id.us++;  /* officially should not, it doesn't 
link here! */
+                       if (r_exists)
+                               *r_exists = true;
+                       return clip;
+               }
+       }
+
+       if (r_exists)
+               *r_exists = false;
+       return BKE_movieclip_file_add(bmain, filepath);
+}
+
+MovieClip *BKE_movieclip_file_add_exists(Main *bmain, const char *filepath)
+{
+       return BKE_movieclip_file_add_exists_ex(bmain, filepath, NULL);
+}
+
 static void real_ibuf_size(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, 
int *width, int *height)
 {
        *width = ibuf->x;
diff --git a/source/blender/blenkernel/intern/sound.c 
b/source/blender/blenkernel/intern/sound.c
index 0b89931..a800d8f 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -71,7 +71,7 @@ static int sound_cfra;
 static char **audio_device_names = NULL;
 #endif
 
-bSound *BKE_sound_new_file(struct Main *bmain, const char *filename)
+bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath)
 {
        bSound *sound;
 
@@ -80,18 +80,18 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char 
*filename)
 
        size_t len;
 
-       BLI_strncpy(str, filename, sizeof(str));
+       BLI_strncpy(str, filepath, sizeof(str));
 
        path = /*bmain ? bmain->name :*/ G.main->name;
 
        BLI_path_abs(str, path);
 
-       len = strlen(filename);
-       while (len > 0 && filename[len - 1] != '/' && filename[len - 1] != '\\')
+       len = strlen(filepath);
+       while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\')
                len--;
 
-       sound = BKE_libblock_alloc(bmain, ID_SO, filename + len);
-       BLI_strncpy(sound->name, filename, FILE_MAX);
+       sound = BKE_libblock_alloc(bmain, ID_SO, filepath + len);
+       BLI_strncpy(sound->name, filepath, FILE_MAX);
        /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */
 
        BKE_sound_load(bmain, sound);
@@ -99,6 +99,37 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char 
*filename)
        return sound;
 }
 
+bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, 
bool *r_exists)
+{
+       bSound *sound;
+       char str[FILE_MAX], strtest[FILE_MAX];
+
+       BLI_strncpy(str, filepath, sizeof(str));
+       BLI_path_abs(str, bmain->name);
+
+       /* first search an identical filepath */
+       for (sound = bmain->sound.first; sound; sound = sound->id.next) {
+               BLI_strncpy(strtest, sound->name, sizeof(sound->name));
+               BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &sound->id));
+
+               if (BLI_path_cmp(strtest, str) == 0) {
+                       sound->id.us++;  /* officially should not, it doesn't 
link here! */
+                       if (r_exists)
+                               *r_exists = true;
+                       return sound;
+               }
+       }
+
+       if (r_exists)
+               *r_exists = false;
+       return BKE_sound_new_file(bmain, filepath);
+}
+
+bSound *BKE_sound_new_file_exists(struct Main *bmain, const char 

@@ 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