Fixed comments
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
9fbec3793f
commit
f7b912fc9d
@ -1,8 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -47,7 +46,7 @@ static ResourceAPI::ModLoaderTypes mcLoaders(BaseInstance* inst)
|
||||
GetModDependenciesTask::GetModDependenciesTask(QObject* parent,
|
||||
BaseInstance* instance,
|
||||
ModFolderModel* folder,
|
||||
QList<std::shared_ptr<PackDependecny>> selected)
|
||||
QList<std::shared_ptr<PackDependency>> selected)
|
||||
: SequentialTask(parent, "Get dependencies")
|
||||
, m_selected(selected)
|
||||
, m_flame_provider{ ModPlatform::ResourceProvider::FLAME, std::make_shared<ResourceDownload::FlameModModel>(*instance),
|
||||
@ -66,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, 20));
|
||||
addTask(prepareDependencyTask(dep, sel->pack.provider, sel->pack.addonId, 20));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,7 +80,7 @@ QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion
|
||||
[&ver_dep](const ModPlatform::Dependency& i) { return i.addonId == ver_dep.addonId; });
|
||||
dep == c_dependencies.end()) { // check the current dependency list
|
||||
if (auto dep = std::find_if(m_selected.begin(), m_selected.end(),
|
||||
[&ver_dep, providerName](std::shared_ptr<PackDependecny> i) {
|
||||
[&ver_dep, providerName](std::shared_ptr<PackDependency> i) {
|
||||
return i->pack.addonId == ver_dep.addonId && i->pack.provider == providerName;
|
||||
});
|
||||
dep == m_selected.end()) { // check the selected versions
|
||||
@ -90,7 +89,15 @@ QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion
|
||||
return i->project_id == ver_dep.addonId && i->provider == providerName;
|
||||
});
|
||||
dep == m_mods.end()) { // check the existing mods
|
||||
c_dependencies.append(ver_dep);
|
||||
if (auto dep = std::find_if(m_pack_dependencies.begin(), m_pack_dependencies.end(),
|
||||
[&ver_dep, providerName](std::shared_ptr<PackDependency> i) {
|
||||
return i->pack.addonId == ver_dep.addonId && i->pack.provider == providerName;
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,11 +108,13 @@ 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<PackDependecny>();
|
||||
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;
|
||||
|
||||
@ -136,7 +145,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, this](auto& doc, auto& pack) {
|
||||
callbacks.on_succeed = [dep, provider, pDep, level, required_by, this](auto& doc, auto& pack) {
|
||||
try {
|
||||
QJsonArray arr;
|
||||
if (dep.version.length() != 0 && doc.isObject()) {
|
||||
@ -144,6 +153,7 @@ 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 ";
|
||||
@ -151,8 +161,10 @@ 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;
|
||||
|
||||
} catch (const JSONValidationError& e) {
|
||||
qDebug() << doc;
|
||||
qWarning() << "Error while reading mod version: " << e.cause();
|
||||
@ -163,7 +175,7 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen
|
||||
return;
|
||||
}
|
||||
for (auto dep : getDependenciesForVersion(pDep->version, provider.name)) {
|
||||
addTask(prepareDependencyTask(dep, provider.name, level - 1));
|
||||
addTask(prepareDependencyTask(dep, provider.name, pDep->pack.addonId, level - 1));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -38,12 +38,12 @@ class GetModDependenciesTask : public SequentialTask {
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<GetModDependenciesTask>;
|
||||
|
||||
struct PackDependecny {
|
||||
struct PackDependency {
|
||||
ModPlatform::Dependency dependency;
|
||||
ModPlatform::IndexedPack pack;
|
||||
ModPlatform::IndexedVersion version;
|
||||
PackDependecny(){};
|
||||
PackDependecny(const ModPlatform::IndexedPack& p, const ModPlatform::IndexedVersion& v)
|
||||
PackDependency(){};
|
||||
PackDependency(const ModPlatform::IndexedPack& p, const ModPlatform::IndexedVersion& v)
|
||||
{
|
||||
pack = p;
|
||||
version = v;
|
||||
@ -59,20 +59,20 @@ class GetModDependenciesTask : public SequentialTask {
|
||||
explicit GetModDependenciesTask(QObject* parent,
|
||||
BaseInstance* instance,
|
||||
ModFolderModel* folder,
|
||||
QList<std::shared_ptr<PackDependecny>> selected);
|
||||
QList<std::shared_ptr<PackDependency>> selected);
|
||||
|
||||
auto getDependecies() const -> QList<std::shared_ptr<PackDependecny>> { return m_pack_dependencies; }
|
||||
auto getDependecies() const -> QList<std::shared_ptr<PackDependency>> { return m_pack_dependencies; }
|
||||
|
||||
protected slots:
|
||||
Task::Ptr prepareDependencyTask(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider, int);
|
||||
Task::Ptr prepareDependencyTask(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider, QVariant, int);
|
||||
QList<ModPlatform::Dependency> getDependenciesForVersion(const ModPlatform::IndexedVersion&,
|
||||
const ModPlatform::ResourceProvider providerName);
|
||||
void prepare();
|
||||
|
||||
private:
|
||||
QList<std::shared_ptr<PackDependecny>> m_pack_dependencies;
|
||||
QList<std::shared_ptr<PackDependency>> m_pack_dependencies;
|
||||
QList<std::shared_ptr<Metadata::ModStruct>> m_mods;
|
||||
QList<std::shared_ptr<PackDependecny>> m_selected;
|
||||
QList<std::shared_ptr<PackDependency>> m_selected;
|
||||
Provider m_flame_provider;
|
||||
Provider m_modrinth_provider;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
|
@ -1,7 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -78,6 +79,7 @@ struct IndexedVersion {
|
||||
// For internal use, not provided by APIs
|
||||
bool is_currently_selected = false;
|
||||
QString custom_target_folder;
|
||||
QList<QVariant> required_by;
|
||||
};
|
||||
|
||||
struct ExtraPackData {
|
||||
|
@ -126,6 +126,22 @@ void ResourceDownloadDialog::connectButtons()
|
||||
|
||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
||||
|
||||
QStringList ResourceDownloadDialog::getReqiredBy(QList<QVariant> req_by)
|
||||
{
|
||||
auto req = QStringList();
|
||||
auto keys = m_selected.keys();
|
||||
for (auto r : req_by) {
|
||||
for (auto& task : keys) {
|
||||
auto selected = m_selected.constFind(task).value()->getPack();
|
||||
if (selected.addonId == r) {
|
||||
req.append(selected.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
||||
void ResourceDownloadDialog::confirm()
|
||||
{
|
||||
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
|
||||
@ -162,8 +178,9 @@ void ResourceDownloadDialog::confirm()
|
||||
keys.sort(Qt::CaseInsensitive);
|
||||
for (auto& task : keys) {
|
||||
auto selected = m_selected.constFind(task).value();
|
||||
auto required_by = getReqiredBy(selected->getVersion().required_by);
|
||||
confirm_dialog->appendResource(
|
||||
{ task, selected->getFilename(), selected->getCustomPath(), ProviderCaps.name(selected->getProvider()) });
|
||||
{ task, selected->getFilename(), selected->getCustomPath(), ProviderCaps.name(selected->getProvider()), required_by });
|
||||
}
|
||||
|
||||
if (confirm_dialog->exec()) {
|
||||
@ -261,10 +278,10 @@ GetModDependenciesTask::Ptr ModDownloadDialog::getModDependenciesTask()
|
||||
{
|
||||
if (auto model = dynamic_cast<ModFolderModel*>(getBaseModel().get()); model) {
|
||||
auto keys = m_selected.keys();
|
||||
QList<std::shared_ptr<GetModDependenciesTask::PackDependecny>> selectedVers;
|
||||
QList<std::shared_ptr<GetModDependenciesTask::PackDependency>> selectedVers;
|
||||
for (auto& task : keys) {
|
||||
auto selected = m_selected.constFind(task).value();
|
||||
selectedVers.append(std::make_shared<GetModDependenciesTask::PackDependecny>(selected->getPack(), selected->getVersion()));
|
||||
selectedVers.append(std::make_shared<GetModDependenciesTask::PackDependency>(selected->getPack(), selected->getVersion()));
|
||||
}
|
||||
|
||||
return makeShared<GetModDependenciesTask>(this, m_instance, model, selectedVers);
|
||||
|
@ -83,6 +83,8 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
|
||||
|
||||
[[nodiscard]] virtual GetModDependenciesTask::Ptr getModDependenciesTask() { return nullptr; }
|
||||
|
||||
QStringList getReqiredBy(QList<QVariant> req_by);
|
||||
|
||||
protected:
|
||||
const std::shared_ptr<ResourceFolderModel> m_base_model;
|
||||
|
||||
|
@ -60,6 +60,18 @@ void ReviewMessageBox::appendResource(ResourceInformation&& info)
|
||||
|
||||
itemTop->insertChildren(childIndx++, { providerItem });
|
||||
|
||||
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));
|
||||
|
||||
itemTop->insertChildren(childIndx++, { requiredByItem });
|
||||
}
|
||||
|
||||
ui->modTreeWidget->addTopLevelItem(itemTop);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ class ReviewMessageBox : public QDialog {
|
||||
QString filename;
|
||||
QString custom_file_path{};
|
||||
QString provider;
|
||||
QStringList required_by;
|
||||
};
|
||||
|
||||
void appendResource(ResourceInformation&& info);
|
||||
|
Loading…
Reference in New Issue
Block a user