Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/windowmanager/intern/wm_files.c')
-rw-r--r--source/blender/windowmanager/intern/wm_files.c107
1 files changed, 61 insertions, 46 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index ed1b29d61ce..d5a240a358e 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -679,7 +679,8 @@ static void wm_file_read_post(bContext *C,
bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
{
/* assume automated tasks with background, don't write recent file list */
- const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0);
+ const bool do_history_file_update = (G.background == false) &&
+ (CTX_wm_manager(C)->op_undo_depth == 0);
bool success = false;
const bool use_data = true;
@@ -745,7 +746,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
WM_check(C); /* opens window(s), checks keymaps */
if (success) {
- if (do_history) {
+ if (do_history_file_update) {
wm_history_file_update();
}
}
@@ -777,7 +778,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
if (success == false) {
/* remove from recent files list */
- if (do_history) {
+ if (do_history_file_update) {
RecentFile *recent = wm_file_history_find(filepath);
if (recent) {
wm_history_file_free(recent);
@@ -905,6 +906,13 @@ void wm_homefile_read(bContext *C,
SET_FLAG_FROM_TEST(G.f, (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0, G_FLAG_SCRIPT_AUTOEXEC);
}
+ if (use_data) {
+ if (reset_app_template) {
+ /* Always load UI when switching to another template. */
+ G.fileflags &= ~G_FILE_NO_UI;
+ }
+ }
+
if (use_userdef || reset_app_template) {
#ifdef WITH_PYTHON
/* This only runs once Blender has already started. */
@@ -1109,18 +1117,6 @@ void wm_homefile_read(bContext *C,
BLI_strncpy(U.app_template, app_template_override, sizeof(U.app_template));
}
- if (use_data) {
- /* 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;
-
- if (reset_app_template) {
- /* Always load UI when switching to another template. */
- G.fileflags &= ~G_FILE_NO_UI;
- }
- }
-
bmain = CTX_data_main(C);
if (use_userdef) {
@@ -1408,11 +1404,10 @@ static ImBuf *blend_file_thumb(const bContext *C,
bool write_crash_blend(void)
{
char path[FILE_MAX];
- int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on crash file */
BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path));
BLI_path_extension_replace(path, sizeof(path), "_crash.blend");
- if (BLO_write_file(G_MAIN, path, fileflags, NULL, NULL)) {
+ if (BLO_write_file(G_MAIN, path, G.fileflags, &(const struct BlendFileWriteParams){0}, NULL)) {
printf("written: %s\n", path);
return 1;
}
@@ -1425,7 +1420,12 @@ bool write_crash_blend(void)
/**
* \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way.
*/
-static bool wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports)
+static bool wm_file_write(bContext *C,
+ const char *filepath,
+ int fileflags,
+ eBLO_WritePathRemap remap_mode,
+ bool use_save_as_copy,
+ ReportList *reports)
{
Main *bmain = CTX_data_main(C);
Library *li;
@@ -1458,7 +1458,7 @@ static bool wm_file_write(bContext *C, const char *filepath, int fileflags, Repo
/* send the OnSave event */
for (li = bmain->libraries.first; li; li = li->id.next) {
- if (BLI_path_cmp(li->filepath, filepath) == 0) {
+ if (BLI_path_cmp(li->filepath_abs, filepath) == 0) {
BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath);
return ok;
}
@@ -1491,21 +1491,29 @@ static bool wm_file_write(bContext *C, const char *filepath, int fileflags, Repo
ED_editors_flush_edits(bmain);
- fileflags |= G_FILE_HISTORY; /* write file history */
-
/* first time saving */
/* XXX temp solution to solve bug, real fix coming (ton) */
- if ((BKE_main_blendfile_path(bmain)[0] == '\0') && !(fileflags & G_FILE_SAVE_COPY)) {
+ if ((BKE_main_blendfile_path(bmain)[0] == '\0') && (use_save_as_copy == false)) {
BLI_strncpy(bmain->name, filepath, sizeof(bmain->name));
}
/* XXX temp solution to solve bug, real fix coming (ton) */
bmain->recovered = 0;
- if (BLO_write_file(CTX_data_main(C), filepath, fileflags, reports, thumb)) {
- const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0);
-
- if (!(fileflags & G_FILE_SAVE_COPY)) {
+ if (BLO_write_file(CTX_data_main(C),
+ filepath,
+ fileflags,
+ &(const struct BlendFileWriteParams){
+ .remap_mode = remap_mode,
+ .use_save_versions = true,
+ .use_save_as_copy = use_save_as_copy,
+ .thumb = thumb,
+ },
+ reports)) {
+ const bool do_history_file_update = (G.background == false) &&
+ (CTX_wm_manager(C)->op_undo_depth == 0);
+
+ if (use_save_as_copy == false) {
G.relbase_valid = 1;
BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); /* is guaranteed current file */
@@ -1515,7 +1523,7 @@ static bool wm_file_write(bContext *C, const char *filepath, int fileflags, Repo
SET_FLAG_FROM_TEST(G.fileflags, fileflags & G_FILE_COMPRESS, G_FILE_COMPRESS);
/* prevent background mode scripts from clobbering history */
- if (do_history) {
+ if (do_history_file_update) {
wm_history_file_update();
}
@@ -1603,16 +1611,14 @@ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *UNUSED(wt))
WM_event_remove_timer(wm, NULL, wm->autosavetimer);
- /* if a modal operator is running, don't autosave, but try again in 10 seconds */
+ /* If a modal operator is running, don't autosave because we might not be in
+ * a valid state to save. But try again in 10ms. */
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) {
if (handler_base->type == WM_HANDLER_TYPE_OP) {
wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
if (handler->op) {
- wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, 10.0);
- if (G.debug) {
- printf("Skipping auto-save, modal operator running, retrying in ten seconds...\n");
- }
+ wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, 0.01);
return;
}
}
@@ -1630,12 +1636,12 @@ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *UNUSED(wt))
}
else {
/* Save as regular blend file. */
- int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
+ const int fileflags = G.fileflags & ~G_FILE_COMPRESS;
ED_editors_flush_edits(bmain);
- /* Error reporting into console */
- BLO_write_file(bmain, filepath, fileflags, NULL, NULL);
+ /* Error reporting into console. */
+ BLO_write_file(bmain, filepath, fileflags, &(const struct BlendFileWriteParams){0}, NULL);
}
/* do timer after file write, just in case file write takes a long time */
wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, U.savetime * 60.0);
@@ -1753,9 +1759,15 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
ED_editors_flush_edits(bmain);
/* Force save as regular blend file. */
- fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
-
- if (BLO_write_file(bmain, filepath, fileflags, op->reports, NULL) == 0) {
+ fileflags = G.fileflags & ~G_FILE_COMPRESS;
+
+ if (BLO_write_file(bmain,
+ filepath,
+ fileflags,
+ &(const struct BlendFileWriteParams){
+ .remap_mode = BLO_WRITE_PATH_REMAP_RELATIVE,
+ },
+ op->reports) == 0) {
printf("fail\n");
return OPERATOR_CANCELLED;
}
@@ -2670,7 +2682,15 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
char path[FILE_MAX];
const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke);
-
+ const bool use_save_as_copy = (RNA_struct_property_is_set(op->ptr, "copy") &&
+ RNA_boolean_get(op->ptr, "copy"));
+
+ /* We could expose all options to the users however in most cases remapping
+ * existing relative paths is a good default.
+ * Users can manually make their paths relative & absolute if they wish. */
+ const eBLO_WritePathRemap remap_mode = RNA_boolean_get(op->ptr, "relative_remap") ?
+ BLO_WRITE_PATH_REMAP_RELATIVE :
+ BLO_WRITE_PATH_REMAP_NONE;
save_set_compress(op);
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -2682,17 +2702,12 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
}
const int fileflags_orig = G.fileflags;
- int fileflags = G.fileflags & ~G_FILE_USERPREFS;
+ int fileflags = G.fileflags;
/* set compression flag */
SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "compress"), G_FILE_COMPRESS);
- SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "relative_remap"), G_FILE_RELATIVE_REMAP);
- SET_FLAG_FROM_TEST(
- fileflags,
- (RNA_struct_property_is_set(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy")),
- G_FILE_SAVE_COPY);
- const bool ok = wm_file_write(C, path, fileflags, op->reports);
+ const bool ok = wm_file_write(C, path, fileflags, remap_mode, use_save_as_copy, op->reports);
if ((op->flag & OP_IS_INVOKE) == 0) {
/* OP_IS_INVOKE is set when the operator is called from the GUI.