doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / windowmanager / intern / wm_files.c
index 22b10c8..d466527 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -49,6 +49,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_ipo_types.h" // XXX old animation system
@@ -72,7 +73,7 @@
 #include "BKE_report.h"
 #include "BKE_sound.h"
 #include "BKE_texture.h"
-#include "BKE_utildefines.h"
+
 
 #include "BLO_readfile.h"
 #include "BLO_writefile.h"
 #include "WM_api.h"
 #include "WM_types.h"
 #include "wm.h"
+#include "wm_files.h"
 #include "wm_window.h"
 #include "wm_event_system.h"
 
@@ -117,7 +119,7 @@ static void write_history(void);
 */
 static void wm_window_match_init(bContext *C, ListBase *wmlist)
 {
-       wmWindowManager *wm= G.main->wm.first;
+       wmWindowManager *wm;
        wmWindow *win, *active_win;
        
        *wmlist= G.main->wm;
@@ -255,10 +257,14 @@ static void wm_init_userdef(bContext *C)
        MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
        sound_init(CTX_data_main(C));
 
+       /* needed so loading a file from the command line respects user-pref [#26156] */
+       if(U.flag & USER_FILENOUI)      G.fileflags |= G_FILE_NO_UI;
+       else                                            G.fileflags &= ~G_FILE_NO_UI;
+
        /* set the python auto-execute setting from user prefs */
        /* disabled by default, unless explicitly enabled in the command line */
        if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) G.f |=  G_SCRIPT_AUTOEXEC;
-       if(U.tempdir[0]) BLI_where_is_temp(btempdir, 1);
+       if(U.tempdir[0]) BLI_where_is_temp(btempdir, FILE_MAX, 1);
 }
 
 void WM_read_file(bContext *C, const char *name, ReportList *reports)
@@ -340,7 +346,7 @@ void WM_read_file(bContext *C, const char *name, ReportList *reports)
        }
        else {
                BKE_reportf(reports, RPT_ERROR, "Unknown error loading: \"%s\".", name);
-               BKE_assert(!"invalid 'retval'");
+               BLI_assert(!"invalid 'retval'");
        }
 
        WM_cursor_wait(0);
@@ -351,11 +357,10 @@ void WM_read_file(bContext *C, const char *name, ReportList *reports)
 /* called on startup,  (context entirely filled with NULLs) */
 /* or called for 'New File' */
 /* op can be NULL */
-int WM_read_homefile(bContext *C, wmOperator *op)
+int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
 {
        ListBase wmbase;
        char tstr[FILE_MAXDIR+FILE_MAXFILE];
-       int from_memory= op && strcmp(op->type->idname, "WM_OT_read_factory_settings")==0;
        int success= 0;
        
        free_ttfont(); /* still weird... what does it here? */
@@ -368,9 +373,7 @@ int WM_read_homefile(bContext *C, wmOperator *op)
                } else {
                        tstr[0] = '\0';
                        from_memory = 1;
-                       if (op) {
-                               BKE_report(op->reports, RPT_INFO, "Config directory with startup.blend file not found."); 
-                       }
+                       BKE_report(reports, RPT_INFO, "Config directory with "STRINGIFY(BLENDER_STARTUP_FILE)" file not found.");
                }
        }
        
@@ -384,7 +387,7 @@ int WM_read_homefile(bContext *C, wmOperator *op)
                success = (BKE_read_file(C, tstr, NULL) != BKE_READ_FILE_FAIL);
                
                if(U.themes.first==NULL) {
-                       printf("\nError: No valid startup.blend, fall back to built-in default.\n\n");
+                       printf("\nError: No valid "STRINGIFY(BLENDER_STARTUP_FILE)", fall back to built-in default.\n\n");
                        success = 0;
                }
        }
@@ -425,21 +428,30 @@ int WM_read_homefile(bContext *C, wmOperator *op)
 #ifdef WITH_PYTHON
        if(CTX_py_init_get(C)) {
                /* sync addons, these may have changed from the defaults */
-               BPY_string_exec(C, "__import__('bpy').utils.addon_reset_all()");
+               BPY_string_exec(C, "__import__('addon_utils').reset_all()");
 
                BPY_driver_reset();
                BPY_modules_load_user(C);
        }
 #endif
-       
+
        WM_event_add_notifier(C, NC_WM|ND_FILEREAD, NULL);
-       CTX_wm_window_set(C, NULL); /* exits queues */
 
-       return OPERATOR_FINISHED;
+       /* in background mode the scene will stay NULL */
+       if(!G.background) {
+               CTX_wm_window_set(C, NULL); /* exits queues */
+       }
+
+       return TRUE;
 }
 
+int WM_read_homefile_exec(bContext *C, wmOperator *op)
+{
+       int from_memory= strcmp(op->type->idname, "WM_OT_read_factory_settings") == 0;
+       return WM_read_homefile(C, op->reports, from_memory) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+}
 
-void read_history(void)
+void WM_read_history(void)
 {
        char name[FILE_MAX];
        LinkNode *l, *lines;
@@ -462,10 +474,7 @@ void read_history(void)
                if (line[0] && BLI_exists(line)) {
                        recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
                        BLI_addtail(&(G.recent_files), recent);
-                       recent->filepath = (char*)MEM_mallocN(sizeof(char)*(strlen(line)+1), "name of file");
-                       recent->filepath[0] = '\0';
-                       
-                       strcpy(recent->filepath, line);
+                       recent->filepath = BLI_strdup(line);
                        num++;
                }
        }
@@ -496,9 +505,7 @@ static void write_history(void)
                if (fp) {
                        /* add current file to the beginning of list */
                        recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");
-                       recent->filepath = (char*)MEM_mallocN(sizeof(char)*(strlen(G.main->name)+1), "name of file");
-                       recent->filepath[0] = '\0';
-                       strcpy(recent->filepath, G.main->name);
+                       recent->filepath = BLI_strdup(G.main->name);
                        BLI_addhead(&(G.recent_files), recent);
                        /* write current file to recent-files.txt */
                        fprintf(fp, "%s\n", recent->filepath);
@@ -536,18 +543,18 @@ static void do_history(char *name, ReportList *reports)
        if(strlen(name)<2) return;
                
        while(hisnr > 1) {
-               sprintf(tempname1, "%s%d", name, hisnr-1);
-               sprintf(tempname2, "%s%d", name, hisnr);
+               BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr-1);
+               BLI_snprintf(tempname2, sizeof(tempname2), "%s%d", name, hisnr);
        
                if(BLI_rename(tempname1, tempname2))
                        BKE_report(reports, RPT_ERROR, "Unable to make version backup");
                        
                hisnr--;
        }
-               
+
        /* is needed when hisnr==1 */
-       sprintf(tempname1, "%s%d", name, hisnr);
-       
+       BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr);
+
        if(BLI_rename(name, tempname1))
                BKE_report(reports, RPT_ERROR, "Unable to make version backup");
 }
@@ -664,7 +671,7 @@ int WM_write_file(bContext *C, const char *target, int fileflags, ReportList *re
        if (BLO_write_file(CTX_data_main(C), di, fileflags, reports, thumb)) {
                if(!copy) {
                        G.relbase_valid = 1;
-                       strcpy(G.main->name, di);       /* is guaranteed current file */
+                       BLI_strncpy(G.main->name, di, sizeof(G.main->name));    /* is guaranteed current file */
        
                        G.save_over = 1; /* disable untitled.blend convention */
                }
@@ -737,8 +744,8 @@ void wm_autosave_location(char *filename)
        char *savedir;
 #endif
 
-       sprintf(pidstr, "%d.blend", abs(getpid()));
-       
+       BLI_snprintf(pidstr, sizeof(pidstr), "%d.blend", abs(getpid()));
+
 #ifdef WIN32
        /* XXX Need to investigate how to handle default location of '/tmp/'
         * This is a relative directory on Windows, and it may be