| 18 | const QString ChatSerializer::VERSION = "0.2"; |
| 19 | |
| 20 | SerializationResult ChatSerializer::saveToFile(const ChatModel *model, const QString &filePath) |
| 21 | { |
| 22 | if (!ensureDirectoryExists(filePath)) { |
| 23 | return {false, "Failed to create directory structure"}; |
| 24 | } |
| 25 | |
| 26 | QFile file(filePath); |
| 27 | if (!file.open(QIODevice::WriteOnly)) { |
| 28 | return {false, QString("Failed to open file for writing: %1").arg(filePath)}; |
| 29 | } |
| 30 | |
| 31 | QJsonObject root = serializeChat(model, filePath); |
| 32 | QJsonDocument doc(root); |
| 33 | |
| 34 | if (file.write(doc.toJson(QJsonDocument::Indented)) == -1) { |
| 35 | return {false, QString("Failed to write to file: %1").arg(file.errorString())}; |
| 36 | } |
| 37 | |
| 38 | return {true, QString()}; |
| 39 | } |
| 40 | |
| 41 | SerializationResult ChatSerializer::loadFromFile(ChatModel *model, const QString &filePath) |
| 42 | { |