* @brief Atomically serializes the current project to @p path. */
| 7711 | * @brief Atomically serializes the current project to @p path. |
| 7712 | */ |
| 7713 | bool DataModel::ProjectModel::writeProjectFile(const QString& path) |
| 7714 | { |
| 7715 | Q_ASSERT(!path.isEmpty()); |
| 7716 | |
| 7717 | QSaveFile file(path); |
| 7718 | if (!file.open(QFile::WriteOnly)) { |
| 7719 | qWarning() << "[ProjectModel] File open error:" << file.errorString(); |
| 7720 | return false; |
| 7721 | } |
| 7722 | |
| 7723 | const QByteArray payload = QJsonDocument(serializeToJson()).toJson(QJsonDocument::Indented); |
| 7724 | if (file.write(payload) != payload.size()) { |
| 7725 | qWarning() << "[ProjectModel] Short write:" << file.errorString(); |
| 7726 | file.cancelWriting(); |
| 7727 | return false; |
| 7728 | } |
| 7729 | |
| 7730 | if (!file.commit()) { |
| 7731 | qWarning() << "[ProjectModel] Commit failed:" << file.errorString(); |
| 7732 | return false; |
| 7733 | } |
| 7734 | |
| 7735 | watchProjectFile(); |
| 7736 | return true; |
| 7737 | } |
| 7738 | |
| 7739 | /** |
| 7740 | * @brief Returns the SHA-256 of the file at @p path, or an empty array when unreadable. |