From 326efb431971e668a41d9a331ccc3d11f9fd3e5f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 23 Nov 2017 03:10:58 +1100 Subject: Fix T53274: Saving template prefs overwrites default prefs --- source/blender/windowmanager/intern/wm_files.c | 20 ++++++++++++++------ source/blender/windowmanager/intern/wm_init_exit.c | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 97aa64a8dee..2f6b18cfd3c 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -713,8 +713,8 @@ int wm_homefile_read( if (!use_factory_settings && BLI_exists(filepath_userdef)) { UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, NULL); if (userdef != NULL) { - BKE_blender_userdef_set_data(userdef); - MEM_freeN(userdef); + BKE_blender_userdef_data_set_and_free(userdef); + userdef = NULL; skip_flags |= BLO_READ_SKIP_USERDEF; printf("Read prefs: %s\n", filepath_userdef); @@ -824,9 +824,8 @@ int wm_homefile_read( read_userdef_from_memory = true; } if (userdef_template) { - BKE_blender_userdef_set_app_template(userdef_template); - BKE_blender_userdef_free_data(userdef_template); - MEM_freeN(userdef_template); + BKE_blender_userdef_app_template_data_set_and_free(userdef_template); + userdef_template = NULL; } } } @@ -1478,9 +1477,18 @@ static int wm_userpref_write_exec(bContext *C, wmOperator *op) WM_keyconfig_update(wm); if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL))) { + bool ok_write; BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL); printf("trying to save userpref at %s ", filepath); - if (BKE_blendfile_userdef_write(filepath, op->reports) != 0) { + + if (U.app_template[0]) { + ok_write = BKE_blendfile_userdef_write_app_template(filepath, op->reports); + } + else { + ok_write = BKE_blendfile_userdef_write(filepath, op->reports); + } + + if (ok_write) { printf("ok\n"); } else { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index e73ec2b081a..7608b015f49 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -569,7 +569,7 @@ void WM_exit_ext(bContext *C, const bool do_python) ED_file_exit(); /* for fsmenu */ UI_exit(); - BKE_blender_userdef_free_data(&U); + BKE_blender_userdef_data_free(&U, false); RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */ -- cgit v1.2.3