| 70 | } |
| 71 | |
| 72 | bool Flame::File::parseFromObject(const QJsonObject& obj, bool throw_on_blocked) |
| 73 | { |
| 74 | fileName = Json::requireString(obj, "fileName"); |
| 75 | // This is a piece of a Flame project JSON pulled out into the file metadata (here) for convenience |
| 76 | // It is also optional |
| 77 | type = File::Type::SingleFile; |
| 78 | |
| 79 | if (fileName.endsWith(".zip")) { |
| 80 | // this is probably a resource pack |
| 81 | targetFolder = "resourcepacks"; |
| 82 | } else { |
| 83 | // this is probably a mod, dunno what else could modpacks download |
| 84 | targetFolder = "mods"; |
| 85 | } |
| 86 | // get the hash |
| 87 | hash = QString(); |
| 88 | auto hashes = Json::ensureArray(obj, "hashes"); |
| 89 | for(QJsonValueRef item : hashes) { |
| 90 | auto hobj = Json::requireObject(item); |
| 91 | auto algo = Json::requireInteger(hobj, "algo"); |
| 92 | auto value = Json::requireString(hobj, "value"); |
| 93 | if (algo == 1) { |
| 94 | hash = value; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | |
| 99 | // may throw, if the project is blocked |
| 100 | QString rawUrl = Json::ensureString(obj, "downloadUrl"); |
| 101 | url = QUrl(rawUrl, QUrl::TolerantMode); |
| 102 | if (!url.isValid() && throw_on_blocked) { |
| 103 | throw JSONValidationError(QString("Invalid URL: %1").arg(rawUrl)); |
| 104 | } |
| 105 | |
| 106 | resolved = true; |
| 107 | return true; |
| 108 | } |
no test coverage detected