fix [#22007] Saving a read-only file on windows : no warning and temporary files left there

* small improvement to last commit: actually pass the error value from WM_write_file back to the operator and cancel the operator if not successful. This also preserves the indication that the file hasn't been saved in case of error.
This commit is contained in:
Andrea Weikert
2010-04-14 20:45:36 +00:00
parent 72a73fc9fb
commit a02a4f0fc4
3 changed files with 10 additions and 6 deletions

View File

@@ -78,7 +78,7 @@ void WM_window_open_temp (struct bContext *C, struct rcti *position, int type);
int WM_read_homefile (struct bContext *C, struct wmOperator *op);
int WM_write_homefile (struct bContext *C, struct wmOperator *op);
void WM_read_file (struct bContext *C, char *name, struct ReportList *reports);
void WM_write_file (struct bContext *C, char *target, int fileflags, struct ReportList *reports);
int WM_write_file (struct bContext *C, char *target, int fileflags, struct ReportList *reports);
void WM_read_autosavefile(struct bContext *C);
void WM_autosave_init (struct wmWindowManager *wm);

View File

@@ -483,7 +483,7 @@ static void do_history(char *name, ReportList *reports)
BKE_report(reports, RPT_ERROR, "Unable to make version backup");
}
void WM_write_file(bContext *C, char *target, int fileflags, ReportList *reports)
int WM_write_file(bContext *C, char *target, int fileflags, ReportList *reports)
{
Library *li;
int len;
@@ -494,14 +494,14 @@ void WM_write_file(bContext *C, char *target, int fileflags, ReportList *reports
if (len == 0) return;
if (len >= FILE_MAX) {
BKE_report(reports, RPT_ERROR, "Path too long, cannot save");
return;
return -1;
}
/* send the OnSave event */
for (li= G.main->library.first; li; li= li->id.next) {
if (BLI_streq(li->name, target)) {
BKE_report(reports, RPT_ERROR, "Cannot overwrite used library");
return;
return -1;
}
}
@@ -539,9 +539,12 @@ void WM_write_file(bContext *C, char *target, int fileflags, ReportList *reports
else G.fileflags &= ~G_FILE_AUTOPLAY;
writeBlog();
} else {
return -1;
}
// XXX waitcursor(0);
return 0;
}
/* operator entry */

View File

@@ -1792,8 +1792,9 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
if(RNA_boolean_get(op->ptr, "relative_remap")) fileflags |= G_FILE_RELATIVE_REMAP;
else fileflags &= ~G_FILE_RELATIVE_REMAP;
WM_write_file(C, path, fileflags, op->reports);
if ( WM_write_file(C, path, fileflags, op->reports) != 0)
return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
return OPERATOR_FINISHED;