Merging r41246 through r41535 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / blender.c
index 4085ce1da76f0c4ca1343940b4ec1341913921da..d68b0b361d1db13d3449b2543320825997f0290c 100644 (file)
@@ -1,9 +1,4 @@
-/*  blender.c   jan 94     MIXED MODEL
- * 
- * common help functions and data
- * 
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
 #include "BLI_blenlib.h"
 #include "BLI_bpath.h"
 #include "BLI_dynstr.h"
-#include "BLI_path_util.h"
 #include "BLI_utildefines.h"
 #include "BLI_callbacks.h"
 
 #include "IMB_imbuf.h"
+#include "IMB_moviecache.h"
 
 #include "BKE_blender.h"
 #include "BKE_context.h"
@@ -82,7 +77,7 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_sequencer.h"
-#include "BKE_moviecache.h"
+#include "BKE_sound.h"
 
 
 #include "BLO_undofile.h"
 
 #include "BKE_utildefines.h"
 
+#include "RNA_access.h"
+
 #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie
 
 Global G;
 UserDef U;
 /* ListBase = {NULL, NULL}; */
-short ENDIAN_ORDER;
 
 char versionstr[48]= "";
 
@@ -116,7 +112,7 @@ void free_blender(void)
        BLI_cb_finalize();
 
        seq_stripelem_cache_destruct();
-       BKE_moviecache_destruct();
+       IMB_moviecache_destruct();
        
        free_nodesystem();      
 }
@@ -131,9 +127,6 @@ void initglobals(void)
 
        strcpy(G.ima, "//");
 
-       ENDIAN_ORDER= 1;
-       ENDIAN_ORDER= (((char*)&ENDIAN_ORDER)[0])? L_ENDIAN: B_ENDIAN;
-
        if(BLENDER_SUBVERSION)
                BLI_snprintf(versionstr, sizeof(versionstr), "blender.org %d.%d", BLENDER_VERSION, BLENDER_SUBVERSION);
        else
@@ -167,22 +160,19 @@ static void clear_global(void)
        G.main= NULL;
 }
 
+static int clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src)
+{
+       strcpy(path_dst, path_src);
+       BLI_clean(path_dst);
+       return (strcmp(path_dst, path_src) == 0) ? FALSE : TRUE;
+}
+
 /* make sure path names are correct for OS */
 static void clean_paths(Main *main)
 {
-       struct BPathIterator *bpi;
-       char filepath_expanded[1024];
        Scene *scene;
 
-       for(BLI_bpathIterator_init(&bpi, main, main->name, BPATH_USE_PACKED); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) {
-               BLI_bpathIterator_getPath(bpi, filepath_expanded);
-
-               BLI_clean(filepath_expanded);
-
-               BLI_bpathIterator_setPath(bpi, filepath_expanded);
-       }
-
-       BLI_bpathIterator_free(bpi);
+       bpath_traverse_main(main, clean_paths_visit_cb, BPATH_TRAVERSE_SKIP_MULTIFILE, NULL);
 
        for(scene= main->scene.first; scene; scene= scene->id.next) {
                BLI_clean(scene->r.pic);
@@ -241,9 +231,14 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
 //     CTX_wm_manager_set(C, NULL);
        clear_global(); 
        
+       /* clear old property update cache, in case some old references are left dangling */
+       RNA_property_update_cache_free();
+       
        G.main= bfd->main;
 
        CTX_data_main_set(C, G.main);
+
+       sound_init_main(G.main);
        
        if (bfd->user) {
                
@@ -316,19 +311,18 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
        set_scene_bg(G.main, CTX_data_scene(C));
        
        MEM_freeN(bfd);
+
+       (void)curscene; /* quiet warning */
 }
 
-static int handle_subversion_warning(Main *main)
+static int handle_subversion_warning(Main *main, ReportList *reports)
 {
        if(main->minversionfile > BLENDER_VERSION ||
           (main->minversionfile == BLENDER_VERSION && 
                 main->minsubversionfile > BLENDER_SUBVERSION)) {
-               
-               char str[128];
-               
-               BLI_snprintf(str, sizeof(str), "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
-// XXX         error(str);
+               BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
        }
+
        return 1;
 }
 
@@ -386,7 +380,7 @@ int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
        if (bfd) {
                if(bfd->user) retval= BKE_READ_FILE_OK_USERPREFS;
                
-               if(0==handle_subversion_warning(bfd->main)) {
+               if(0==handle_subversion_warning(bfd->main, reports)) {
                        free_main(bfd->main);
                        MEM_freeN(bfd);
                        bfd= NULL;
@@ -501,7 +495,7 @@ static int read_undosave(bContext *C, UndoElem *uel)
 void BKE_write_undo(bContext *C, const char *name)
 {
        uintptr_t maxmem, totmem, memused;
-       int nr, success;
+       int nr /*, success */ /* UNUSED */;
        UndoElem *uel;
        
        if( (U.uiflag & USER_GLOBALUNDO)==0) return;
@@ -517,7 +511,7 @@ void BKE_write_undo(bContext *C, const char *name)
        
        /* make new */
        curundo= uel= MEM_callocN(sizeof(UndoElem), "undo file");
-       strncpy(uel->name, name, MAXUNDONAME-1);
+       BLI_strncpy(uel->name, name, sizeof(uel->name));
        BLI_addtail(&undobase, uel);
        
        /* and limit amount to the maximum */
@@ -551,9 +545,9 @@ void BKE_write_undo(bContext *C, const char *name)
                counter= counter % U.undosteps; 
        
                BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
-               BLI_make_file_string("/", filepath, btempdir, numstr);
+               BLI_make_file_string("/", filepath, BLI_temporary_dir(), numstr);
        
-               success= BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL);
+               /* success= */ /* UNUSED */ BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL);
                
                BLI_strncpy(curundo->str, filepath, sizeof(curundo->str));
        }
@@ -563,7 +557,7 @@ void BKE_write_undo(bContext *C, const char *name)
                if(curundo->prev) prevfile= &(curundo->prev->memfile);
                
                memused= MEM_get_memory_in_use();
-               success= BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags);
+               /* success= */ /* UNUSED */ BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags);
                curundo->undosize= MEM_get_memory_in_use() - memused;
        }
 
@@ -721,7 +715,7 @@ void BKE_undo_save_quit(void)
        /* no undo state to save */
        if(undobase.first==undobase.last) return;
                
-       BLI_make_file_string("/", str, btempdir, "quit.blend");
+       BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
 
        file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
        if(file == -1) {