edits ontop of Alex's patch from r41292.

pass main rather than use G.main when naming from -> to relative paths.
This commit is contained in:
Campbell Barton
2011-10-26 21:22:35 +00:00
parent ba0ef7a592
commit a267f9ba4e
19 changed files with 66 additions and 58 deletions

View File

@@ -59,7 +59,7 @@ int id_copy(struct ID *id, struct ID **newid, int test);
int id_unlink(struct ID *id, int test);
int new_id(struct ListBase *lb, struct ID *id, const char *name);
void id_clear_lib_data(struct ListBase *lb, struct ID *id);
void id_clear_lib_data(struct Main *bmain, struct ID *id);
struct ListBase *which_libbase(struct Main *mainlib, short type);

View File

@@ -137,14 +137,14 @@ void make_local_action(bAction *act)
// XXX: double-check this; it used to be just single-user check, but that was when fake-users were still default
if ((act->id.flag & LIB_FAKEUSER) && (act->id.us<=1)) {
id_clear_lib_data(&bmain->action, (ID *)act);
id_clear_lib_data(bmain, (ID *)act);
return;
}
BKE_animdata_main_cb(bmain, make_localact_init_cb, &mlac);
if (mlac.local && mlac.lib==0) {
id_clear_lib_data(&bmain->action, (ID *)act);
id_clear_lib_data(bmain, (ID *)act);
}
else if (mlac.local && mlac.lib) {
mlac.actn= copy_action(act);

View File

@@ -141,7 +141,7 @@ void make_local_armature(bArmature *arm)
if (arm->id.lib==NULL) return;
if (arm->id.us==1) {
id_clear_lib_data(&bmain->armature, (ID *)arm);
id_clear_lib_data(bmain, (ID *)arm);
return;
}
@@ -153,7 +153,7 @@ void make_local_armature(bArmature *arm)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->armature, (ID *)arm);
id_clear_lib_data(bmain, (ID *)arm);
}
else if(local && lib) {
bArmature *armn= copy_armature(arm);

View File

@@ -201,7 +201,7 @@ void make_local_brush(Brush *brush)
if(brush->clone.image) {
/* special case: ima always local immediately. Clone image should only
have one user anyway. */
id_clear_lib_data(&bmain->brush, (ID *)brush->clone.image);
id_clear_lib_data(bmain, (ID *)brush->clone.image);
extern_local_brush(brush);
}
@@ -213,7 +213,7 @@ void make_local_brush(Brush *brush)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->brush, (ID *)brush);
id_clear_lib_data(bmain, (ID *)brush);
extern_local_brush(brush);
/* enable fake user by default */

View File

@@ -255,7 +255,7 @@ void make_local_curve(Curve *cu)
if(cu->id.lib==NULL) return;
if(cu->id.us==1) {
id_clear_lib_data(&bmain->curve, (ID *)cu);
id_clear_lib_data(bmain, (ID *)cu);
extern_local_curve(cu);
return;
}
@@ -268,7 +268,7 @@ void make_local_curve(Curve *cu)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->curve, (ID *)cu);
id_clear_lib_data(bmain, (ID *)cu);
extern_local_curve(cu);
}
else if(local && lib) {

View File

@@ -323,7 +323,8 @@ static void extern_local_image(Image *UNUSED(ima))
match id_make_local pattern. */
}
void make_local_image(struct Image *ima) {
void make_local_image(struct Image *ima)
{
Main *bmain= G.main;
Tex *tex;
Brush *brush;
@@ -339,9 +340,9 @@ void make_local_image(struct Image *ima) {
/* Can't take short cut here: must check meshes at least because of bogus
texface ID refs. - z0r */
#if(0)
#if 0
if(ima->id.us==1) {
id_clear_lib_data(&bmain->image, (ID *)ima);
id_clear_lib_data(bmain, (ID *)ima);
extern_local_image(ima);
return;
}
@@ -380,16 +381,17 @@ void make_local_image(struct Image *ima) {
}
if(local && lib==0) {
id_clear_lib_data(&bmain->image, (ID *)ima);
id_clear_lib_data(bmain, (ID *)ima);
extern_local_image(ima);
}
else if(local && lib) {
Image *iman= copy_image(ima);
char *user_data[2]= {bmain->name, iman->id.lib->filepath};
iman->id.us= 0;
/* Remap paths of new ID using old library as base. */
bpath_traverse_id((ID *)iman, bpath_relocate_visitor,
((ID *)ima)->lib->filepath);
bpath_traverse_id(&iman->id, bpath_relocate_visitor, user_data);
tex= bmain->tex.first;
while(tex) {

View File

@@ -255,7 +255,7 @@ void make_local_lattice(Lattice *lt)
if(lt->id.lib==NULL) return;
if(lt->id.us==1) {
id_clear_lib_data(&bmain->latt, (ID *)lt);
id_clear_lib_data(bmain, (ID *)lt);
return;
}
@@ -267,7 +267,7 @@ void make_local_lattice(Lattice *lt)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->latt, (ID *)lt);
id_clear_lib_data(bmain, (ID *)lt);
}
else if(local && lib) {
Lattice *ltn= copy_lattice(lt);

View File

@@ -1250,12 +1250,13 @@ int new_id(ListBase *lb, ID *id, const char *tname)
/* Pull an ID out of a library (make it local). Only call this for IDs that
don't have other library users. */
void id_clear_lib_data(ListBase *lb, ID *id)
void id_clear_lib_data(Main *bmain, ID *id)
{
bpath_traverse_id(id, bpath_relocate_visitor, id->lib->filepath);
char *user_data[2]= {bmain->name, id->lib->filepath};
bpath_traverse_id(id, bpath_relocate_visitor, user_data);
id->lib= NULL;
id->flag= LIB_LOCAL;
new_id(lb, id, NULL);
new_id(which_libbase(bmain, GS(id->name)), id, NULL);
}
/* next to indirect usage in read/writefile also in editobject.c scene.c */

View File

@@ -297,7 +297,7 @@ void make_local_material(Material *ma)
/* One local user; set flag and return. */
if(ma->id.us==1) {
id_clear_lib_data(&bmain->mat, (ID *)ma);
id_clear_lib_data(bmain, (ID *)ma);
extern_local_material(ma);
return;
}
@@ -359,7 +359,7 @@ void make_local_material(Material *ma)
/* Only local users. */
if(local && lib==0) {
id_clear_lib_data(&bmain->mat, (ID *)ma);
id_clear_lib_data(bmain, (ID *)ma);
extern_local_material(ma);
}
/* Both user and local, so copy. */

View File

@@ -156,7 +156,7 @@ void make_local_mball(MetaBall *mb)
if(mb->id.lib==NULL) return;
if(mb->id.us==1) {
id_clear_lib_data(&bmain->mball, (ID *)mb);
id_clear_lib_data(bmain, (ID *)mb);
extern_local_mball(mb);
return;
@@ -170,7 +170,7 @@ void make_local_mball(MetaBall *mb)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->mball, (ID *)mb);
id_clear_lib_data(bmain, (ID *)mb);
extern_local_mball(mb);
}
else if(local && lib) {

View File

@@ -280,7 +280,7 @@ void make_local_mesh(Mesh *me)
if(me->id.lib==NULL) return;
if(me->id.us==1) {
id_clear_lib_data(&bmain->mesh, (ID *)me);
id_clear_lib_data(bmain, (ID *)me);
expand_local_mesh(me);
return;
}
@@ -293,7 +293,7 @@ void make_local_mesh(Mesh *me)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->mesh, (ID *)me);
id_clear_lib_data(bmain, (ID *)me);
expand_local_mesh(me);
}
else if(local && lib) {

View File

@@ -1050,7 +1050,7 @@ void ntreeMakeLocal(bNodeTree *ntree)
if(ntree->id.lib==NULL) return;
if(ntree->id.us==1) {
id_clear_lib_data(&bmain->nodetree, (ID *)ntree);
id_clear_lib_data(bmain, (ID *)ntree);
return;
}
@@ -1064,7 +1064,7 @@ void ntreeMakeLocal(bNodeTree *ntree)
/* if all users are local, we simply make tree local */
if(cd.local && cd.lib==0) {
id_clear_lib_data(&bmain->nodetree, (ID *)ntree);
id_clear_lib_data(bmain, (ID *)ntree);
}
else if(cd.local && cd.lib) {
/* this is the mixed case, we copy the tree and assign it to local users */

View File

@@ -756,7 +756,7 @@ void make_local_camera(Camera *cam)
if(cam->id.lib==NULL) return;
if(cam->id.us==1) {
id_clear_lib_data(&bmain->camera, (ID *)cam);
id_clear_lib_data(bmain, (ID *)cam);
return;
}
@@ -768,7 +768,7 @@ void make_local_camera(Camera *cam)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->camera, (ID *)cam);
id_clear_lib_data(bmain, (ID *)cam);
}
else if(local && lib) {
Camera *camn= copy_camera(cam);
@@ -917,7 +917,7 @@ void make_local_lamp(Lamp *la)
if(la->id.lib==NULL) return;
if(la->id.us==1) {
id_clear_lib_data(&bmain->lamp, (ID *)la);
id_clear_lib_data(bmain, (ID *)la);
return;
}
@@ -931,7 +931,7 @@ void make_local_lamp(Lamp *la)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->lamp, (ID *)la);
id_clear_lib_data(bmain, (ID *)la);
}
else if(local && lib) {
lan= copy_lamp(la);
@@ -1083,7 +1083,6 @@ Object *add_only_object(int type, const char *name)
/* ob->pad3 == Contact Processing Threshold */
ob->m_contactProcessingThreshold = 1.;
ob->obstacleRad = 1.;
ob->col_group = ob->col_mask = 1;
/* NT fluid sim defaults */
ob->fluidsimFlag = 0;
@@ -1461,7 +1460,7 @@ void make_local_object(Object *ob)
ob->proxy= ob->proxy_from= NULL;
if(ob->id.us==1) {
id_clear_lib_data(&bmain->object, (ID *)ob);
id_clear_lib_data(bmain, (ID *)ob);
extern_local_object(ob);
}
else {
@@ -1473,7 +1472,7 @@ void make_local_object(Object *ob)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->object, (ID *)ob);
id_clear_lib_data(bmain, (ID *)ob);
extern_local_object(ob);
}
else if(local && lib) {

View File

@@ -3610,7 +3610,7 @@ void make_local_particlesettings(ParticleSettings *part)
if(part->id.lib==0) return;
if(part->id.us==1) {
id_clear_lib_data(&bmain->particle, (ID *)part);
id_clear_lib_data(bmain, (ID *)part);
expand_local_particlesettings(part);
return;
}
@@ -3627,7 +3627,7 @@ void make_local_particlesettings(ParticleSettings *part)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->particle, (ID *)part);
id_clear_lib_data(bmain, (ID *)part);
expand_local_particlesettings(part);
}
else if(local && lib) {

View File

@@ -87,7 +87,7 @@ void make_local_speaker(Speaker *spk)
if(spk->id.lib==NULL) return;
if(spk->id.us==1) {
id_clear_lib_data(&bmain->speaker, (ID *)spk);
id_clear_lib_data(bmain, (ID *)spk);
return;
}
@@ -101,7 +101,7 @@ void make_local_speaker(Speaker *spk)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->speaker, (ID *)spk);
id_clear_lib_data(bmain, (ID *)spk);
}
else if(local && lib) {
Speaker *spkn= copy_speaker(spk);

View File

@@ -814,7 +814,8 @@ Tex *localize_texture(Tex *tex)
/* ------------------------------------------------------------------------- */
static void extern_local_texture(Tex *tex) {
static void extern_local_texture(Tex *tex)
{
id_lib_extern((ID *)tex->ima);
}
@@ -837,7 +838,7 @@ void make_local_texture(Tex *tex)
if(tex->id.lib==NULL) return;
if(tex->id.us==1) {
id_clear_lib_data(&bmain->tex, (ID *)tex);
id_clear_lib_data(bmain, (ID *)tex);
extern_local_texture(tex);
return;
}
@@ -892,7 +893,7 @@ void make_local_texture(Tex *tex)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->tex, (ID *)tex);
id_clear_lib_data(bmain, (ID *)tex);
extern_local_texture(tex);
}
else if(local && lib) {

View File

@@ -160,7 +160,7 @@ void make_local_world(World *wrld)
if(wrld->id.lib==NULL) return;
if(wrld->id.us==1) {
id_clear_lib_data(&bmain->world, (ID *)wrld);
id_clear_lib_data(bmain, (ID *)wrld);
return;
}
@@ -172,7 +172,7 @@ void make_local_world(World *wrld)
}
if(local && lib==0) {
id_clear_lib_data(&bmain->world, (ID *)wrld);
id_clear_lib_data(bmain, (ID *)wrld);
}
else if(local && lib) {
World *wrldn= copy_world(wrld);

View File

@@ -54,10 +54,10 @@ void BLI_bpathIterator_setPath (struct BPathIterator *bpi, const char *path)
/* Function that does something with an ID's file path. Should return 1 if the
path has changed, and in that case, should write the result to pathOut. */
typedef int (*bpath_visitor)(void *userdata, char *pathIn, char *pathOut);
typedef int (*BPathVisitor)(void *userdata, char *path_dst, const char *path_src);
/* Executes 'visit' for each path associated with 'id'. */
void bpath_traverse_id(struct ID *id, bpath_visitor visit, void *userdata);
int bpath_relocate_visitor(void *oldbasepath, char *pathIn, char *pathOut);
void bpath_traverse_id(struct ID *id, BPathVisitor visit, void *userdata);
int bpath_relocate_visitor(void *oldbasepath, char *path_dst, const char *path_src);
/* high level funcs */

View File

@@ -953,14 +953,16 @@ void findMissingFiles(Main *bmain, const char *str)
}
/* Run a visitor on a string, replacing the contents of the string as needed. */
static void rewrite_path(char *path, bpath_visitor visit, void *userdata) {
static void rewrite_path(char *path, BPathVisitor visit, void *userdata)
{
char pathOut[FILE_MAX];
if (visit(userdata, path, pathOut))
BLI_strncpy(path, pathOut, FILE_MAX);
}
/* Run visitor function 'visit' on all paths contained in 'id'. */
void bpath_traverse_id(ID *id, bpath_visitor visit, void *userdata) {
void bpath_traverse_id(ID *id, BPathVisitor visit, void *userdata)
{
Image *ima;
switch(GS(id->name)) {
@@ -981,26 +983,29 @@ void bpath_traverse_id(ID *id, bpath_visitor visit, void *userdata) {
/* Rewrites a relative path to be relative to the main file - unless the path is
absolute, in which case it is not altered. */
int bpath_relocate_visitor(void *oldbasepath_v, char *pathIn, char *pathOut) {
int bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *path_src)
{
/* be sure there is low chance of the path being too short */
char filepath[(FILE_MAXDIR * 2) + FILE_MAXFILE];
char *oldbasepath = oldbasepath_v;
const char *base_new= ((char **)pathbase_v)[0];
const char *base_old= ((char **)pathbase_v)[1];
if (strncmp(oldbasepath, "//", 2) == 0) {
printf("Error: old base path '%s' is not absolute.\n", oldbasepath);
if (strncmp(base_old, "//", 2) == 0) {
printf("%s: error, old base path '%s' is not absolute.\n",
__func__, base_old);
return 0;
}
/* Make referenced file absolute. This would be a side-effect of
BLI_cleanup_file, but we do it explicitely so we know if it changed. */
BLI_strncpy(filepath, pathIn, FILE_MAX);
if (BLI_path_abs(filepath, oldbasepath)) {
BLI_strncpy(filepath, path_src, FILE_MAX);
if (BLI_path_abs(filepath, base_old)) {
/* Path was relative and is now absolute. Remap.
* Important BLI_cleanup_dir runs before the path is made relative
* because it wont work for paths that start with "//../" */
BLI_cleanup_file(G.main->name, filepath);
BLI_path_rel(filepath, G.main->name);
BLI_strncpy(pathOut, filepath, FILE_MAX);
BLI_cleanup_file(base_new, filepath);
BLI_path_rel(filepath, base_new);
BLI_strncpy(path_dst, filepath, FILE_MAX);
return 1;
}
else {