[Bf-blender-cvs] [c832354e33] master: Load user-preferences before startup file

Campbell Barton noreply at git.blender.org
Wed Mar 15 17:58:49 CET 2017


Commit: c832354e330c575a5c450cf0febebb7cc058df87
Author: Campbell Barton
Date:   Thu Mar 16 03:54:58 2017 +1100
Branches: master
https://developer.blender.org/rBc832354e330c575a5c450cf0febebb7cc058df87

Load user-preferences before startup file

Internal change needed for template support.
Loading the user preferences first so it's possible
for preferences to control startup behavior.

In general it's useful to load preferences before data-files,
so we know security settings for eg.

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

M	source/blender/blenkernel/BKE_blendfile.h
M	source/blender/blenkernel/intern/blender_undo.c
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/editors/render/render_preview.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 6767fce3ab..6e6d1455b2 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -34,20 +34,21 @@ struct Main;
 struct MemFile;
 struct ReportList;
 
-int BKE_blendfile_read(struct bContext *C, const char *filepath, struct ReportList *reports);
-
 enum {
 	BKE_BLENDFILE_READ_FAIL             = 0, /* no load */
 	BKE_BLENDFILE_READ_OK               = 1, /* OK */
 	BKE_BLENDFILE_READ_OK_USERPREFS     = 2, /* OK, and with new user settings */
 };
 
+int BKE_blendfile_read(
+        struct bContext *C, const char *filepath,
+        struct ReportList *reports, int skip_flag);
 bool BKE_blendfile_read_from_memory(
-        struct bContext *C, const void *filebuf,
-        int filelength, struct ReportList *reports, bool update_defaults);
+        struct bContext *C, const void *filebuf, int filelength,
+        struct ReportList *reports, int skip_flag, bool update_defaults);
 bool BKE_blendfile_read_from_memfile(
         struct bContext *C, struct MemFile *memfile,
-        struct ReportList *reports);
+        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);
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c
index bc98d6f680..396c06f96d 100644
--- a/source/blender/blenkernel/intern/blender_undo.c
+++ b/source/blender/blenkernel/intern/blender_undo.c
@@ -108,9 +108,9 @@ static int read_undosave(bContext *C, UndoElem *uel)
 	G.fileflags |= G_FILE_NO_UI;
 
 	if (UNDO_DISK)
-		success = (BKE_blendfile_read(C, uel->str, NULL) != BKE_BLENDFILE_READ_FAIL);
+		success = (BKE_blendfile_read(C, uel->str, NULL, 0) != BKE_BLENDFILE_READ_FAIL);
 	else
-		success = BKE_blendfile_read_from_memfile(C, &uel->memfile, NULL);
+		success = BKE_blendfile_read_from_memfile(C, &uel->memfile, NULL, 0);
 
 	/* restore */
 	BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */
@@ -389,7 +389,7 @@ bool BKE_undo_save_file(const char *filename)
 Main *BKE_undo_get_main(Scene **r_scene)
 {
 	Main *mainp = NULL;
-	BlendFileData *bfd = BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL);
+	BlendFileData *bfd = BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL, 0);
 
 	if (bfd) {
 		mainp = bfd->main;
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 54f709a1e5..146c67576e 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -349,7 +349,9 @@ static int handle_subversion_warning(Main *main, ReportList *reports)
 	return 1;
 }
 
-int BKE_blendfile_read(bContext *C, const char *filepath, ReportList *reports)
+int BKE_blendfile_read(
+        bContext *C, const char *filepath,
+        ReportList *reports, int skip_flags)
 {
 	BlendFileData *bfd;
 	int retval = BKE_BLENDFILE_READ_OK;
@@ -357,9 +359,11 @@ int BKE_blendfile_read(bContext *C, const char *filepath, ReportList *reports)
 	if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) /* don't print user-pref loading */
 		printf("read blend: %s\n", filepath);
 
-	bfd = BLO_read_from_file(filepath, reports);
+	bfd = BLO_read_from_file(filepath, reports, skip_flags);
 	if (bfd) {
-		if (bfd->user) retval = BKE_BLENDFILE_READ_OK_USERPREFS;
+		if (bfd->user) {
+			retval = BKE_BLENDFILE_READ_OK_USERPREFS;
+		}
 
 		if (0 == handle_subversion_warning(bfd->main, reports)) {
 			BKE_main_free(bfd->main);
@@ -379,11 +383,11 @@ int BKE_blendfile_read(bContext *C, const char *filepath, ReportList *reports)
 
 bool BKE_blendfile_read_from_memory(
         bContext *C, const void *filebuf, int filelength,
-        ReportList *reports, bool update_defaults)
+        ReportList *reports, int skip_flags, bool update_defaults)
 {
 	BlendFileData *bfd;
 
-	bfd = BLO_read_from_memory(filebuf, filelength, reports);
+	bfd = BLO_read_from_memory(filebuf, filelength, reports, skip_flags);
 	if (bfd) {
 		if (update_defaults)
 			BLO_update_defaults_startup_blend(bfd->main);
@@ -399,11 +403,11 @@ bool BKE_blendfile_read_from_memory(
 /* memfile is the undo buffer */
 bool BKE_blendfile_read_from_memfile(
         bContext *C, struct MemFile *memfile,
-        ReportList *reports)
+        ReportList *reports, int skip_flags)
 {
 	BlendFileData *bfd;
 
-	bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports);
+	bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports, skip_flags);
 	if (bfd) {
 		/* remove the unused screens and wm */
 		while (bfd->main->wm.first)
@@ -426,7 +430,7 @@ int BKE_blendfile_read_userdef(const char *filepath, ReportList *reports)
 	BlendFileData *bfd;
 	int retval = BKE_BLENDFILE_READ_FAIL;
 
-	bfd = BLO_read_from_file(filepath, reports);
+	bfd = BLO_read_from_file(filepath, reports, 0);
 	if (bfd) {
 		if (bfd->user) {
 			retval = BKE_BLENDFILE_READ_OK_USERPREFS;
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index c85cf12864..e07d567ce6 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -71,11 +71,21 @@ typedef struct BlendFileData {
 	BlenFileType type;
 } BlendFileData;
 
-BlendFileData *BLO_read_from_file(const char *filepath, struct ReportList *reports);
-BlendFileData *BLO_read_from_memory(const void *mem, int memsize, struct ReportList *reports);
+
+/* skip reading some data-block types (may want to skip screen data too). */
+typedef enum eBLOReadSkip {
+	BLO_READ_SKIP_USERDEF = (1 << 0),
+} eBLOReadSkip;
+
+BlendFileData *BLO_read_from_file(
+        const char *filepath,
+        struct ReportList *reports, eBLOReadSkip skip_flag);
+BlendFileData *BLO_read_from_memory(
+        const void *mem, int memsize,
+        struct ReportList *reports, eBLOReadSkip skip_flag);
 BlendFileData *BLO_read_from_memfile(
         struct Main *oldmain, const char *filename, struct MemFile *memfile,
-        struct ReportList *reports);
+        struct ReportList *reports, eBLOReadSkip skip_flag);
 
 void BLO_blendfiledata_free(BlendFileData *bfd);
 
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index be893177b3..7310941327 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -317,7 +317,9 @@ void BLO_blendhandle_close(BlendHandle *bh)
  * \param reports If the return value is NULL, errors indicating the cause of the failure.
  * \return The data of the file.
  */
-BlendFileData *BLO_read_from_file(const char *filepath, ReportList *reports)
+BlendFileData *BLO_read_from_file(
+        const char *filepath,
+        ReportList *reports, eBLOReadSkip skip_flags)
 {
 	BlendFileData *bfd = NULL;
 	FileData *fd;
@@ -325,6 +327,7 @@ BlendFileData *BLO_read_from_file(const char *filepath, ReportList *reports)
 	fd = blo_openblenderfile(filepath, reports);
 	if (fd) {
 		fd->reports = reports;
+		fd->skip_flags = skip_flags;
 		bfd = blo_read_file_internal(fd, filepath);
 		blo_freefiledata(fd);
 	}
@@ -341,7 +344,9 @@ BlendFileData *BLO_read_from_file(const char *filepath, ReportList *reports)
  * \param reports If the return value is NULL, errors indicating the cause of the failure.
  * \return The data of the file.
  */
-BlendFileData *BLO_read_from_memory(const void *mem, int memsize, ReportList *reports)
+BlendFileData *BLO_read_from_memory(
+        const void *mem, int memsize,
+        ReportList *reports, eBLOReadSkip skip_flags)
 {
 	BlendFileData *bfd = NULL;
 	FileData *fd;
@@ -349,6 +354,7 @@ BlendFileData *BLO_read_from_memory(const void *mem, int memsize, ReportList *re
 	fd = blo_openblendermemory(mem, memsize,  reports);
 	if (fd) {
 		fd->reports = reports;
+		fd->skip_flags = skip_flags;
 		bfd = blo_read_file_internal(fd, "");
 		blo_freefiledata(fd);
 	}
@@ -362,7 +368,9 @@ BlendFileData *BLO_read_from_memory(const void *mem, int memsize, ReportList *re
  * \param oldmain old main, from which we will keep libraries and other datablocks that should not have changed.
  * \param filename current file, only for retrieving library data.
  */
-BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFile *memfile, ReportList *reports)
+BlendFileData *BLO_read_from_memfile(
+        Main *oldmain, const char *filename, MemFile *memfile,
+        ReportList *reports, eBLOReadSkip skip_flags)
 {
 	BlendFileData *bfd = NULL;
 	FileData *fd;
@@ -371,6 +379,7 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
 	fd = blo_openblendermemfile(memfile, reports);
 	if (fd) {
 		fd->reports = reports;
+		fd->skip_flags = skip_flags;
 		BLI_strncpy(fd->relabase, filename, sizeof(fd->relabase));
 		
 		/* clear ob->proxy_from pointers in old main */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 638f877c84..91c96aef8e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8597,7 +8597,12 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
 			bhead = read_global(bfd, fd, bhead);
 			break;
 		case USER:
-			bhead = read_userdef(bfd, fd, bhead);
+			if (fd->skip_flags & BLO_READ_SKIP_USERDEF) {
+				bhead = blo_nextbhead(fd, bhead);
+			}
+			else {
+				bhead = read_userdef(bfd, fd, bhead);
+			}
 			break;
 		case ENDB:
 			bhead = NULL;
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index d97bef13a7..62ce15a640 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -81,6 +81,8 @@ typedef struct FileData {
 	int id_name_offs;       /* used to retrieve ID names from (bhead+1) */
 	int globalf, fileflags; /* for do_versions patching */
 	
+	eBLOReadSkip skip_flags;  /* skip some data-blocks */
+
 	struct OldNewMap *datamap;
 	s

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list