| 124 | } |
| 125 | |
| 126 | VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder) |
| 127 | { |
| 128 | QFile file(fileInfo.absoluteFilePath()); |
| 129 | if (!file.open(QFile::ReadOnly)) |
| 130 | { |
| 131 | auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString()); |
| 132 | return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr); |
| 133 | } |
| 134 | QJsonParseError error; |
| 135 | auto data = file.readAll(); |
| 136 | QJsonDocument doc = QJsonDocument::fromJson(data, &error); |
| 137 | file.close(); |
| 138 | if (error.error != QJsonParseError::NoError) |
| 139 | { |
| 140 | int line = 1; |
| 141 | int column = 0; |
| 142 | for(int i = 0; i < error.offset; i++) |
| 143 | { |
| 144 | if(data[i] == '\n') |
| 145 | { |
| 146 | line++; |
| 147 | column = 0; |
| 148 | continue; |
| 149 | } |
| 150 | column++; |
| 151 | } |
| 152 | auto errorStr = QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.") |
| 153 | .arg(fileInfo.fileName(), error.errorString()) |
| 154 | .arg(line).arg(column); |
| 155 | return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr); |
| 156 | } |
| 157 | return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), requireOrder); |
| 158 | } |
| 159 | |
| 160 | bool saveJsonFile(const QJsonDocument doc, const QString & filename) |
| 161 | { |
no test coverage detected