MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / getProjectInfo

Method getProjectInfo

launcher/modplatform/ResourceAPI.cpp:151–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151Task::Ptr ResourceAPI::getProjectInfo(ProjectInfoArgs&& args, Callback<ModPlatform::IndexedPack::Ptr>&& callbacks) const
152{
153 auto [job, response] = getProject(args.pack->addonId.toString());
154
155 QObject::connect(job.get(), &NetJob::succeeded, [this, response, callbacks, args] {
156 auto pack = args.pack;
157 QJsonParseError parse_error{};
158 QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
159 if (parse_error.error != QJsonParseError::NoError) {
160 qWarning() << "Error while parsing JSON response for mod info at" << parse_error.offset
161 << "reason:" << parse_error.errorString();
162 qWarning() << *response;
163 return;
164 }
165 try {
166 auto obj = Json::requireObject(doc);
167 if (obj.contains("data"))
168 obj = Json::requireObject(obj, "data");
169 loadIndexedPack(*pack, obj);
170 loadExtraPackInfo(*pack, obj);
171 } catch (const JSONValidationError& e) {
172 qDebug() << doc;
173 qWarning() << "Error while reading" << debugName() << "resource info:" << e.cause();
174 }
175 callbacks.on_succeed(pack);
176 });
177 // Capture a weak_ptr instead of a shared_ptr to avoid circular dependency issues.
178 // This prevents the lambda from extending the lifetime of the shared resource,
179 // as it only temporarily locks the resource when needed.
180 auto weak = job.toWeakRef();
181 QObject::connect(job.get(), &NetJob::failed, [weak, callbacks](const QString& reason) {
182 int network_error_code = -1;
183 if (auto job = weak.lock()) {
184 if (auto netJob = qSharedPointerDynamicCast<NetJob>(job)) {
185 if (auto* failed_action = netJob->getFailedActions().at(0); failed_action) {
186 network_error_code = failed_action->replyStatusCode();
187 }
188 }
189 }
190 callbacks.on_fail(reason, network_error_code);
191 });
192 QObject::connect(job.get(), &NetJob::aborted, [callbacks] {
193 if (callbacks.on_abort != nullptr)
194 callbacks.on_abort();
195 });
196 return job;
197}
198
199Task::Ptr ResourceAPI::getDependencyVersion(DependencySearchArgs&& args, Callback<ModPlatform::IndexedVersion>&& callbacks) const
200{

Callers 5

searchMethod · 0.80
loadEntryMethod · 0.80
onSelectionChangedMethod · 0.80

Calls 11

requireObjectFunction · 0.85
errorStringMethod · 0.80
causeMethod · 0.80
getFailedActionsMethod · 0.80
replyStatusCodeMethod · 0.80
debugNameFunction · 0.50
toStringMethod · 0.45
getMethod · 0.45
containsMethod · 0.45
lockMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected