Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-10-06 11:40:15 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-10-06 11:44:02 +0300
commit9f15bcb218ef32d5f15e1e13235d2d7fa667e04a (patch)
tree58669c2b15dad9fb28ca08e122f146318f23b768 /source/blender/blenkernel
parent65bd2a6e6ae72a64dd2d3822fe79b44736b82264 (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')
-rw-r--r--source/blender/blenkernel/BKE_font.h4
-rw-r--r--source/blender/blenkernel/BKE_movieclip.h2
-rw-r--r--source/blender/blenkernel/BKE_sound.h4
-rw-r--r--source/blender/blenkernel/intern/font.c45
-rw-r--r--source/blender/blenkernel/intern/image.c2
-rw-r--r--source/blender/blenkernel/intern/movieclip.c46
-rw-r--r--source/blender/blenkernel/intern/sound.c43
7 files changed, 116 insertions, 30 deletions
diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h
index 137670215cc..f20c166aa6d 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 7d7675270de..afca326c727 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 e68be701b61..67db2537c8f 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 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) {