| 15 | static const int currentOrderFileVersion = 1; |
| 16 | |
| 17 | bool readOverrideOrders(QString path, PatchOrder &order) |
| 18 | { |
| 19 | QFile orderFile(path); |
| 20 | if (!orderFile.exists()) |
| 21 | { |
| 22 | qWarning() << "Order file doesn't exist. Ignoring."; |
| 23 | return false; |
| 24 | } |
| 25 | if (!orderFile.open(QFile::ReadOnly)) |
| 26 | { |
| 27 | qCritical() << "Couldn't open" << orderFile.fileName() |
| 28 | << " for reading:" << orderFile.errorString(); |
| 29 | qWarning() << "Ignoring overriden order"; |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // and it's valid JSON |
| 34 | QJsonParseError error; |
| 35 | QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error); |
| 36 | if (error.error != QJsonParseError::NoError) |
| 37 | { |
| 38 | qCritical() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString(); |
| 39 | qWarning() << "Ignoring overriden order"; |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | // and then read it and process it if all above is true. |
| 44 | try |
| 45 | { |
| 46 | auto obj = Json::requireObject(doc); |
| 47 | // check order file version. |
| 48 | auto version = Json::requireValueInteger(obj.value("version")); |
| 49 | if (version != currentOrderFileVersion) |
| 50 | { |
| 51 | throw JSONValidationError(QObject::tr("Invalid order file version, expected %1") |
| 52 | .arg(currentOrderFileVersion)); |
| 53 | } |
| 54 | auto orderArray = Json::requireValueArray(obj.value("order")); |
| 55 | for(auto item: orderArray) |
| 56 | { |
| 57 | order.append(Json::requireValueString(item)); |
| 58 | } |
| 59 | } |
| 60 | catch (const JSONValidationError &err) |
| 61 | { |
| 62 | qCritical() << "Couldn't parse" << orderFile.fileName() << ": bad file format"; |
| 63 | qWarning() << "Ignoring overriden order"; |
| 64 | order.clear(); |
| 65 | return false; |
| 66 | } |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | static VersionFilePtr createErrorVersionFile(QString fileId, QString filepath, QString error) |
| 71 | { |
no test coverage detected