WM: minor correction to user-pref writing

When saving templates had wrong return value.
This commit is contained in:
Campbell Barton 2017-11-22 17:11:03 +11:00 committed by Bastien Montagne
parent 0c456eb90a
commit 75aec5eeaa
3 changed files with 25 additions and 20 deletions

View File

@ -58,8 +58,7 @@ struct UserDef *BKE_blendfile_userdef_read_from_memory(
const void *filebuf, int filelength,
struct ReportList *reports);
int BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
bool BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
/* partial blend file writing */
void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set);

View File

@ -494,19 +494,22 @@ UserDef *BKE_blendfile_userdef_read_from_memory(
}
/* only write the userdef in a .blend */
int BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
/**
* Only write the userdef in a .blend
* \return success
*/
bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
{
Main *mainb = MEM_callocN(sizeof(Main), "empty main");
int retval = 0;
bool ok = false;
if (BLO_write_file(mainb, filepath, G_FILE_USERPREFS, reports, NULL)) {
retval = 1;
ok = true;
}
MEM_freeN(mainb);
return retval;
return ok;
}
/** \} */

View File

@ -1456,7 +1456,7 @@ static int wm_userpref_write_exec(bContext *C, wmOperator *op)
wmWindowManager *wm = CTX_wm_manager(C);
char filepath[FILE_MAX];
const char *cfgdir;
bool ok = false;
bool ok = true;
/* update keymaps in user preferences */
WM_keyconfig_update(wm);
@ -1466,31 +1466,34 @@ static int wm_userpref_write_exec(bContext *C, wmOperator *op)
printf("trying to save userpref at %s ", filepath);
if (BKE_blendfile_userdef_write(filepath, op->reports) != 0) {
printf("ok\n");
ok = true;
}
else {
printf("fail\n");
ok = false;
}
}
else {
BKE_report(op->reports, RPT_ERROR, "Unable to create userpref path");
}
if (U.app_template[0] && (cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) {
/* Also save app-template prefs */
BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL);
printf("trying to save app-template userpref at %s ", filepath);
if (BKE_blendfile_userdef_write(filepath, op->reports) == 0) {
printf("fail\n");
ok = true;
if (U.app_template[0]) {
if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) {
/* Also save app-template prefs */
BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL);
printf("trying to save app-template userpref at %s ", filepath);
if (BKE_blendfile_userdef_write(filepath, op->reports) != 0) {
printf("ok\n");
}
else {
printf("fail\n");
ok = false;
}
}
else {
printf("ok\n");
BKE_report(op->reports, RPT_ERROR, "Unable to create app-template userpref path");
ok = false;
}
}
else if (U.app_template[0]) {
BKE_report(op->reports, RPT_ERROR, "Unable to create app-template userpref path");
}
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}