WIP: uv-simple-select #1

Closed
Chris Blackbourn wants to merge 182 commits from uv-simple-select into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit fbbe2b4eaa - Show all commits

View File

@ -1760,6 +1760,41 @@ bool write_crash_blend(void)
return 0;
}
/**
* Helper to check if file `filepath` can be written.
* \return true if it can, otherwise report an error and return false.
*/
static bool wm_file_write_check_with_report_on_failure(Main *bmain,
const char *filepath,
ReportList *reports)
{
const int filepath_len = strlen(filepath);
if (filepath_len == 0) {
BKE_report(reports, RPT_ERROR, "Path is empty, cannot save");
return false;
}
if (filepath_len >= FILE_MAX) {
BKE_report(reports, RPT_ERROR, "Path too long, cannot save");
return false;
}
/* Check if file write permission is ok */
if (BLI_exists(filepath) && !BLI_file_is_writable(filepath)) {
BKE_reportf(reports, RPT_ERROR, "Cannot save blend file, path '%s' is not writable", filepath);
return false;
}
LISTBASE_FOREACH (Library *, li, &bmain->libraries) {
if (BLI_path_cmp(li->filepath_abs, filepath) == 0) {
BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath);
return false;
}
}
return true;
}
/**
* \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way.
*/
@ -1771,40 +1806,17 @@ static bool wm_file_write(bContext *C,
ReportList *reports)
{
Main *bmain = CTX_data_main(C);
int len;
int ok = false;
BlendThumbnail *thumb = nullptr, *main_thumb = nullptr;
ImBuf *ibuf_thumb = nullptr;
len = strlen(filepath);
if (len == 0) {
BKE_report(reports, RPT_ERROR, "Path is empty, cannot save");
return ok;
}
if (len >= FILE_MAX) {
BKE_report(reports, RPT_ERROR, "Path too long, cannot save");
return ok;
}
/* Check if file write permission is ok */
if (BLI_exists(filepath) && !BLI_file_is_writable(filepath)) {
BKE_reportf(reports, RPT_ERROR, "Cannot save blend file, path '%s' is not writable", filepath);
return ok;
}
/* NOTE: used to replace the file extension (to ensure '.blend'),
* no need to now because the operator ensures,
* its handy for scripts to save to a predefined name without blender editing it */
/* send the OnSave event */
LISTBASE_FOREACH (Library *, li, &bmain->libraries) {
if (BLI_path_cmp(li->filepath_abs, filepath) == 0) {
BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath);
if (!wm_file_write_check_with_report_on_failure(bmain, filepath, reports)) {
return ok;
}
}
/* Call pre-save callbacks before writing preview,
* that way you can generate custom file thumbnail. */