MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / getLatestVersions

Method getLatestVersions

launcher/modplatform/flame/FlameAPI.cpp:105–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

executeTaskMethod · 0.80

Calls 12

QStringClass · 0.85
requireObjectFunction · 0.85
requireArrayFunction · 0.85
valueMethod · 0.80
networkMethod · 0.80
addNetActionMethod · 0.80
errorStringMethod · 0.80
appendMethod · 0.80
whatMethod · 0.80
getMethod · 0.45
startMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected