diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-06 11:40:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-06 11:44:02 +0300 |
commit | 9f15bcb218ef32d5f15e1e13235d2d7fa667e04a (patch) | |
tree | 58669c2b15dad9fb28ca08e122f146318f23b768 /source/blender/blenkernel/intern | |
parent | 65bd2a6e6ae72a64dd2d3822fe79b44736b82264 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 45 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 46 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 43 |
4 files changed, 108 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 23261b63486..e3ebb7f908c 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 4a76c704130..c314131e246 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 7a8c4ad4564..ed92c942b57 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 0b89931aa75..a800d8f3f38 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 *filepath) +{ + return BKE_sound_new_file_exists_ex(bmain, filepath, NULL); +} + void BKE_sound_free(bSound *sound) { if (sound->packedfile) { |