diff options
Diffstat (limited to 'source/blender/windowmanager/intern/wm_files.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index b3be3b4cc0c..ec86977cab9 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -517,7 +517,9 @@ void WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* called on startup, (context entirely filled with NULLs) */ /* or called for 'New File' */ /* both startup.blend and userpref.blend are checked */ -int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory) +/* the optional paramater custom_file points to an alterntive startup page */ +/* custom_file can be NULL */ +int wm_homefile_read(bContext *C, ReportList *reports, short from_memory, const char *custom_file) { ListBase wmbase; char startstr[FILE_MAX]; @@ -529,7 +531,17 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory G.relbase_valid = 0; if (!from_memory) { const char * const cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL); - if (cfgdir) { + if (custom_file) { + BLI_strncpy(startstr, custom_file, FILE_MAX); + + if (cfgdir) { + BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE); + } + else { + prefstr[0] = '\0'; + } + } + else if (cfgdir) { BLI_make_file_string(G.main->name, startstr, cfgdir, BLENDER_STARTUP_FILE); BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE); } @@ -544,13 +556,12 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory G.fileflags &= ~G_FILE_NO_UI; /* put aside screens to match with persistent windows later */ - wm_window_match_init(C, &wmbase); + wm_window_match_init(C, &wmbase); if (!from_memory) { - if (BLI_exists(startstr)) { + if (BLI_access(startstr, R_OK) == 0) { success = (BKE_read_file(C, startstr, NULL) != BKE_READ_FILE_FAIL); } - if (U.themes.first == NULL) { if (G.debug & G_DEBUG) printf("\nNote: No (valid) '%s' found, fall back to built-in default.\n\n", startstr); @@ -558,6 +569,11 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory } } + if (success == 0 && custom_file && reports) { + BKE_reportf(reports, RPT_ERROR, "Could not read '%s'", custom_file); + /*We can not return from here because wm is already reset*/ + } + if (success == 0) { success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL, true); if (wmbase.first == NULL) wm_clear_default_size(C); @@ -581,7 +597,7 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory G.fileflags &= ~G_FILE_RELATIVE_REMAP; /* check userdef before open window, keymaps etc */ - wm_init_userdef(C, from_memory); + wm_init_userdef(C, (bool)from_memory); /* match the read WM with current WM */ wm_window_match_do(C, &wmbase); @@ -636,8 +652,23 @@ int wm_history_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) int wm_homefile_read_exec(bContext *C, wmOperator *op) { - int from_memory = strcmp(op->type->idname, "WM_OT_read_factory_settings") == 0; - return wm_homefile_read(C, op->reports, from_memory) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + int from_memory = (strcmp(op->type->idname, "WM_OT_read_factory_settings") == 0); + char filepath_buffer[FILE_MAX] = ""; + char *filepath = NULL; + + if (!from_memory) + { + RNA_string_get(op->ptr, "filepath", filepath_buffer); + if (filepath_buffer[0] != '\0') { + filepath = filepath_buffer; + if (BLI_access(filepath, R_OK)) { + BKE_reportf(op->reports, RPT_ERROR, "Can't read alternative start-up file: '%s'", filepath); + return OPERATOR_CANCELLED; + } + } + } + + return wm_homefile_read(C, op->reports, from_memory, filepath) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void wm_read_history(void) |