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

Method getLatestVersion

launcher/modplatform/flame/FlameAPI.cpp:107–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion
108{
109 QEventLoop loop;
110
111 auto netJob = new NetJob(QString("Flame::GetLatestVersion(%1)").arg(args.addonId), APPLICATION->network());
112 auto response = new QByteArray();
113 ModPlatform::IndexedVersion ver;
114
115 netJob->addNetAction(Net::Download::makeByteArray(getVersionsURL(args), response));
116
117 QObject::connect(netJob, &NetJob::succeeded, [response, args, &ver] {
118 QJsonParseError parse_error{};
119 QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
120 if (parse_error.error != QJsonParseError::NoError) {
121 qWarning() << "Error while parsing JSON response from latest mod version at " << parse_error.offset
122 << " reason: " << parse_error.errorString();
123 qWarning() << *response;
124 return;
125 }
126
127 try {
128 auto obj = Json::requireObject(doc);
129 auto arr = Json::requireArray(obj, "data");
130
131 QJsonObject latest_file_obj;
132 ModPlatform::IndexedVersion ver_tmp;
133
134 for (auto file : arr) {
135 auto file_obj = Json::requireObject(file);
136 auto file_tmp = FlameMod::loadIndexedPackVersion(file_obj);
137 if(file_tmp.date > ver_tmp.date) {
138 ver_tmp = file_tmp;
139 latest_file_obj = file_obj;
140 }
141 }
142
143 ver = FlameMod::loadIndexedPackVersion(latest_file_obj);
144 } catch (Json::JsonException& e) {
145 qCritical() << "Failed to parse response from a version request.";
146 qCritical() << e.what();
147 qDebug() << doc;
148 }
149 });
150
151 QObject::connect(netJob, &NetJob::finished, [response, netJob, &loop] {
152 netJob->deleteLater();
153 delete response;
154 loop.quit();
155 });
156
157 netJob->start();
158
159 loop.exec();
160
161 return ver;
162}
163
164auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob*

Callers 1

executeTaskMethod · 0.80

Calls 9

QStringClass · 0.85
fromJsonFunction · 0.85
requireObjectFunction · 0.85
requireArrayFunction · 0.85
networkMethod · 0.80
addNetActionMethod · 0.80
whatMethod · 0.80
startMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected