| 110 | } |
| 111 | |
| 112 | VersionFilePtr parseJsonFile(const QFileInfo& fileInfo, const bool requireOrder) |
| 113 | { |
| 114 | QFile file(fileInfo.absoluteFilePath()); |
| 115 | if (!file.open(QFile::ReadOnly)) { |
| 116 | auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString()); |
| 117 | return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr); |
| 118 | } |
| 119 | QJsonParseError error; |
| 120 | auto data = file.readAll(); |
| 121 | QJsonDocument doc = QJsonDocument::fromJson(data, &error); |
| 122 | file.close(); |
| 123 | if (error.error != QJsonParseError::NoError) { |
| 124 | int line = 1; |
| 125 | int column = 0; |
| 126 | for (int i = 0; i < error.offset; i++) { |
| 127 | if (data[i] == '\n') { |
| 128 | line++; |
| 129 | column = 0; |
| 130 | continue; |
| 131 | } |
| 132 | column++; |
| 133 | } |
| 134 | auto errorStr = QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.") |
| 135 | .arg(fileInfo.fileName(), error.errorString()) |
| 136 | .arg(line) |
| 137 | .arg(column); |
| 138 | return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr); |
| 139 | } |
| 140 | return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), requireOrder); |
| 141 | } |
| 142 | |
| 143 | bool saveJsonFile(const QJsonDocument& doc, const QString& filename) |
| 144 | { |
no test coverage detected