Fix T57989: File loaded as startup
The file contents was used to check if the file was a startup file. Now pass in an argument from startup loading code instead.
This commit is contained in:
@@ -34,6 +34,7 @@ struct Main;
|
|||||||
struct MemFile;
|
struct MemFile;
|
||||||
struct ReportList;
|
struct ReportList;
|
||||||
struct UserDef;
|
struct UserDef;
|
||||||
|
struct BlendFileReadParams;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
BKE_BLENDFILE_READ_FAIL = 0, /* no load */
|
BKE_BLENDFILE_READ_FAIL = 0, /* no load */
|
||||||
@@ -43,13 +44,16 @@ enum {
|
|||||||
|
|
||||||
int BKE_blendfile_read(
|
int BKE_blendfile_read(
|
||||||
struct bContext *C, const char *filepath,
|
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(
|
bool BKE_blendfile_read_from_memory(
|
||||||
struct bContext *C, const void *filebuf, int filelength,
|
struct bContext *C, const void *filebuf, int filelength, bool update_defaults,
|
||||||
struct ReportList *reports, int skip_flag, bool update_defaults);
|
const struct BlendFileReadParams *params,
|
||||||
|
struct ReportList *reports);
|
||||||
bool BKE_blendfile_read_from_memfile(
|
bool BKE_blendfile_read_from_memfile(
|
||||||
struct bContext *C, struct MemFile *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);
|
void BKE_blendfile_read_make_empty(struct bContext *C);
|
||||||
|
|
||||||
struct UserDef *BKE_blendfile_userdef_read(
|
struct UserDef *BKE_blendfile_userdef_read(
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
#include "BKE_main.h"
|
#include "BKE_main.h"
|
||||||
|
|
||||||
#include "BLO_undofile.h"
|
#include "BLO_undofile.h"
|
||||||
|
#include "BLO_readfile.h"
|
||||||
#include "BLO_writefile.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);
|
success = (BKE_blendfile_read(C, mfu->filename, NULL, 0) != BKE_BLENDFILE_READ_FAIL);
|
||||||
}
|
}
|
||||||
else {
|
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. */
|
/* Restore, bmain has been re-allocated. */
|
||||||
|
@@ -111,11 +111,12 @@ static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
|
|||||||
*/
|
*/
|
||||||
static void setup_app_data(
|
static void setup_app_data(
|
||||||
bContext *C, BlendFileData *bfd,
|
bContext *C, BlendFileData *bfd,
|
||||||
const char *filepath, ReportList *reports)
|
const char *filepath,
|
||||||
|
const bool is_startup,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
Main *bmain = G_MAIN;
|
Main *bmain = G_MAIN;
|
||||||
Scene *curscene = NULL;
|
Scene *curscene = NULL;
|
||||||
const bool is_startup = (bfd->filename[0] == '\0');
|
|
||||||
const bool recover = (G.fileflags & G_FILE_RECOVER) != 0;
|
const bool recover = (G.fileflags & G_FILE_RECOVER) != 0;
|
||||||
enum {
|
enum {
|
||||||
LOAD_UI = 1,
|
LOAD_UI = 1,
|
||||||
@@ -296,7 +297,7 @@ static void setup_app_data(
|
|||||||
bmain->recovered = 0;
|
bmain->recovered = 0;
|
||||||
|
|
||||||
/* startup.blend or recovered startup */
|
/* startup.blend or recovered startup */
|
||||||
if (bfd->filename[0] == 0) {
|
if (is_startup) {
|
||||||
bmain->name[0] = '\0';
|
bmain->name[0] = '\0';
|
||||||
}
|
}
|
||||||
else if (recover && G.relbase_valid) {
|
else if (recover && G.relbase_valid) {
|
||||||
@@ -351,7 +352,8 @@ static int handle_subversion_warning(Main *main, ReportList *reports)
|
|||||||
|
|
||||||
int BKE_blendfile_read(
|
int BKE_blendfile_read(
|
||||||
bContext *C, const char *filepath,
|
bContext *C, const char *filepath,
|
||||||
ReportList *reports, int skip_flags)
|
const struct BlendFileReadParams *params,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
BlendFileData *bfd;
|
BlendFileData *bfd;
|
||||||
int retval = BKE_BLENDFILE_READ_OK;
|
int retval = BKE_BLENDFILE_READ_OK;
|
||||||
@@ -361,7 +363,7 @@ int BKE_blendfile_read(
|
|||||||
printf("Read blend: %s\n", filepath);
|
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) {
|
||||||
if (bfd->user) {
|
if (bfd->user) {
|
||||||
retval = BKE_BLENDFILE_READ_OK_USERPREFS;
|
retval = BKE_BLENDFILE_READ_OK_USERPREFS;
|
||||||
@@ -374,7 +376,7 @@ int BKE_blendfile_read(
|
|||||||
retval = BKE_BLENDFILE_READ_FAIL;
|
retval = BKE_BLENDFILE_READ_FAIL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setup_app_data(C, bfd, filepath, reports);
|
setup_app_data(C, bfd, filepath, params->is_startup, reports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -384,16 +386,17 @@ int BKE_blendfile_read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool BKE_blendfile_read_from_memory(
|
bool BKE_blendfile_read_from_memory(
|
||||||
bContext *C, const void *filebuf, int filelength,
|
bContext *C, const void *filebuf, int filelength, bool update_defaults,
|
||||||
ReportList *reports, int skip_flags, bool update_defaults)
|
const struct BlendFileReadParams *params,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
BlendFileData *bfd;
|
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 (bfd) {
|
||||||
if (update_defaults)
|
if (update_defaults)
|
||||||
BLO_update_defaults_startup_blend(bfd->main);
|
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 {
|
else {
|
||||||
BKE_reports_prepend(reports, "Loading failed: ");
|
BKE_reports_prepend(reports, "Loading failed: ");
|
||||||
@@ -405,12 +408,13 @@ bool BKE_blendfile_read_from_memory(
|
|||||||
/* memfile is the undo buffer */
|
/* memfile is the undo buffer */
|
||||||
bool BKE_blendfile_read_from_memfile(
|
bool BKE_blendfile_read_from_memfile(
|
||||||
bContext *C, struct MemFile *memfile,
|
bContext *C, struct MemFile *memfile,
|
||||||
ReportList *reports, int skip_flags)
|
const struct BlendFileReadParams *params,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
Main *bmain = CTX_data_main(C);
|
Main *bmain = CTX_data_main(C);
|
||||||
BlendFileData *bfd;
|
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) {
|
if (bfd) {
|
||||||
/* remove the unused screens and wm */
|
/* remove the unused screens and wm */
|
||||||
while (bfd->main->wm.first)
|
while (bfd->main->wm.first)
|
||||||
@@ -418,7 +422,7 @@ bool BKE_blendfile_read_from_memfile(
|
|||||||
while (bfd->main->screen.first)
|
while (bfd->main->screen.first)
|
||||||
BKE_libblock_free(bfd->main, 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 {
|
else {
|
||||||
BKE_reports_prepend(reports, "Loading failed: ");
|
BKE_reports_prepend(reports, "Loading failed: ");
|
||||||
@@ -459,7 +463,7 @@ UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
|
|||||||
BlendFileData *bfd;
|
BlendFileData *bfd;
|
||||||
UserDef *userdef = NULL;
|
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) {
|
||||||
if (bfd->user) {
|
if (bfd->user) {
|
||||||
userdef = bfd->user;
|
userdef = bfd->user;
|
||||||
@@ -479,7 +483,10 @@ UserDef *BKE_blendfile_userdef_read_from_memory(
|
|||||||
BlendFileData *bfd;
|
BlendFileData *bfd;
|
||||||
UserDef *userdef = NULL;
|
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) {
|
||||||
if (bfd->user) {
|
if (bfd->user) {
|
||||||
userdef = bfd->user;
|
userdef = bfd->user;
|
||||||
|
@@ -48,6 +48,7 @@ struct View3D;
|
|||||||
struct bContext;
|
struct bContext;
|
||||||
struct BHead;
|
struct BHead;
|
||||||
struct FileData;
|
struct FileData;
|
||||||
|
struct BlendFileReadParams;
|
||||||
|
|
||||||
typedef struct BlendHandle BlendHandle;
|
typedef struct BlendHandle BlendHandle;
|
||||||
|
|
||||||
@@ -71,6 +72,10 @@ typedef struct BlendFileData {
|
|||||||
eBlenFileType type;
|
eBlenFileType type;
|
||||||
} BlendFileData;
|
} 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). */
|
/* skip reading some data-block types (may want to skip screen data too). */
|
||||||
typedef enum eBLOReadSkip {
|
typedef enum eBLOReadSkip {
|
||||||
@@ -83,13 +88,16 @@ typedef enum eBLOReadSkip {
|
|||||||
|
|
||||||
BlendFileData *BLO_read_from_file(
|
BlendFileData *BLO_read_from_file(
|
||||||
const char *filepath,
|
const char *filepath,
|
||||||
struct ReportList *reports, eBLOReadSkip skip_flag);
|
eBLOReadSkip skip_flags,
|
||||||
|
struct ReportList *reports);
|
||||||
BlendFileData *BLO_read_from_memory(
|
BlendFileData *BLO_read_from_memory(
|
||||||
const void *mem, int memsize,
|
const void *mem, int memsize,
|
||||||
struct ReportList *reports, eBLOReadSkip skip_flag);
|
eBLOReadSkip skip_flags,
|
||||||
|
struct ReportList *reports);
|
||||||
BlendFileData *BLO_read_from_memfile(
|
BlendFileData *BLO_read_from_memfile(
|
||||||
struct Main *oldmain, const char *filename, struct MemFile *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);
|
void BLO_blendfiledata_free(BlendFileData *bfd);
|
||||||
|
|
||||||
|
@@ -319,7 +319,8 @@ void BLO_blendhandle_close(BlendHandle *bh)
|
|||||||
*/
|
*/
|
||||||
BlendFileData *BLO_read_from_file(
|
BlendFileData *BLO_read_from_file(
|
||||||
const char *filepath,
|
const char *filepath,
|
||||||
ReportList *reports, eBLOReadSkip skip_flags)
|
eBLOReadSkip skip_flags,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
BlendFileData *bfd = NULL;
|
BlendFileData *bfd = NULL;
|
||||||
FileData *fd;
|
FileData *fd;
|
||||||
@@ -346,7 +347,8 @@ BlendFileData *BLO_read_from_file(
|
|||||||
*/
|
*/
|
||||||
BlendFileData *BLO_read_from_memory(
|
BlendFileData *BLO_read_from_memory(
|
||||||
const void *mem, int memsize,
|
const void *mem, int memsize,
|
||||||
ReportList *reports, eBLOReadSkip skip_flags)
|
eBLOReadSkip skip_flags,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
BlendFileData *bfd = NULL;
|
BlendFileData *bfd = NULL;
|
||||||
FileData *fd;
|
FileData *fd;
|
||||||
@@ -370,7 +372,8 @@ BlendFileData *BLO_read_from_memory(
|
|||||||
*/
|
*/
|
||||||
BlendFileData *BLO_read_from_memfile(
|
BlendFileData *BLO_read_from_memfile(
|
||||||
Main *oldmain, const char *filename, MemFile *memfile,
|
Main *oldmain, const char *filename, MemFile *memfile,
|
||||||
ReportList *reports, eBLOReadSkip skip_flags)
|
eBLOReadSkip skip_flags,
|
||||||
|
ReportList *reports)
|
||||||
{
|
{
|
||||||
BlendFileData *bfd = NULL;
|
BlendFileData *bfd = NULL;
|
||||||
FileData *fd;
|
FileData *fd;
|
||||||
|
@@ -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 *BLO_memfile_main_get(struct MemFile *memfile, struct Main *oldmain, struct Scene **r_scene)
|
||||||
{
|
{
|
||||||
struct Main *bmain_undo = NULL;
|
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) {
|
if (bfd) {
|
||||||
bmain_undo = bfd->main;
|
bmain_undo = bfd->main;
|
||||||
|
@@ -196,7 +196,7 @@ static Main *load_main_from_memory(const void *blend, int blend_size)
|
|||||||
BlendFileData *bfd;
|
BlendFileData *bfd;
|
||||||
|
|
||||||
G.fileflags |= G_FILE_NO_UI;
|
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) {
|
if (bfd) {
|
||||||
bmain = bfd->main;
|
bmain = bfd->main;
|
||||||
|
|
||||||
|
@@ -569,7 +569,10 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
|
|||||||
|
|
||||||
/* confusing this global... */
|
/* confusing this global... */
|
||||||
G.relbase_valid = 1;
|
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. */
|
/* BKE_file_read sets new Main into context. */
|
||||||
Main *bmain = CTX_data_main(C);
|
Main *bmain = CTX_data_main(C);
|
||||||
@@ -804,7 +807,13 @@ int wm_homefile_read(
|
|||||||
|
|
||||||
if (!use_factory_settings || (filepath_startup[0] != '\0')) {
|
if (!use_factory_settings || (filepath_startup[0] != '\0')) {
|
||||||
if (BLI_access(filepath_startup, R_OK) == 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 (BLI_listbase_is_empty(&U.themes)) {
|
||||||
if (G.debug & G_DEBUG)
|
if (G.debug & G_DEBUG)
|
||||||
@@ -820,8 +829,12 @@ int wm_homefile_read(
|
|||||||
|
|
||||||
if (success == false) {
|
if (success == false) {
|
||||||
success = BKE_blendfile_read_from_memory(
|
success = BKE_blendfile_read_from_memory(
|
||||||
C, datatoc_startup_blend, datatoc_startup_blend_size,
|
C, datatoc_startup_blend, datatoc_startup_blend_size, true,
|
||||||
NULL, skip_flags, true);
|
&(const struct BlendFileReadParams){
|
||||||
|
.is_startup = true,
|
||||||
|
.skip_flags = skip_flags,
|
||||||
|
},
|
||||||
|
NULL);
|
||||||
if (success) {
|
if (success) {
|
||||||
if (use_userdef) {
|
if (use_userdef) {
|
||||||
if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
|
if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
|
||||||
|
@@ -110,7 +110,8 @@ static BlendFileData *load_game_data(const char *filename)
|
|||||||
BlendFileData *bfd;
|
BlendFileData *bfd;
|
||||||
|
|
||||||
BKE_reports_init(&reports, RPT_STORE);
|
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) {
|
if (!bfd) {
|
||||||
printf("Loading %s failed: ", filename);
|
printf("Loading %s failed: ", filename);
|
||||||
|
@@ -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));
|
BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name));
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
if (!bfd && filename) {
|
||||||
|
Reference in New Issue
Block a user