Updated required_by as dependency

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-05-04 23:54:46 +03:00
parent 8b14b946e2
commit 107b470289
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
5 changed files with 25 additions and 26 deletions

View File

@ -65,7 +65,7 @@ void GetModDependenciesTask::prepare()
{
for (auto sel : m_selected) {
for (auto dep : getDependenciesForVersion(sel->version, sel->pack.provider)) {
addTask(prepareDependencyTask(dep, sel->pack.provider, sel->pack.addonId, 20));
addTask(prepareDependencyTask(dep, sel->pack.provider, 20));
}
}
}
@ -95,8 +95,6 @@ QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion
});
dep == m_pack_dependencies.end()) { // check loaded dependencies
c_dependencies.append(ver_dep);
} else { // already there just append the required_by
dep->get()->version.required_by.append(version.addonId);
}
}
}
@ -108,13 +106,11 @@ QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion
Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Dependency& dep,
const ModPlatform::ResourceProvider providerName,
QVariant required_by,
int level)
{
auto pDep = std::make_shared<PackDependency>();
pDep->dependency = dep;
pDep->pack = { dep.addonId, providerName };
pDep->version.required_by.append(required_by);
m_pack_dependencies.append(pDep);
auto provider = providerName == m_flame_provider.name ? m_flame_provider : m_modrinth_provider;
@ -145,7 +141,7 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen
ResourceAPI::DependencySearchArgs args = { dep, m_version, m_loaderType };
ResourceAPI::DependencySearchCallbacks callbacks;
callbacks.on_succeed = [dep, provider, pDep, level, required_by, this](auto& doc, auto& pack) {
callbacks.on_succeed = [dep, provider, pDep, level, this](auto& doc, auto& pack) {
try {
QJsonArray arr;
if (dep.version.length() != 0 && doc.isObject()) {
@ -153,7 +149,6 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen
} else {
arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
}
auto required_by = pDep->version.required_by;
pDep->version = provider.mod->loadDependencyVersions(dep, arr);
if (!pDep->version.addonId.isValid()) {
qWarning() << "Error while reading mod version empty ";
@ -161,7 +156,6 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen
return;
}
pDep->version.is_currently_selected = true;
pDep->version.required_by = required_by;
pDep->pack.versions = { pDep->version };
pDep->pack.versionsLoaded = true;
@ -175,7 +169,7 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen
return;
}
for (auto dep : getDependenciesForVersion(pDep->version, provider.name)) {
addTask(prepareDependencyTask(dep, provider.name, pDep->pack.addonId, level - 1));
addTask(prepareDependencyTask(dep, provider.name, level - 1));
}
};

View File

@ -64,7 +64,7 @@ class GetModDependenciesTask : public SequentialTask {
auto getDependecies() const -> QList<std::shared_ptr<PackDependency>> { return m_pack_dependencies; }
protected slots:
Task::Ptr prepareDependencyTask(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider, QVariant, int);
Task::Ptr prepareDependencyTask(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider, int);
QList<ModPlatform::Dependency> getDependenciesForVersion(const ModPlatform::IndexedVersion&,
const ModPlatform::ResourceProvider providerName);
void prepare();

View File

@ -78,7 +78,6 @@ struct IndexedVersion {
// For internal use, not provided by APIs
bool is_currently_selected = false;
QList<QVariant> required_by;
};
struct ExtraPackData {

View File

@ -125,16 +125,17 @@ void ResourceDownloadDialog::connectButtons()
static ModPlatform::ProviderCapabilities ProviderCaps;
QStringList getReqiredBy(QList<ResourceDownloadDialog::DownloadTaskPtr> tasks, QList<QVariant> req_by)
QStringList getReqiredBy(QList<ResourceDownloadDialog::DownloadTaskPtr> tasks, QVariant addonId)
{
auto req = QStringList();
for (auto r : req_by) {
for (auto& task : tasks) {
auto selected = task->getPack();
if (selected.addonId == r) {
req.append(selected.name);
break;
}
auto deps = task->getVersion().dependencies;
if (auto dep = std::find_if(deps.begin(), deps.end(),
[addonId](const ModPlatform::Dependency& d) {
return d.addonId == addonId && d.type == ModPlatform::DependencyType::REQUIRED;
});
dep) {
req.append(task->getName());
}
}
return req;
@ -178,7 +179,7 @@ void ResourceDownloadDialog::confirm()
});
for (auto& task : selected) {
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(),
ProviderCaps.name(task->getProvider()), getReqiredBy(selected, task->getVersion().required_by) });
ProviderCaps.name(task->getProvider()), getReqiredBy(selected, task->getPack().addonId) });
}
if (confirm_dialog->exec()) {

View File

@ -62,12 +62,17 @@ void ReviewMessageBox::appendResource(ResourceInformation&& info)
if (!info.required_by.isEmpty()) {
auto requiredByItem = new QTreeWidgetItem(itemTop);
QString req;
if (info.required_by.length() == 1)
req = info.required_by.back();
else
req = QString("[%1]").arg(info.required_by.join(", "));
requiredByItem->setText(0, tr("Required by: %1").arg(req));
if (info.required_by.length() == 1) {
requiredByItem->setText(0, tr("Required by: %1").arg(info.required_by.back()));
} else {
requiredByItem->setText(0, tr("Required by:"));
auto i = 0;
for (auto req : info.required_by) {
auto reqItem = new QTreeWidgetItem(requiredByItem);
reqItem->setText(0, req);
reqItem->insertChildren(i++, { reqItem });
}
}
itemTop->insertChildren(childIndx++, { requiredByItem });
}