[Bf-blender-cvs] [7b7e27c9a3] app-templates: Minor API changes to read user-preferences

Campbell Barton noreply at git.blender.org
Thu Mar 16 16:01:32 CET 2017


Commit: 7b7e27c9a31fcf6625d680a1f1d331c482166995
Author: Campbell Barton
Date:   Fri Mar 17 02:05:17 2017 +1100
Branches: app-templates
https://developer.blender.org/rB7b7e27c9a31fcf6625d680a1f1d331c482166995

Minor API changes to read user-preferences

Support reading user-preferences without assigning to `U`

===================================================================

M	source/blender/blenkernel/BKE_blendfile.h
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/windowmanager/intern/wm_files.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 6e6d1455b2..7d1825506e 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -33,6 +33,7 @@ struct ID;
 struct Main;
 struct MemFile;
 struct ReportList;
+struct UserDef;
 
 enum {
 	BKE_BLENDFILE_READ_FAIL             = 0, /* no load */
@@ -50,8 +51,9 @@ bool BKE_blendfile_read_from_memfile(
         struct bContext *C, struct MemFile *memfile,
         struct ReportList *reports, int skip_flag);
 
-int BKE_blendfile_read_userdef(const char *filepath, struct ReportList *reports);
-int BKE_blendfile_write_userdef(const char *filepath, struct ReportList *reports);
+void            BKE_blendfile_userdef_assign(struct UserDef *userdef);
+struct UserDef *BKE_blendfile_userdef_read(const char *filepath, struct ReportList *reports);
+int             BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
 
 
 /* partial blend file writing */
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 8b47224993..c254311c17 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -424,32 +424,35 @@ bool BKE_blendfile_read_from_memfile(
 	return (bfd != NULL);
 }
 
+void BKE_blendfile_userdef_assign(UserDef *userdef)
+{
+	/* only here free userdef themes... */
+	BKE_blender_userdef_free(&U);
+	U = *userdef;
+	MEM_freeN(userdef);
+}
+
 /* only read the userdef from a .blend */
-int BKE_blendfile_read_userdef(const char *filepath, ReportList *reports)
+UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
 {
 	BlendFileData *bfd;
-	int retval = BKE_BLENDFILE_READ_FAIL;
+	UserDef *userdef = NULL;
 
 	bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_NONE);
 	if (bfd) {
 		if (bfd->user) {
-			retval = BKE_BLENDFILE_READ_OK_USERPREFS;
-
-			/* only here free userdef themes... */
-			BKE_blender_userdef_free(&U);
-
-			U = *bfd->user;
-			MEM_freeN(bfd->user);
+			userdef = bfd->user;
+			bfd->user = NULL;
 		}
 		BKE_main_free(bfd->main);
 		MEM_freeN(bfd);
 	}
 
-	return retval;
+	return userdef;
 }
 
 /* only write the userdef in a .blend */
-int BKE_blendfile_write_userdef(const char *filepath, ReportList *reports)
+int BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
 {
 	Main *mainb = MEM_callocN(sizeof(Main), "empty main");
 	int retval = 0;
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 37a5ba81dc..a458c8be33 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -713,8 +713,10 @@ int wm_homefile_read(
 	
 	/* load preferences before startup.blend */
 	if (!from_memory && BLI_exists(filepath_userdef)) {
-		int done = BKE_blendfile_read_userdef(filepath_userdef, NULL);
-		if (done != BKE_BLENDFILE_READ_FAIL) {
+		UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, NULL);
+		if (userdef != NULL) {
+			BKE_blendfile_userdef_assign(userdef);
+
 			read_userdef_from_memory = false;
 			skip_flags |= BLO_READ_SKIP_USERDEF;
 			printf("Read prefs: %s\n", filepath_userdef);
@@ -753,6 +755,11 @@ int wm_homefile_read(
 #endif
 	}
 	
+	/* Load a file but keep the splash open */
+	if (custom_app_template) {
+		BLI_strncpy(U.app_template, custom_app_template, sizeof(U.app_template));
+	}
+
 	/* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
 	 * can remove this eventually, only in a 2.53 and older, now its not written */
 	G.fileflags &= ~G_FILE_RELATIVE_REMAP;
@@ -773,11 +780,6 @@ int wm_homefile_read(
 	G.save_over = 0;    // start with save preference untitled.blend
 	G.fileflags &= ~G_FILE_AUTOPLAY;    /*  disable autoplay in startup.blend... */
 
-	/* Load a file but keep the splash open */
-	if (custom_app_template) {
-		BLI_strncpy(U.app_template, custom_app_template, sizeof(U.app_template));
-	}
-
 	wm_file_read_post(C, true);
 
 	return true;
@@ -1386,7 +1388,7 @@ static int wm_userpref_write_exec(bContext *C, wmOperator *op)
 	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_USERPREF_FILE);
 	printf("trying to save userpref at %s ", filepath);
 
-	if (BKE_blendfile_write_userdef(filepath, op->reports) == 0) {
+	if (BKE_blendfile_userdef_write(filepath, op->reports) == 0) {
 		printf("fail\n");
 		return OPERATOR_CANCELLED;
 	}




More information about the Bf-blender-cvs mailing list