svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22717:22875
[blender.git] / source / blender / windowmanager / intern / wm_files.c
index d13d8ec6ccc66a8eb7e91424cb85e34b0cb6c727..9c30c99bbdd29ede1a74e805030f170e72eb0302 100644 (file)
@@ -68,6 +68,7 @@
 #include "BKE_main.h"
 #include "BKE_packedFile.h"
 #include "BKE_report.h"
+#include "BKE_sound.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
 
@@ -224,7 +225,7 @@ static void wm_init_userdef()
 {
        UI_init_userdef();
        MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
-       
+       sound_init();
 }
 
 void WM_read_file(bContext *C, char *name, ReportList *reports)
@@ -252,7 +253,6 @@ void WM_read_file(bContext *C, char *name, ReportList *reports)
                wm_check(C); /* opens window(s), checks keymaps */
                
 // XXX         mainwindow_set_filename_to_title(G.main->name);
-// XXX         sound_initialize_sounds();
 
                if(retval==2) wm_init_userdef();        // in case a userdef is read from regular .blend
                
@@ -294,8 +294,6 @@ int WM_read_homefile(bContext *C, wmOperator *op)
        G.relbase_valid = 0;
        if (!from_memory) {
                BLI_make_file_string(G.sce, tstr, home, ".B25.blend");
-               if(!BLI_exists(tstr))
-                       BLI_make_file_string(G.sce, tstr, home, ".B.blend");
        }
        strcpy(scestr, G.sce);  /* temporary store */
        
@@ -336,8 +334,8 @@ int WM_read_homefile(bContext *C, wmOperator *op)
        
        WM_event_add_notifier(C, NC_WM|ND_FILEREAD, NULL);
        CTX_wm_window_set(C, NULL); /* exits queues */
-                                  
-       return success;
+
+       return OPERATOR_FINISHED;
 }
 
 
@@ -541,7 +539,7 @@ static void do_history(char *name, ReportList *reports)
                BKE_report(reports, RPT_ERROR, "Unable to make version backup");
 }
 
-void WM_write_file(bContext *C, char *target, ReportList *reports)
+void WM_write_file(bContext *C, char *target, int compress, ReportList *reports)
 {
        Library *li;
        int writeflags, len;
@@ -556,8 +554,6 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
        }
  
        /* send the OnSave event */
-// XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&CTX_data_scene(C)->id, SCRIPT_ONSAVE);
-
        for (li= G.main->library.first; li; li= li->id.next) {
                if (BLI_streq(li->name, target)) {
                        BKE_report(reports, RPT_ERROR, "Cannot overwrite used library");
@@ -577,17 +573,18 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
 //     }
        
        if (G.fileflags & G_AUTOPACK) {
-               packAll();
+               packAll(G.main, reports);
        }
        
        ED_object_exit_editmode(C, 0);
 
        do_history(di, reports);
        
-       /* we use the UserDef to define compression flag */
-       writeflags= G.fileflags & ~G_FILE_COMPRESS;
-       if(U.flag & USER_FILECOMPRESS)
-               writeflags |= G_FILE_COMPRESS;
+       writeflags= G.fileflags;
+
+       /* set compression flag */
+       if(compress) writeflags |= G_FILE_COMPRESS;
+       else writeflags &= ~G_FILE_COMPRESS;
        
        if (BLO_write_file(CTX_data_main(C), di, writeflags, reports)) {
                strcpy(G.sce, di);
@@ -595,6 +592,9 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
                strcpy(G.main->name, di);       /* is guaranteed current file */
 
                G.save_over = 1; /* disable untitled.blend convention */
+
+               if(compress) G.fileflags |= G_FILE_COMPRESS;
+               else G.fileflags &= ~G_FILE_COMPRESS;
                
                writeBlog();
        }
@@ -605,11 +605,17 @@ void WM_write_file(bContext *C, char *target, ReportList *reports)
 /* operator entry */
 int WM_write_homefile(bContext *C, wmOperator *op)
 {
+       wmWindow *win= CTX_wm_window(C);
        char tstr[FILE_MAXDIR+FILE_MAXFILE];
        int write_flags;
        
+       /* check current window and close it if temp */
+       if(win->screen->full == SCREENTEMP) {
+               wm_window_close(C, win);
+       }
+       
        BLI_make_file_string("/", tstr, BLI_gethome(), ".B25.blend");
-               
+       
        /*  force save as regular blend file */
        write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);