Move project save write planning to app core

This commit is contained in:
2026-06-06 12:00:57 +02:00
parent ed9709ade8
commit a03db82307
8 changed files with 199 additions and 15 deletions

View File

@@ -2370,7 +2370,7 @@ bool Canvas::project_save_thread(std::string file_path, bool show_progress)
// static char name[128];
// sprintf(name, "%s/latlong.ppi", data_path.c_str());
FILE* fp;
FILE* fp = nullptr;
const auto save_target = pp::app::plan_document_canvas_project_save_target(App::I->data_path, file_path);
if (!save_target) {
@@ -2385,15 +2385,25 @@ bool Canvas::project_save_thread(std::string file_path, bool show_progress)
LOG("file name %s", file_name.c_str());
LOG("tmp path %s", tmp_path.c_str());
bool use_tmp = false;
// check if file already exists
if ((fp = fopen(file_path.c_str(), "rb")))
{
bool target_exists = false;
if ((fp = fopen(file_path.c_str(), "rb"))) {
fclose(fp);
fp = nullptr;
target_exists = true;
}
const auto write_plan = pp::app::plan_document_canvas_project_save_write(save_paths, target_exists);
if (!write_plan) {
LOG("cannot plan project save write for %s: %s", file_path.c_str(), write_plan.status().message);
return false;
}
bool use_tmp = write_plan.value().uses_temporary;
if (write_plan.value().uses_temporary)
{
LOG("use tmp file");
// use tmp file for writing
use_tmp = true;
if (!(fp = fopen(tmp_path.c_str(), "wb")))
fp = fopen(write_plan.value().write_path.c_str(), "wb");
if (!fp)
{
LOG("cannot write tmp project to %s", tmp_path.c_str());
use_tmp = false;