| 89 | } |
| 90 | |
| 91 | VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder) |
| 92 | { |
| 93 | QFile file(fileInfo.absoluteFilePath()); |
| 94 | if (!file.open(QFile::ReadOnly)) |
| 95 | { |
| 96 | auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString()); |
| 97 | return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr); |
| 98 | } |
| 99 | QJsonParseError error; |
| 100 | auto data = file.readAll(); |
| 101 | QJsonDocument doc = QJsonDocument::fromJson(data, &error); |
| 102 | file.close(); |
| 103 | if (error.error != QJsonParseError::NoError) |
| 104 | { |
| 105 | int line = 1; |
| 106 | int column = 0; |
| 107 | for(int i = 0; i < error.offset; i++) |
| 108 | { |
| 109 | if(data[i] == '\n') |
| 110 | { |
| 111 | line++; |
| 112 | column = 0; |
| 113 | continue; |
| 114 | } |
| 115 | column++; |
| 116 | } |
| 117 | auto errorStr = QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.") |
| 118 | .arg(fileInfo.fileName(), error.errorString()) |
| 119 | .arg(line).arg(column); |
| 120 | return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr); |
| 121 | } |
| 122 | return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), requireOrder); |
| 123 | } |
| 124 | |
| 125 | bool saveJsonFile(const QJsonDocument doc, const QString & filename) |
| 126 | { |
no test coverage detected