Plan save-as file writes in app core

This commit is contained in:
2026-06-02 23:18:19 +02:00
parent 853307697a
commit 8de9dadf1d
6 changed files with 92 additions and 27 deletions

View File

@@ -66,6 +66,11 @@ struct DocumentVersionTarget {
std::string path;
};
struct DocumentFileSavePlan {
DocumentFileTarget target;
DocumentFileWriteDecision write_decision = DocumentFileWriteDecision::save_now;
};
struct NewDocumentPlan {
DocumentFileTarget target;
int resolution = 0;
@@ -182,6 +187,23 @@ struct NewDocumentPlan {
: DocumentFileWriteDecision::save_now;
}
template <typename ExistsPredicate>
[[nodiscard]] pp::foundation::Result<DocumentFileSavePlan> plan_document_file_save(
std::string_view work_directory,
std::string_view document_name,
ExistsPredicate&& exists)
{
auto target = make_document_file_target(work_directory, document_name);
if (!target) {
return pp::foundation::Result<DocumentFileSavePlan>::failure(target.status());
}
DocumentFileSavePlan plan;
plan.target = std::move(target.value());
plan.write_decision = plan_document_file_write(exists(plan.target.path));
return pp::foundation::Result<DocumentFileSavePlan>::success(std::move(plan));
}
[[nodiscard]] constexpr pp::foundation::Result<int> document_resolution_from_index(int index) noexcept
{
constexpr std::array<int, 6> resolutions{ 512, 1024, 1536, 2048, 4096, 8192 };
@@ -205,15 +227,18 @@ template <typename ExistsPredicate>
return pp::foundation::Result<NewDocumentPlan>::failure(resolution.status());
}
auto target = make_document_file_target(work_directory, document_name);
if (!target) {
return pp::foundation::Result<NewDocumentPlan>::failure(target.status());
auto save_plan = plan_document_file_save(
work_directory,
document_name,
std::forward<ExistsPredicate>(exists));
if (!save_plan) {
return pp::foundation::Result<NewDocumentPlan>::failure(save_plan.status());
}
NewDocumentPlan plan;
plan.target = std::move(target.value());
plan.target = std::move(save_plan.value().target);
plan.resolution = resolution.value();
plan.write_decision = plan_document_file_write(exists(plan.target.path));
plan.write_decision = save_plan.value().write_decision;
return pp::foundation::Result<NewDocumentPlan>::success(std::move(plan));
}