MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / parseFromObject

Method parseFromObject

launcher/modplatform/flame/PackManifest.cpp:72–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72bool 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}

Callers 2

updateInstanceMethod · 0.80
netJobFinishedMethod · 0.80

Calls 4

QStringClass · 0.85
requireObjectFunction · 0.85
QUrlClass · 0.85
isValidMethod · 0.45

Tested by

no test coverage detected