Fix T57989: File loaded as startup
authorCampbell Barton <ideasman42@gmail.com>
Thu, 22 Nov 2018 03:57:41 +0000 (14:57 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 22 Nov 2018 04:06:14 +0000 (15:06 +1100)
The file contents was used to check if the file was a startup file.

Now pass in an argument from startup loading code instead.

source/blender/blenkernel/BKE_blendfile.h
source/blender/blenkernel/intern/blender_undo.c
source/blender/blenkernel/intern/blendfile.c
source/blender/blenloader/BLO_readfile.h
source/blender/blenloader/intern/readblenentry.c
source/blender/blenloader/intern/undofile.c
source/blender/editors/render/render_preview.c
source/blender/windowmanager/intern/wm_files.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

index 9ff164f60bea460019d3f2d86a9915393cd44b9e..74fdde93d9a5419c7ba425562ac62315cbb26ebc 100644 (file)
@@ -34,6 +34,7 @@ struct Main;
 struct MemFile;
 struct ReportList;
 struct UserDef;
+struct BlendFileReadParams;
 
 enum {
        BKE_BLENDFILE_READ_FAIL             = 0, /* no load */
@@ -43,13 +44,16 @@ enum {
 
 int BKE_blendfile_read(
         struct bContext *C, const char *filepath,
-        struct ReportList *reports, int skip_flag);
+        const struct BlendFileReadParams *params,
+        struct ReportList *reports);
 bool BKE_blendfile_read_from_memory(
-        struct bContext *C, const void *filebuf, int filelength,
-        struct ReportList *reports, int skip_flag, bool update_defaults);
+        struct bContext *C, const void *filebuf, int filelength, bool update_defaults,
+        const struct BlendFileReadParams *params,
+        struct ReportList *reports);
 bool BKE_blendfile_read_from_memfile(
         struct bContext *C, struct MemFile *memfile,
-        struct ReportList *reports, int skip_flag);
+        const struct BlendFileReadParams *params,
+        struct ReportList *reports);
 void BKE_blendfile_read_make_empty(struct bContext *C);
 
 struct UserDef *BKE_blendfile_userdef_read(
index df2caba0208b03c570293e40a8f1486d211b0df2..441687c1c01c43dae39ee929bda67c5bb5671ac0 100644 (file)
@@ -55,6 +55,7 @@
 #include "BKE_main.h"
 
 #include "BLO_undofile.h"
+#include "BLO_readfile.h"
 #include "BLO_writefile.h"
 
 /* -------------------------------------------------------------------- */
@@ -79,7 +80,10 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C)
                success = (BKE_blendfile_read(C, mfu->filename, NULL, 0) != BKE_BLENDFILE_READ_FAIL);
        }
        else {
-               success = BKE_blendfile_read_from_memfile(C, &mfu->memfile, NULL, 0);
+               success = BKE_blendfile_read_from_memfile(
+                       C, &mfu->memfile,
+                       &(const struct BlendFileReadParams){0},
+                       NULL);
        }
 
        /* Restore, bmain has been re-allocated. */
index c92648da67cded9c6313054f481c053c37c548b0..c6cb8a412fef0ba78d467bb72c0afc867249ea7b 100644 (file)
@@ -111,11 +111,12 @@ static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
  */
 static void setup_app_data(
         bContext *C, BlendFileData *bfd,
-        const char *filepath, ReportList *reports)
+        const char *filepath,
+        const bool is_startup,
+        ReportList *reports)
 {
        Main *bmain = G_MAIN;
        Scene *curscene = NULL;
-       const bool is_startup = (bfd->filename[0] == '\0');
        const bool recover = (G.fileflags & G_FILE_RECOVER) != 0;
        enum {
                LOAD_UI = 1,
@@ -296,7 +297,7 @@ static void setup_app_data(
        bmain->recovered = 0;
 
        /* startup.blend or recovered startup */
-       if (bfd->filename[0] == 0) {
+       if (is_startup) {
                bmain->name[0] = '\0';
        }
        else if (recover && G.relbase_valid) {
@@ -351,7 +352,8 @@ static int handle_subversion_warning(Main *main, ReportList *reports)
 
 int BKE_blendfile_read(
         bContext *C, const char *filepath,
-        ReportList *reports, int skip_flags)
+        const struct BlendFileReadParams *params,
+        ReportList *reports)
 {
        BlendFileData *bfd;
        int retval = BKE_BLENDFILE_READ_OK;
@@ -361,7 +363,7 @@ int BKE_blendfile_read(
                printf("Read blend: %s\n", filepath);
        }
 
-       bfd = BLO_read_from_file(filepath, reports, skip_flags);
+       bfd = BLO_read_from_file(filepath, params->skip_flags, reports);
        if (bfd) {
                if (bfd->user) {
                        retval = BKE_BLENDFILE_READ_OK_USERPREFS;
@@ -374,7 +376,7 @@ int BKE_blendfile_read(
                        retval = BKE_BLENDFILE_READ_FAIL;
                }
                else {
-                       setup_app_data(C, bfd, filepath, reports);
+                       setup_app_data(C, bfd, filepath, params->is_startup, reports);
                }
        }
        else
@@ -384,16 +386,17 @@ int BKE_blendfile_read(
 }
 
 bool BKE_blendfile_read_from_memory(
-        bContext *C, const void *filebuf, int filelength,
-        ReportList *reports, int skip_flags, bool update_defaults)
+        bContext *C, const void *filebuf, int filelength, bool update_defaults,
+        const struct BlendFileReadParams *params,
+        ReportList *reports)
 {
        BlendFileData *bfd;
 
-       bfd = BLO_read_from_memory(filebuf, filelength, reports, skip_flags);
+       bfd = BLO_read_from_memory(filebuf, filelength, params->skip_flags, reports);
        if (bfd) {
                if (update_defaults)
                        BLO_update_defaults_startup_blend(bfd->main);
-               setup_app_data(C, bfd, "<memory2>", reports);
+               setup_app_data(C, bfd, "<memory2>", params->is_startup, reports);
        }
        else {
                BKE_reports_prepend(reports, "Loading failed: ");
@@ -405,12 +408,13 @@ bool BKE_blendfile_read_from_memory(
 /* memfile is the undo buffer */
 bool BKE_blendfile_read_from_memfile(
         bContext *C, struct MemFile *memfile,
-        ReportList *reports, int skip_flags)
+        const struct BlendFileReadParams *params,
+        ReportList *reports)
 {
        Main *bmain = CTX_data_main(C);
        BlendFileData *bfd;
 
-       bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, reports, skip_flags);
+       bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, params->skip_flags, reports);
        if (bfd) {
                /* remove the unused screens and wm */
                while (bfd->main->wm.first)
@@ -418,7 +422,7 @@ bool BKE_blendfile_read_from_memfile(
                while (bfd->main->screen.first)
                        BKE_libblock_free(bfd->main, bfd->main->screen.first);
 
-               setup_app_data(C, bfd, "<memory1>", reports);
+               setup_app_data(C, bfd, "<memory1>", params->is_startup, reports);
        }
        else {
                BKE_reports_prepend(reports, "Loading failed: ");
@@ -459,7 +463,7 @@ UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
        BlendFileData *bfd;
        UserDef *userdef = NULL;
 
-       bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF);
+       bfd = BLO_read_from_file(filepath, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, reports);
        if (bfd) {
                if (bfd->user) {
                        userdef = bfd->user;
@@ -479,7 +483,10 @@ UserDef *BKE_blendfile_userdef_read_from_memory(
        BlendFileData *bfd;
        UserDef *userdef = NULL;
 
-       bfd = BLO_read_from_memory(filebuf, filelength, reports, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF);
+       bfd = BLO_read_from_memory(
+               filebuf, filelength,
+               BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF,
+               reports);
        if (bfd) {
                if (bfd->user) {
                        userdef = bfd->user;
index 11f34732cfc762e977bf139ab9911e3ba6399cad..5a1c479f45050e802072d72f728bc13cc4ff2786 100644 (file)
@@ -48,6 +48,7 @@ struct View3D;
 struct bContext;
 struct BHead;
 struct FileData;
+struct BlendFileReadParams;
 
 typedef struct BlendHandle BlendHandle;
 
@@ -71,6 +72,10 @@ typedef struct BlendFileData {
        eBlenFileType type;
 } BlendFileData;
 
+struct BlendFileReadParams {
+       uint skip_flags : 2;  /* eBLOReadSkip */
+       uint is_startup : 1;
+};
 
 /* skip reading some data-block types (may want to skip screen data too). */
 typedef enum eBLOReadSkip {
@@ -83,13 +88,16 @@ typedef enum eBLOReadSkip {
 
 BlendFileData *BLO_read_from_file(
         const char *filepath,
-        struct ReportList *reports, eBLOReadSkip skip_flag);
+        eBLOReadSkip skip_flags,
+        struct ReportList *reports);
 BlendFileData *BLO_read_from_memory(
         const void *mem, int memsize,
-        struct ReportList *reports, eBLOReadSkip skip_flag);
+        eBLOReadSkip skip_flags,
+        struct ReportList *reports);
 BlendFileData *BLO_read_from_memfile(
         struct Main *oldmain, const char *filename, struct MemFile *memfile,
-        struct ReportList *reports, eBLOReadSkip skip_flag);
+        eBLOReadSkip skip_flags,
+        struct ReportList *reports);
 
 void BLO_blendfiledata_free(BlendFileData *bfd);
 
index 7488d62bb3c9d1e8e6a4d003b486cc8808eaf7f3..b2bcf745eac76bcd4631c9f5faeaab906f6c7db2 100644 (file)
@@ -319,7 +319,8 @@ void BLO_blendhandle_close(BlendHandle *bh)
  */
 BlendFileData *BLO_read_from_file(
         const char *filepath,
-        ReportList *reports, eBLOReadSkip skip_flags)
+        eBLOReadSkip skip_flags,
+        ReportList *reports)
 {
        BlendFileData *bfd = NULL;
        FileData *fd;
@@ -346,7 +347,8 @@ BlendFileData *BLO_read_from_file(
  */
 BlendFileData *BLO_read_from_memory(
         const void *mem, int memsize,
-        ReportList *reports, eBLOReadSkip skip_flags)
+        eBLOReadSkip skip_flags,
+        ReportList *reports)
 {
        BlendFileData *bfd = NULL;
        FileData *fd;
@@ -370,7 +372,8 @@ BlendFileData *BLO_read_from_memory(
  */
 BlendFileData *BLO_read_from_memfile(
         Main *oldmain, const char *filename, MemFile *memfile,
-        ReportList *reports, eBLOReadSkip skip_flags)
+        eBLOReadSkip skip_flags,
+        ReportList *reports)
 {
        BlendFileData *bfd = NULL;
        FileData *fd;
index 614a3be559b505dc9870e007b370efa88097b517..37cd69b72f2a6c7d8cc034d69c8294a5b43502db 100644 (file)
@@ -130,7 +130,7 @@ void memfile_chunk_add(
 struct Main *BLO_memfile_main_get(struct MemFile *memfile, struct Main *oldmain, struct Scene **r_scene)
 {
        struct Main *bmain_undo = NULL;
-       BlendFileData *bfd = BLO_read_from_memfile(oldmain, BKE_main_blendfile_path(oldmain), memfile, NULL, BLO_READ_SKIP_NONE);
+       BlendFileData *bfd = BLO_read_from_memfile(oldmain, BKE_main_blendfile_path(oldmain), memfile, BLO_READ_SKIP_NONE, NULL);
 
        if (bfd) {
                bmain_undo = bfd->main;
index e1042f17229fc5692efc4f95288758289b392cc9..a8069b010267ffc4eca3f31f648e3dcf9cce6459 100644 (file)
@@ -196,7 +196,7 @@ static Main *load_main_from_memory(const void *blend, int blend_size)
        BlendFileData *bfd;
 
        G.fileflags |= G_FILE_NO_UI;
-       bfd = BLO_read_from_memory(blend, blend_size, NULL, BLO_READ_SKIP_NONE);
+       bfd = BLO_read_from_memory(blend, blend_size, BLO_READ_SKIP_NONE, NULL);
        if (bfd) {
                bmain = bfd->main;
 
index ef951010ba587a2865870039388e102a53e627d7..acb954a4b05abb7cca8bfe0eb54e24a880376d50 100644 (file)
@@ -569,7 +569,10 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
 
                /* confusing this global... */
                G.relbase_valid = 1;
-               retval = BKE_blendfile_read(C, filepath, reports, 0);
+               retval = BKE_blendfile_read(
+                       C, filepath,
+                       &(const struct BlendFileReadParams){0},
+                       reports);
 
                /* BKE_file_read sets new Main into context. */
                Main *bmain = CTX_data_main(C);
@@ -804,7 +807,13 @@ int wm_homefile_read(
 
        if (!use_factory_settings || (filepath_startup[0] != '\0')) {
                if (BLI_access(filepath_startup, R_OK) == 0) {
-                       success = (BKE_blendfile_read(C, filepath_startup, NULL, skip_flags) != BKE_BLENDFILE_READ_FAIL);
+                       success = BKE_blendfile_read(
+                               C, filepath_startup,
+                               &(const struct BlendFileReadParams){
+                                   .is_startup = true,
+                                   .skip_flags = skip_flags,
+                               },
+                               NULL) != BKE_BLENDFILE_READ_FAIL;
                }
                if (BLI_listbase_is_empty(&U.themes)) {
                        if (G.debug & G_DEBUG)
@@ -820,8 +829,12 @@ int wm_homefile_read(
 
        if (success == false) {
                success = BKE_blendfile_read_from_memory(
-                       C, datatoc_startup_blend, datatoc_startup_blend_size,
-                       NULL, skip_flags, true);
+                       C, datatoc_startup_blend, datatoc_startup_blend_size, true,
+                       &(const struct BlendFileReadParams){
+                           .is_startup = true,
+                           .skip_flags = skip_flags,
+                       },
+                       NULL);
                if (success) {
                        if (use_userdef) {
                                if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
index 22616458b54fe40dfc0c167b41944d9974753808..84cbf4bf85bb1d4f936b0f7f6c49408d282bea5f 100644 (file)
@@ -110,7 +110,8 @@ static BlendFileData *load_game_data(const char *filename)
        BlendFileData *bfd;
 
        BKE_reports_init(&reports, RPT_STORE);
-       bfd= BLO_read_from_file(filename, &reports, BLO_READ_SKIP_USERDEF);
+       bfd= BLO_read_from_file(filename, BLO_READ_SKIP_USERDEF, &reports);
+
 
        if (!bfd) {
                printf("Loading %s failed: ", filename);
index 42b603f8980ec82d9474fc6fe1cc42e1b3e97788..46b477a6da57ebcc0e67748ea84d2df67834b61c 100644 (file)
@@ -355,7 +355,7 @@ static BlendFileData *load_game_data(const char *progname, char *filename = NULL
                        BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name));
                }
        } else {
-               bfd= BLO_read_from_file(progname, &reports, BLO_READ_SKIP_NONE);
+               bfd= BLO_read_from_file(progname, BLO_READ_SKIP_NONE, &reports);
        }
 
        if (!bfd && filename) {