| 50 | static const int currentOrderFileVersion = 1; |
| 51 | |
| 52 | bool readOverrideOrders(QString path, PatchOrder &order) |
| 53 | { |
| 54 | QFile orderFile(path); |
| 55 | if (!orderFile.exists()) |
| 56 | { |
| 57 | qWarning() << "Order file doesn't exist. Ignoring."; |
| 58 | return false; |
| 59 | } |
| 60 | if (!orderFile.open(QFile::ReadOnly)) |
| 61 | { |
| 62 | qCritical() << "Couldn't open" << orderFile.fileName() |
| 63 | << " for reading:" << orderFile.errorString(); |
| 64 | qWarning() << "Ignoring overriden order"; |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | // and it's valid JSON |
| 69 | QJsonParseError error; |
| 70 | QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error); |
| 71 | if (error.error != QJsonParseError::NoError) |
| 72 | { |
| 73 | qCritical() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString(); |
| 74 | qWarning() << "Ignoring overriden order"; |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | // and then read it and process it if all above is true. |
| 79 | try |
| 80 | { |
| 81 | auto obj = Json::requireObject(doc); |
| 82 | // check order file version. |
| 83 | auto version = Json::requireInteger(obj.value("version")); |
| 84 | if (version != currentOrderFileVersion) |
| 85 | { |
| 86 | throw JSONValidationError(QObject::tr("Invalid order file version, expected %1") |
| 87 | .arg(currentOrderFileVersion)); |
| 88 | } |
| 89 | auto orderArray = Json::requireArray(obj.value("order")); |
| 90 | for(auto item: orderArray) |
| 91 | { |
| 92 | order.append(Json::requireString(item)); |
| 93 | } |
| 94 | } |
| 95 | catch (const JSONValidationError &err) |
| 96 | { |
| 97 | qCritical() << "Couldn't parse" << orderFile.fileName() << ": bad file format"; |
| 98 | qWarning() << "Ignoring overriden order"; |
| 99 | order.clear(); |
| 100 | return false; |
| 101 | } |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | static VersionFilePtr createErrorVersionFile(QString fileId, QString filepath, QString error) |
| 106 | { |
nothing calls this directly
no test coverage detected