Merging r39717 through r39983 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 51cb4cc64ed6bcf437cf235ee59ff92e825815c6..b1e5f63e641efcd146ef833fe46b71b967f195fd 100644 (file)
 #include "DNA_scene_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_smoke_types.h"
+#include "DNA_speaker_types.h"
 #include "DNA_sound_types.h"
 #include "DNA_space_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_world_types.h"
+#include "DNA_movieclip_types.h"
 
 #include "MEM_guardedalloc.h"
 
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
 #include "BKE_sound.h"
 
+#include "NOD_socket.h"
+
 //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
 //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
 //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
@@ -1033,6 +1037,8 @@ void blo_freefiledata(FileData *fd)
                        oldnewmap_free(fd->globmap);
                if (fd->imamap)
                        oldnewmap_free(fd->imamap);
+               if (fd->movieclipmap)
+                       oldnewmap_free(fd->movieclipmap);
                if (fd->libmap && !(fd->flags & FD_FLAGS_NOT_MY_LIBMAP))
                        oldnewmap_free(fd->libmap);
                if (fd->bheadmap)
@@ -1108,6 +1114,13 @@ static void *newimaadr(FileData *fd, void *adr)          /* used to restore image data a
        return NULL;
 }
 
+static void *newmclipadr(FileData *fd, void *adr)              /* used to restore movie clip data after undo */
+{
+       if(fd->movieclipmap && adr)
+               return oldnewmap_lookup_and_inc(fd->movieclipmap, adr);
+       return NULL;
+}
+
 
 static void *newlibadr(FileData *fd, void *lib, void *adr)             /* only lib data */
 {
@@ -1236,6 +1249,38 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain)
        }
 }
 
+void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain)
+{
+       MovieClip *clip= oldmain->movieclip.first;
+
+       fd->movieclipmap= oldnewmap_new();
+
+       for(;clip; clip= clip->id.next) {
+               if(clip->cache)
+                       oldnewmap_insert(fd->movieclipmap, clip->cache, clip->cache, 0);
+       }
+}
+
+/* set old main movie clips caches to zero if it has been restored */
+/* this works because freeing old main only happens after this call */
+void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain)
+{
+       OldNew *entry= fd->movieclipmap->entries;
+       MovieClip *clip= oldmain->movieclip.first;
+       int i;
+
+       /* used entries were restored, so we put them to zero */
+       for (i=0; i<fd->movieclipmap->nentries; i++, entry++) {
+               if (entry->nr>0)
+                               entry->newp= NULL;
+       }
+
+       for(;clip; clip= clip->id.next) {
+               clip->cache= newmclipadr(fd, clip->cache);
+       }
+}
+
+
 /* undo file support: add all library pointers in lookup */
 void blo_add_library_pointer_map(ListBase *mainlist, FileData *fd)
 {
@@ -2051,10 +2096,21 @@ static void lib_link_nodetree(FileData *fd, Main *main)
        }
 }
 
+static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       bNode *node;
+       
+       ntreeInitTypes(ntree);
+       
+       /* XXX could be replaced by do_versions for new nodes */
+       for (node=ntree->nodes.first; node; node=node->next)
+               node_verify_socket_templates(ntree, node);
+}
+
 /* updates group node socket own_index so that
  * external links to/from the group node are preserved.
  */
-static void lib_node_do_versions_group(bNode *gnode)
+static void lib_node_do_versions_group_indices(bNode *gnode)
 {
        bNodeTree *ngroup= (bNodeTree*)gnode->id;
        bNode *intnode;
@@ -2087,92 +2143,101 @@ static void lib_node_do_versions_group(bNode *gnode)
 }
 
 /* updates external links for all group nodes in a tree */
-static void lib_nodetree_do_versions_group(bNodeTree *ntree)
+static void lib_nodetree_do_versions_group_indices_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 {
        bNode *node;
        
        for (node=ntree->nodes.first; node; node=node->next) {
                if (node->type==NODE_GROUP) {
                        bNodeTree *ngroup= (bNodeTree*)node->id;
-                       if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS))
-                               lib_node_do_versions_group(node);
+                       if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE))
+                               lib_node_do_versions_group_indices(node);
                }
        }
 }
 
+/* make an update call for the tree */
+static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       if (ntree->update)
+               ntreeUpdateTree(ntree);
+}
+
 /* verify types for nodes and groups, all data has to be read */
 /* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
 * typedefs*/
 static void lib_verify_nodetree(Main *main, int UNUSED(open))
 {
-       Scene *sce;
-       Material *ma;
-       Tex *tx;
        bNodeTree *ntree;
-       
+       int i;
+       bNodeTreeType *ntreetype;
+
        /* this crashes blender on undo/redo
                if(open==1) {
                        reinit_nodesystem();
                }*/
        
-       /* now create the own typeinfo structs an verify nodes */
-       /* here we still assume no groups in groups */
-       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
-               ntreeVerifyTypes(ntree);                /* internal nodes, no groups! */
+       /* set node->typeinfo pointers */
+       for (i=0; i < NUM_NTREE_TYPES; ++i) {
+               ntreetype= ntreeGetType(i);
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, lib_nodetree_init_types_cb);
        }
+       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
+               ntreeInitTypes(ntree);
        
        {
-               /*int has_old_groups=0;*/ /*UNUSED*/
+               int has_old_groups=0;
                /* XXX this should actually be part of do_versions, but since we need
                 * finished library linking, it is not possible there. Instead in do_versions
                 * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the
                 * actual group node updates.
                 */
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
-                       if (ntree->flag & NTREE_DO_VERSIONS) {
+                       if (ntree->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE) {
                                /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
-                               nodeGroupExposeAllSockets(ntree);
-                               /*has_old_groups = 1;*/ /*UNUSED*/
+                               node_group_expose_all_sockets(ntree);
+                               has_old_groups = 1;
                        }
                }
-               /* now verify all types in material trees, groups are set OK now */
-               for(ma= main->mat.first; ma; ma= ma->id.next) {
-                       if(ma->nodetree)
-                               lib_nodetree_do_versions_group(ma->nodetree);
-               }
-               /* and scene trees */
-               for(sce= main->scene.first; sce; sce= sce->id.next) {
-                       if(sce->nodetree)
-                               lib_nodetree_do_versions_group(sce->nodetree);
-               }
-               /* and texture trees */
-               for(tx= main->tex.first; tx; tx= tx->id.next) {
-                       if(tx->nodetree)
-                               lib_nodetree_do_versions_group(tx->nodetree);
+               
+               if (has_old_groups) {
+                       for (i=0; i < NUM_NTREE_TYPES; ++i) {
+                               ntreetype= ntreeGetType(i);
+                               if (ntreetype && ntreetype->foreach_nodetree)
+                                       ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_group_indices_cb);
+                       }
                }
                
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
-                       ntree->flag &= ~NTREE_DO_VERSIONS;
+                       ntree->flag &= ~NTREE_DO_VERSIONS_GROUP_EXPOSE;
        }
-
-       /* now verify all types in material trees, groups are set OK now */
-       for(ma= main->mat.first; ma; ma= ma->id.next) {
-               if(ma->nodetree)
-                       ntreeVerifyTypes(ma->nodetree);
-       }
-       /* and scene trees */
-       for(sce= main->scene.first; sce; sce= sce->id.next) {
-               if(sce->nodetree)
-                       ntreeVerifyTypes(sce->nodetree);
+       
+       /* verify all group user nodes */
+       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
+               ntreeVerifyNodes(main, &ntree->id);
        }
-       /* and texture trees */
-       for(tx= main->tex.first; tx; tx= tx->id.next) {
-               if(tx->nodetree)
-                       ntreeVerifyTypes(tx->nodetree);
+       
+       /* make update calls where necessary */
+       {
+               for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
+                       if (ntree->update)
+                               ntreeUpdateTree(ntree);
+               for (i=0; i < NUM_NTREE_TYPES; ++i) {
+                       ntreetype= ntreeGetType(i);
+                       if (ntreetype && ntreetype->foreach_nodetree)
+                               ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_update_cb);
+               }
        }
 }
 
-
+static void direct_link_node_socket(FileData *fd, bNodeSocket *sock)
+{
+       sock->link= newdataadr(fd, sock->link);
+       sock->storage= newdataadr(fd, sock->storage);
+       sock->default_value= newdataadr(fd, sock->default_value);
+       sock->cache= NULL;
+}
 
 /* ntree itself has been read! */
 static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
@@ -2184,6 +2249,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        
        ntree->init= 0;         /* to set callbacks and force setting types */
        ntree->progress= NULL;
+       ntree->execdata= NULL;
        
        ntree->adt= newdataadr(fd, ntree->adt);
        direct_link_animdata(fd, ntree->adt);
@@ -2193,12 +2259,15 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                if(node->type == NODE_DYNAMIC) {
                        node->custom1= 0;
                        node->custom1= BSET(node->custom1, NODE_DYNAMIC_LOADED);
-                       node->typeinfo= NULL;
                }
+
+               node->typeinfo= NULL;
+               
+               link_list(fd, &node->inputs);
+               link_list(fd, &node->outputs);
                
                node->storage= newdataadr(fd, node->storage);
                if(node->storage) {
-                       
                        /* could be handlerized at some point */
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
                                direct_link_curvemapping(fd, node->storage);
@@ -2215,8 +2284,6 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                                        ((ImageUser *)node->storage)->ok= 1;
                        }
                }
-               link_list(fd, &node->inputs);
-               link_list(fd, &node->outputs);
        }
        link_list(fd, &ntree->links);
        
@@ -2226,15 +2293,19 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        
        /* and we connect the rest */
        for(node= ntree->nodes.first; node; node= node->next) {
+               node->parent = newdataadr(fd, node->parent);
                node->preview= newimaadr(fd, node->preview);
                node->lasty= 0;
+               
                for(sock= node->inputs.first; sock; sock= sock->next)
-                       sock->link= newdataadr(fd, sock->link);
+                       direct_link_node_socket(fd, sock);
                for(sock= node->outputs.first; sock; sock= sock->next)
-                       sock->ns.data= NULL;
+                       direct_link_node_socket(fd, sock);
        }
+       for(sock= ntree->inputs.first; sock; sock= sock->next)
+               direct_link_node_socket(fd, sock);
        for(sock= ntree->outputs.first; sock; sock= sock->next)
-               sock->link= newdataadr(fd, sock->link);
+               direct_link_node_socket(fd, sock);
        
        for(link= ntree->links.first; link; link= link->next) {
                link->fromnode= newdataadr(fd, link->fromnode);
@@ -3162,7 +3233,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
                        if(part->effector_weights)
                                part->effector_weights->group = newlibadr(fd, part->id.lib, part->effector_weights->group);
 
-                       if(part->dupliweights.first) {
+                       if(part->dupliweights.first && part->dup_group) {
                                int index_ok = 0;
                                /* check for old files without indices (all indexes 0) */
                                dw = part->dupliweights.first;
@@ -3193,6 +3264,9 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
                                                dw->ob = newlibadr(fd, part->id.lib, dw->ob);
                                }
                        }
+                       else {
+                               part->dupliweights.first = part->dupliweights.last = NULL;
+                       }
 
                        if(part->boids) {
                                BoidState *state = part->boids->states.first;
@@ -4469,7 +4543,7 @@ static void lib_link_scene(FileData *fd, Main *main)
 #endif
 
                        if(sce->ed)
-                               seq_update_muting(sce, sce->ed);
+                               seq_update_muting(sce->ed);
                        
                        if(sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
@@ -4687,6 +4761,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        if(sce->nodetree)
                direct_link_nodetree(fd, sce->nodetree);
        
+       sce->clip= newlibadr_us(fd, sce->id.lib, sce->clip);
 }
 
 /* ************ READ WM ***************** */
@@ -4723,6 +4798,8 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
 
        wm->keyconfigs.first= wm->keyconfigs.last= NULL;
        wm->defaultconf= NULL;
+       wm->addonconf= NULL;
+       wm->userconf= NULL;
 
        wm->jobs.first= wm->jobs.last= NULL;
        wm->drags.first= wm->drags.last= NULL;
@@ -4839,6 +4916,7 @@ static void lib_link_screen(FileData *fd, Main *main)
 
                                                for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
                                                        bgpic->ima= newlibadr_us(fd, sc->id.lib, bgpic->ima);
+                                                       bgpic->clip= newlibadr_us(fd, sc->id.lib, bgpic->clip);
                                                }
                                                if(v3d->localvd) {
                                                        v3d->localvd->camera= newlibadr(fd, sc->id.lib, v3d->localvd->camera);
@@ -4951,19 +5029,34 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                SpaceNode *snode= (SpaceNode *)sl;
                                                
                                                snode->id= newlibadr(fd, sc->id.lib, snode->id);
+                                               snode->edittree= NULL;
                                                
-                                               /* internal data, a bit patchy */
-                                               if(snode->id) {
-                                                       if(GS(snode->id->name)==ID_MA)
-                                                               snode->nodetree= ((Material *)snode->id)->nodetree;
-                                                       else if(GS(snode->id->name)==ID_SCE)
-                                                               snode->nodetree= ((Scene *)snode->id)->nodetree;
-                                                       else if(GS(snode->id->name)==ID_TE)
-                                                               snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
+                                                       /* internal data, a bit patchy */
+                                                       snode->nodetree= NULL;
+                                                       if(snode->id) {
+                                                               if(GS(snode->id->name)==ID_MA)
+                                                                       snode->nodetree= ((Material *)snode->id)->nodetree;
+                                                               else if(GS(snode->id->name)==ID_SCE)
+                                                                       snode->nodetree= ((Scene *)snode->id)->nodetree;
+                                                               else if(GS(snode->id->name)==ID_TE)
+                                                                       snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                                       }
+                                               }
+                                               else {
+                                                       snode->nodetree= newlibadr_us(fd, sc->id.lib, snode->nodetree);
                                                }
                                                
                                                snode->linkdrag.first = snode->linkdrag.last = NULL;
                                        }
+                                       else if(sl->spacetype==SPACE_CLIP) {
+                                               SpaceClip *sclip= (SpaceClip *)sl;
+
+                                               sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
+
+                                               sclip->scopes.track_preview = NULL;
+                                               sclip->scopes.ok = 0;
+                                       }
                                }
                                sa= sa->next;
                        }
@@ -5050,6 +5143,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        
                                        for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
                                                bgpic->ima= restore_pointer_by_name(newmain, (ID *)bgpic->ima, 1);
+                                               bgpic->clip= restore_pointer_by_name(newmain, (ID *)bgpic->clip, 1);
                                        }
                                        if(v3d->localvd) {
                                                /*Base *base;*/
@@ -5179,17 +5273,28 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        snode->id= restore_pointer_by_name(newmain, snode->id, 1);
                                        snode->edittree= NULL;
                                        
-                                       if(snode->id==NULL)
+                                       if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
                                                snode->nodetree= NULL;
+                                               if(snode->id) {
+                                                       if(GS(snode->id->name)==ID_MA)
+                                                               snode->nodetree= ((Material *)snode->id)->nodetree;
+                                                       else if(GS(snode->id->name)==ID_SCE)
+                                                               snode->nodetree= ((Scene *)snode->id)->nodetree;
+                                                       else if(GS(snode->id->name)==ID_TE)
+                                                               snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               }
+                                       }
                                        else {
-                                               if(GS(snode->id->name)==ID_MA)
-                                                       snode->nodetree= ((Material *)snode->id)->nodetree;
-                                               else if(GS(snode->id->name)==ID_SCE)
-                                                       snode->nodetree= ((Scene *)snode->id)->nodetree;
-                                               else if(GS(snode->id->name)==ID_TE)
-                                                       snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1);
                                        }
                                }
+                               else if(sl->spacetype==SPACE_CLIP) {
+                                       SpaceClip *sclip= (SpaceClip *)sl;
+
+                                       sclip->clip= restore_pointer_by_name(newmain, (ID *)sclip->clip, 1);
+
+                                       sclip->scopes.ok = 0;
+                               }
                        }
                        sa= sa->next;
                }
@@ -5416,7 +5521,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                        snode->gpd= newdataadr(fd, snode->gpd);
                                        direct_link_gpencil(fd, snode->gpd);
                                }
-                               snode->nodetree= snode->edittree= NULL;
                        }
                        else if(sl->spacetype==SPACE_TIME) {
                                SpaceTime *stime= (SpaceTime *)sl;
@@ -5566,12 +5670,51 @@ static void fix_relpaths_library(const char *basepath, Main *main)
        }
 }
 
+/* ************ READ SPEAKER ***************** */
+
+static void lib_link_speaker(FileData *fd, Main *main)
+{
+       Speaker *spk;
+
+       spk= main->speaker.first;
+       while(spk) {
+               if(spk->id.flag & LIB_NEEDLINK) {
+                       if (spk->adt) lib_link_animdata(fd, &spk->id, spk->adt);
+
+                       spk->sound= newlibadr(fd, spk->id.lib, spk->sound);
+                       if (spk->sound) {
+                               spk->sound->id.us++;
+                       }
+
+                       spk->id.flag -= LIB_NEEDLINK;
+               }
+               spk= spk->id.next;
+       }
+}
+
+static void direct_link_speaker(FileData *fd, Speaker *spk)
+{
+       spk->adt= newdataadr(fd, spk->adt);
+       direct_link_animdata(fd, spk->adt);
+
+       /*spk->sound= newdataadr(fd, spk->sound);
+       direct_link_sound(fd, spk->sound);*/
+}
+
 /* ************** READ SOUND ******************* */
 
 static void direct_link_sound(FileData *fd, bSound *sound)
 {
        sound->handle = NULL;
        sound->playback_handle = NULL;
+       sound->waveform = NULL;
+
+       // versioning stuff, if there was a cache, then we enable caching:
+       if(sound->cache)
+       {
+               sound->flags |= SOUND_FLAGS_CACHING;
+               sound->cache = NULL;
+       }
 
        sound->packedfile = direct_link_packedfile(fd, sound->packedfile);
        sound->newpackedfile = direct_link_packedfile(fd, sound->newpackedfile);
@@ -5588,9 +5731,6 @@ static void lib_link_sound(FileData *fd, Main *main)
                        sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system
                        
                        sound_load(main, sound);
-
-                       if(sound->cache)
-                               sound_cache_notifying(main, sound, 1);
                }
                sound= sound->id.next;
        }
@@ -5633,6 +5773,51 @@ static void lib_link_group(FileData *fd, Main *main)
        }
 }
 
+/* ***************** READ MOVIECLIP *************** */
+
+static void direct_link_movieclip(FileData *fd, MovieClip *clip)
+{
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingTrack *track;
+
+       if(fd->movieclipmap) clip->cache= newmclipadr(fd, clip->cache);
+       else clip->cache= NULL;
+
+       tracking->reconstruction.cameras= newdataadr(fd, tracking->reconstruction.cameras);
+
+       link_list(fd, &tracking->tracks);
+
+       track= tracking->tracks.first;
+       while(track) {
+               track->markers= newdataadr(fd, track->markers);
+
+               track= track->next;
+       }
+
+       clip->tracking.act_track= newdataadr(fd, clip->tracking.act_track);
+
+       clip->anim= NULL;
+       clip->tracking_context= NULL;
+
+       clip->tracking.stabilization.ok= 0;
+       clip->tracking.stabilization.scaleibuf= NULL;
+}
+
+static void lib_link_movieclip(FileData *fd, Main *main)
+{
+       MovieClip *clip;
+
+       clip= main->movieclip.first;
+       while(clip) {
+               if(clip->id.flag & LIB_NEEDLINK) {
+                       clip->gpd= newlibadr_us(fd, clip->id.lib, clip->gpd);
+
+                       clip->id.flag -= LIB_NEEDLINK;
+               }
+               clip= clip->id.next;
+       }
+}
+
 /* ************** GENERAL & MAIN ******************** */
 
 
@@ -5661,11 +5846,13 @@ static const char *dataname(short id_code)
                case ID_SCR: return "Data from SCR";
                case ID_VF: return "Data from VF";
                case ID_TXT     : return "Data from TXT";
+               case ID_SPK: return "Data from SPK";
                case ID_SO: return "Data from SO";
                case ID_NT: return "Data from NT";
                case ID_BR: return "Data from BR";
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
+               case ID_MC: return "Data from MC";
        }
        return "Data from Lib Block";
        
@@ -5805,6 +5992,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_CA:
                        direct_link_camera(fd, (Camera *)id);
                        break;
+               case ID_SPK:
+                       direct_link_speaker(fd, (Speaker *)id);
+                       break;
                case ID_SO:
                        direct_link_sound(fd, (bSound *)id);
                        break;
@@ -5832,6 +6022,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_GD:
                        direct_link_gpencil(fd, (bGPdata *)id);
                        break;
+               case ID_MC:
+                       direct_link_movieclip(fd, (MovieClip *)id);
+                       break;
        }
        
        /*link direct data of ID properties*/
@@ -6885,6 +7078,62 @@ static void do_version_bone_roll_256(Bone *bone)
                do_version_bone_roll_256(child);
 }
 
+static void do_versions_socket_default_value(bNodeSocket *sock)
+{
+       bNodeSocketValueFloat *valfloat;
+       bNodeSocketValueVector *valvector;
+       bNodeSocketValueRGBA *valrgba;
+       
+       if (sock->default_value)
+               return;
+       
+       switch (sock->type) {
+       case SOCK_FLOAT:
+               valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value");
+               valfloat->value = sock->ns.vec[0];
+               valfloat->min = sock->ns.min;
+               valfloat->max = sock->ns.max;
+               valfloat->subtype = PROP_NONE;
+               break;
+       case SOCK_VECTOR:
+               valvector = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueVector), "default socket value");
+               copy_v3_v3(valvector->value, sock->ns.vec);
+               valvector->min = sock->ns.min;
+               valvector->max = sock->ns.max;
+               valvector->subtype = PROP_NONE;
+               break;
+       case SOCK_RGBA:
+               valrgba = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueRGBA), "default socket value");
+               copy_v4_v4(valrgba->value, sock->ns.vec);
+               break;
+       }
+}
+
+static void do_versions_nodetree_default_value(bNodeTree *ntree)
+{
+       bNode *node;
+       bNodeSocket *sock;
+       for (node=ntree->nodes.first; node; node=node->next) {
+               for (sock=node->inputs.first; sock; sock=sock->next)
+                       do_versions_socket_default_value(sock);
+               for (sock=node->outputs.first; sock; sock=sock->next)
+                       do_versions_socket_default_value(sock);
+       }
+       for (sock=ntree->inputs.first; sock; sock=sock->next)
+               do_versions_socket_default_value(sock);
+       for (sock=ntree->outputs.first; sock; sock=sock->next)
+               do_versions_socket_default_value(sock);
+}
+
+static void do_versions_nodetree_dynamic_sockets(bNodeTree *ntree)
+{
+       bNodeSocket *sock;
+       for (sock=ntree->inputs.first; sock; sock=sock->next)
+               sock->flag |= SOCK_DYNAMIC;
+       for (sock=ntree->outputs.first; sock; sock=sock->next)
+               sock->flag |= SOCK_DYNAMIC;
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -9946,12 +10195,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        if(ed) {
                                SEQP_BEGIN(ed, seq) {
                                        if (seq->strip && seq->strip->proxy){
-                                               if (sce->r.size != 100.0) {
-                                                       seq->strip->proxy->size
-                                                               = sce->r.size;
-                                               } else {
-                                                       seq->strip->proxy->size = 25;
-                                               }
                                                seq->strip->proxy->quality =90;
                                        }
                                }
@@ -10041,7 +10284,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                           !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
                                        {
                                                
-                                               snprintf(seq->strip->proxy->dir, 
+                                               BLI_snprintf(seq->strip->proxy->dir, 
                                                         FILE_MAXDIR, "%s/BL_proxy", 
                                                         seq->strip->dir);
                                        }
@@ -10058,7 +10301,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                 * to have them show in RNA viewer and accessible otherwise.
                 */
                for(ma= main->mat.first; ma; ma= ma->id.next) {
-                       if(ma->nodetree && strlen(ma->nodetree->id.name)==0)
+                       if(ma->nodetree && ma->nodetree->id.name[0] == '\0')
                                strcpy(ma->nodetree->id.name, "NTShader Nodetree");
                        
                        /* which_output 0 is now "not specified" */
@@ -10072,7 +10315,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
                /* and composit trees */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
-                       if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
+                       if(sce->nodetree && sce->nodetree->id.name[0] == '\0')
                                strcpy(sce->nodetree->id.name, "NTCompositing Nodetree");
 
                        /* move to cameras */
@@ -10094,7 +10337,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        bNode *node;
 
                        if(tx->nodetree) {
-                               if(strlen(tx->nodetree->id.name)==0)
+                               if(tx->nodetree->id.name[0] == '\0')
                                        strcpy(tx->nodetree->id.name, "NTTexture Nodetree");
 
                                /* which_output 0 is now "not specified" */
@@ -11542,7 +11785,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                         * is done in lib_verify_nodetree, because at this point the internal
                         * nodes may not be up-to-date! (missing lib-link)
                         */
-                       ntree->flag |= NTREE_DO_VERSIONS;
+                       ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE;
                }
        }
 
@@ -11665,12 +11908,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        Tex *tex;
                        for(tex= main->tex.first; tex; tex= tex->id.next) {
                                if(tex->pd) {
-                                       if (tex->pd->falloff_speed_scale == 0.0)
-                                               tex->pd->falloff_speed_scale = 100.0;
-
+                                       if (tex->pd->falloff_speed_scale == 0.0f)
+                                               tex->pd->falloff_speed_scale = 100.0f;
+                                       
                                        if (!tex->pd->falloff_curve) {
                                                tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
-
+                                               
                                                tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
                                                tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
                                                curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
@@ -11694,7 +11937,93 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
-               
+
+               {
+                       ParticleSettings *part;
+                       for(part = main->particle.first; part; part = part->id.next) {
+                               /* Initialize particle billboard scale */
+                               part->bb_size[0] = part->bb_size[1] = 1.0f;
+                       }
+               }
+       }
+
+       if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 1)){
+               {
+                       Scene *scene;
+                       Sequence *seq;
+
+                       for (scene=main->scene.first; scene; scene=scene->id.next)
+                       {
+                               scene->r.ffcodecdata.audio_channels = 2;
+                               scene->audio.volume = 1.0f;
+                               SEQ_BEGIN(scene->ed, seq) {
+                                       seq->pitch = 1.0f;
+                               }
+                               SEQ_END
+                       }
+               }
+               {
+                       bScreen *screen;
+                       for(screen= main->screen.first; screen; screen= screen->id.next) {
+                               ScrArea *sa;
+                               /* add regions */
+                               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                                       SpaceLink *sl= sa->spacedata.first;
+                                       if(sl->spacetype==SPACE_SEQ) {
+                                               ARegion *ar;
+                                               for (ar=sa->regionbase.first; ar; ar= ar->next) {
+                                                       if(ar->regiontype == RGN_TYPE_WINDOW) {
+                                                               if(ar->v2d.min[1] == 4.0f)
+                                                                       ar->v2d.min[1]= 0.5f;
+                                                       }
+                                               }
+                                       }
+                                       for (sl= sa->spacedata.first; sl; sl= sl->next) {
+                                               if(sl->spacetype==SPACE_SEQ) {
+                                                       ARegion *ar;
+                                                       for (ar=sl->regionbase.first; ar; ar= ar->next) {
+                                                               if(ar->regiontype == RGN_TYPE_WINDOW) {
+                                                                       if(ar->v2d.min[1] == 4.0f)
+                                                                               ar->v2d.min[1]= 0.5f;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               {
+                       /* Make "auto-clamped" handles a per-keyframe setting instead of per-FCurve 
+                        *
+                        * We're only patching F-Curves in Actions here, since it is assumed that most
+                        * drivers out there won't be using this (and if they are, they're in the minority).
+                        * While we should aim to fix everything ideally, in practice it's far too hard
+                        * to get to every animdata block, not to mention the performance hit that'd have
+                        */
+                       bAction *act;
+                       FCurve *fcu;
+                       
+                       for (act = main->action.first; act; act = act->id.next) {
+                               for (fcu = act->curves.first; fcu; fcu = fcu->next) {
+                                       BezTriple *bezt;
+                                       unsigned int i = 0;
+                                       
+                                       /* only need to touch curves that had this flag set */
+                                       if ((fcu->flag & FCURVE_AUTO_HANDLES) == 0)
+                                               continue;
+                                       if ((fcu->totvert == 0) || (fcu->bezt == NULL))
+                                               continue;
+                                               
+                                       /* only change auto-handles to auto-clamped */
+                                       for (bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
+                                               if (bezt->h1 == HD_AUTO) bezt->h1 = HD_AUTO_ANIM;
+                                               if (bezt->h2 == HD_AUTO) bezt->h2 = HD_AUTO_ANIM;
+                                       }
+                                       
+                                       fcu->flag &= ~FCURVE_AUTO_HANDLES;
+                               }
+                       }
+               }
                {
                        /* convert fcurve and shape action actuators to action actuators */
                        Object *ob;
@@ -11716,7 +12045,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                aa->end = ia->end;
                                                strcpy(aa->name, ia->name);
                                                strcpy(aa->frameProp, ia->frameProp);
-                                               aa->act = ob->adt->action;
+                                               if (ob->adt)
+                                                       aa->act = ob->adt->action;
 
                                                // Get rid of the old actuator
                                                MEM_freeN(ia);
@@ -11732,35 +12062,115 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
+       }
 
+       if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)){
                {
-                       ParticleSettings *part;
-                       for(part = main->particle.first; part; part = part->id.next) {
-                               /* Initialize particle billboard scale */
-                               part->bb_size[0] = part->bb_size[1] = 1.0f;
+                       /* Convert default socket values from bNodeStack */
+                       Scene *sce;
+                       Material *mat;
+                       Tex *tex;
+                       bNodeTree *ntree;
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_default_value(ntree);
+                               ntree->update |= NTREE_UPDATE;
+                       }
+                       for (sce=main->scene.first; sce; sce=sce->id.next)
+                               if (sce->nodetree) {
+                               do_versions_nodetree_default_value(sce->nodetree);
+                               sce->nodetree->update |= NTREE_UPDATE;
                        }
+                       for (mat=main->mat.first; mat; mat=mat->id.next)
+                               if (mat->nodetree) {
+                               do_versions_nodetree_default_value(mat->nodetree);
+                               mat->nodetree->update |= NTREE_UPDATE;
+                       }
+                       for (tex=main->tex.first; tex; tex=tex->id.next)
+                               if (tex->nodetree) {
+                               do_versions_nodetree_default_value(tex->nodetree);
+                               tex->nodetree->update |= NTREE_UPDATE;
+                       }
+               }
+
+               /* add SOCK_DYNAMIC flag to existing group sockets */
+               {
+                       bNodeTree *ntree;
+                       /* only need to do this for trees in main, local trees are not used as groups */
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_dynamic_sockets(ntree);
+                               ntree->update |= NTREE_UPDATE;
+                       }
+               }
+
+               {
+                       /* Initialize group tree nodetypes.
+                        * These are used to distinguish tree types and
+                        * associate them with specific node types for polling.
+                        */
+                       bNodeTree *ntree;
+                       /* all node trees in main->nodetree are considered groups */
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+                               ntree->nodetype = NODE_GROUP;
                }
        }
+
        /* put compatibility code here until next subversion bump */
 
        {
+               bScreen *sc;
+               Camera *cam;
+               MovieClip *clip;
 
-               {
-                       Scene *scene;
-                       Sequence *seq;
+               for (sc= main->screen.first; sc; sc= sc->id.next) {
+                       ScrArea *sa;
+                       for (sa= sc->areabase.first; sa; sa= sa->next) {
+                               SpaceLink *sl;
+                               for (sl= sa->spacedata.first; sl; sl= sl->next) {
+                                       if(sl->spacetype==SPACE_VIEW3D) {
+                                               View3D *v3d= (View3D *)sl;
 
-                       for (scene=main->scene.first; scene; scene=scene->id.next)
-                       {
-                               scene->r.ffcodecdata.audio_channels = 2;
-                               scene->audio.volume = 1.0f;
-                               SEQ_BEGIN(scene->ed, seq) {
-                                       seq->pitch = 1.0f;
+                                               if(v3d->bundle_size==0.0f) {
+                                                       v3d->bundle_size= 0.1f;
+                                                       v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
+                                               }
+
+                                               if(v3d->bundle_drawtype==0)
+                                                       v3d->bundle_drawtype= OB_EMPTY_SPHERE;
+                                       }
+                                       else if(sl->spacetype==SPACE_CLIP) {
+                                               SpaceClip *sclip= (SpaceClip *)sl;
+                                               if(sclip->scopes.track_preview_height==0)
+                                                       sclip->scopes.track_preview_height= 120;
+                                       }
                                }
-                               SEQ_END
+                       }
+               }
+
+               for (clip= main->movieclip.first; clip; clip= clip->id.next) {
+                       if(clip->aspx<1.0f) {
+                               clip->aspx= 1.0f;
+                               clip->aspy= 1.0f;
+                       }
+
+                       /* XXX: a bit hacky, probably include imbuf and use real constants are nicer */
+                       clip->proxy.build_tc_flags= 7;
+                       if(clip->proxy.build_size_flags==0)
+                               clip->proxy.build_size_flags= 1;
+
+                       if(clip->proxy.quality==0)
+                               clip->proxy.quality= 90;
+
+                       if(clip->tracking.camera.pixel_aspect<0.01f)
+                               clip->tracking.camera.pixel_aspect= 1.f;
+               }
+
+               for(cam= main->camera.first; cam; cam= cam->id.next) {
+                       if (cam->sensor_x < 0.01f) {
+                               cam->sensor_x = 32.f;
                        }
                }
        }
-       
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 
@@ -11796,6 +12206,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_latt(fd, main);
        lib_link_text(fd, main);
        lib_link_camera(fd, main);
+       lib_link_speaker(fd, main);
        lib_link_sound(fd, main);
        lib_link_group(fd, main);
        lib_link_armature(fd, main);
@@ -11804,39 +12215,64 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_nodetree(fd, main);    /* has to be done after scene/materials, this will verify group nodes */
        lib_link_brush(fd, main);
        lib_link_particlesettings(fd, main);
+       lib_link_movieclip(fd, main);
 
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
 
        lib_link_library(fd, main);             /* only init users */
 }
 
+static void direct_link_keymapitem(FileData *fd, wmKeyMapItem *kmi)
+{
+       kmi->properties= newdataadr(fd, kmi->properties);
+       if(kmi->properties)
+               IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+       kmi->ptr= NULL;
+       kmi->flag &= ~KMI_UPDATE;
+}
 
 static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
 {
        UserDef *user;
        wmKeyMap *keymap;
        wmKeyMapItem *kmi;
+       wmKeyMapDiffItem *kmdi;
 
        bfd->user= user= read_struct(fd, bhead, "user def");
 
        /* read all data into fd->datamap */
        bhead= read_data_into_oldnewmap(fd, bhead, "user def");
 
+       if(user->keymaps.first) {
+               /* backwards compatibility */
+               user->user_keymaps= user->keymaps;
+               user->keymaps.first= user->keymaps.last= NULL;
+       }
+
        link_list(fd, &user->themes);
-       link_list(fd, &user->keymaps);
+       link_list(fd, &user->user_keymaps);
        link_list(fd, &user->addons);
 
-       for(keymap=user->keymaps.first; keymap; keymap=keymap->next) {
+       for(keymap=user->user_keymaps.first; keymap; keymap=keymap->next) {
                keymap->modal_items= NULL;
                keymap->poll= NULL;
+               keymap->flag &= ~KEYMAP_UPDATE;
 
+               link_list(fd, &keymap->diff_items);
                link_list(fd, &keymap->items);
-               for(kmi=keymap->items.first; kmi; kmi=kmi->next) {
-                       kmi->properties= newdataadr(fd, kmi->properties);
-                       if(kmi->properties)
-                               IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
-                       kmi->ptr= NULL;
+               
+               for(kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) {
+                       kmdi->remove_item= newdataadr(fd, kmdi->remove_item);
+                       kmdi->add_item= newdataadr(fd, kmdi->add_item);
+
+                       if(kmdi->remove_item)
+                               direct_link_keymapitem(fd, kmdi->remove_item);
+                       if(kmdi->add_item)
+                               direct_link_keymapitem(fd, kmdi->add_item);
                }
+
+               for(kmi=keymap->items.first; kmi; kmi=kmi->next)
+                       direct_link_keymapitem(fd, kmi);
        }
 
        // XXX
@@ -12712,6 +13148,14 @@ static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
                expand_animdata(fd, mainvar, ca->adt);
 }
 
+static void expand_speaker(FileData *fd, Main *mainvar, Speaker *spk)
+{
+       expand_doit(fd, mainvar, spk->sound);
+
+       if (spk->adt)
+               expand_animdata(fd, mainvar, spk->adt);
+}
+
 static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
 {
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
@@ -12774,6 +13218,9 @@ static void expand_main(FileData *fd, Main *mainvar)
                                        case ID_CA:
                                                expand_camera(fd, mainvar, (Camera *)id);
                                                break;
+                                       case ID_SPK:
+                                               expand_speaker(fd, mainvar,(Speaker *)id);
+                                               break;
                                        case ID_SO:
                                                expand_sound(fd, mainvar, (bSound *)id);
                                                break;
@@ -13023,9 +13470,8 @@ static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r)
 
 /* common routine to append/link something from a library */
 
-static Main* library_append_begin(const bContext *C, FileData **fd, const char *filepath)
+static Main* library_append_begin(Main *mainvar, FileData **fd, const char *filepath)
 {
-       Main *mainvar= CTX_data_main(C);
        Main *mainl;
 
        /* make mains */
@@ -13041,64 +13487,17 @@ static Main* library_append_begin(const bContext *C, FileData **fd, const char *
        return mainl;
 }
 
-Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, const char *filepath)
+Main* BLO_library_append_begin(Main *mainvar, BlendHandle** bh, const char *filepath)
 {
        FileData *fd= (FileData*)(*bh);
-       return library_append_begin(C, &fd, filepath);
+       return library_append_begin(mainvar, &fd, filepath);
 }
 
-static void append_do_cursor(Scene *scene, Library *curlib, short flag)
-{
-       Base *centerbase;
-       Object *ob;
-       float *curs, centerloc[3], vec[3], min[3], max[3];
-       int count= 0;
-
-       /* when not linking (appending)... */
-       if(flag & FILE_LINK) 
-               return;
-
-       /* we're not appending at cursor */
-       if((flag & FILE_ATCURSOR) == 0) 
-               return;
-       
-       /* find the center of everything appended */
-       INIT_MINMAX(min, max);
-       centerbase= (scene->base.first);
-       while(centerbase) {
-               if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) {
-                       VECCOPY(vec, centerbase->object->loc);
-                       DO_MINMAX(vec, min, max);
-                       count++;
-               }
-               centerbase= centerbase->next;
-       }
-       /* we haven't found any objects to move to cursor */
-       if(!count) 
-               return;
-       
-       /* move from the center of the appended objects to cursor */
-       mid_v3_v3v3(centerloc, min, max);
-       curs = scene->cursor;
-       VECSUB(centerloc,curs,centerloc);
-       
-       /* now translate the center of the objects */
-       centerbase= (scene->base.first);
-       while(centerbase) {
-               if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) {
-                       ob= centerbase->object;
-                       ob->loc[0] += centerloc[0];
-                       ob->loc[1] += centerloc[1];
-                       ob->loc[2] += centerloc[2];
-               }
-               centerbase= centerbase->next;
-       }
-}
 
+/* Context == NULL signifies not to do any scene manipulation */
 static void library_append_end(const bContext *C, Main *mainl, FileData **fd, int idcode, short flag)
 {
        Main *mainvar;
-       Scene *scene= CTX_data_scene(C);
        Library *curlib;
 
        /* make main consistent */
@@ -13127,22 +13526,26 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in
        lib_verify_nodetree(mainvar, FALSE);
        fix_relpaths_library(G.main->name, mainvar); /* make all relative paths, relative to the open blend file */
 
-       /* give a base to loose objects. If group append, do it for objects too */
-       if(scene) {
-               const short is_link= (flag & FILE_LINK) != 0;
-               if(idcode==ID_SCE) {
-                       /* dont instance anything when linking in scenes, assume the scene its self instances the data */
-               }
-               else {
-                       give_base_to_objects(mainvar, scene, curlib, idcode, is_link);
+       if(C) {
+               Scene *scene= CTX_data_scene(C);
+
+               /* give a base to loose objects. If group append, do it for objects too */
+               if(scene) {
+                       const short is_link= (flag & FILE_LINK) != 0;
+                       if(idcode==ID_SCE) {
+                               /* dont instance anything when linking in scenes, assume the scene its self instances the data */
+                       }
+                       else {
+                               give_base_to_objects(mainvar, scene, curlib, idcode, is_link);
 
-                       if (flag & FILE_GROUP_INSTANCE) {
-                               give_base_to_groups(mainvar, scene);
+                               if (flag & FILE_GROUP_INSTANCE) {
+                                       give_base_to_groups(mainvar, scene);
+                               }
                        }
                }
-       }
-       else {
-               printf("library_append_end, scene is NULL (objects wont get bases)\n");
+               else {
+                       printf("library_append_end, scene is NULL (objects wont get bases)\n");
+               }
        }
        /* has been removed... erm, why? s..ton) */
        /* 20040907: looks like they are give base already in append_named_part(); -Nathan L */
@@ -13153,8 +13556,6 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in
                blo_freefiledata( *fd );
                *fd = NULL;
        }       
-
-       append_do_cursor(scene, curlib, flag);
 }
 
 void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag)