| 11 | { |
| 12 | |
| 13 | bool parseVersionInfo(const QByteArray &data, VersionFileList &list, QString &error) |
| 14 | { |
| 15 | QJsonParseError jsonError; |
| 16 | QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); |
| 17 | if (jsonError.error != QJsonParseError::NoError) |
| 18 | { |
| 19 | error = QString("Failed to parse version info JSON: %1 at %2") |
| 20 | .arg(jsonError.errorString()) |
| 21 | .arg(jsonError.offset); |
| 22 | qCritical() << error; |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | QJsonObject json = jsonDoc.object(); |
| 27 | |
| 28 | qDebug() << data; |
| 29 | qDebug() << "Loading version info from JSON."; |
| 30 | QJsonArray filesArray = json.value("Files").toArray(); |
| 31 | for (QJsonValue fileValue : filesArray) |
| 32 | { |
| 33 | QJsonObject fileObj = fileValue.toObject(); |
| 34 | |
| 35 | QString file_path = fileObj.value("Path").toString(); |
| 36 | |
| 37 | VersionFileEntry file{file_path, fileObj.value("Perms").toVariant().toInt(), |
| 38 | FileSourceList(), fileObj.value("MD5").toString(), }; |
| 39 | qDebug() << "File" << file.path << "with perms" << file.mode; |
| 40 | |
| 41 | QJsonArray sourceArray = fileObj.value("Sources").toArray(); |
| 42 | for (QJsonValue val : sourceArray) |
| 43 | { |
| 44 | QJsonObject sourceObj = val.toObject(); |
| 45 | |
| 46 | QString type = sourceObj.value("SourceType").toString(); |
| 47 | if (type == "http") |
| 48 | { |
| 49 | file.sources.append(FileSource("http", sourceObj.value("Url").toString())); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | qWarning() << "Unknown source type" << type << "ignored."; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | qDebug() << "Loaded info for" << file.path; |
| 58 | |
| 59 | list.append(file); |
| 60 | } |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | bool processFileLists |
| 66 | ( |