Merge pull request #1263 from Trial97/develop
This commit is contained in:
commit
531b58093e
@ -251,3 +251,32 @@ void GetModDependenciesTask::removePack(const QVariant addonId)
|
|||||||
++it;
|
++it;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<QString, QStringList> GetModDependenciesTask::getRequiredBy()
|
||||||
|
{
|
||||||
|
QHash<QString, QStringList> rby;
|
||||||
|
auto fullList = m_selected + m_pack_dependencies;
|
||||||
|
for (auto& mod : fullList) {
|
||||||
|
auto addonId = mod->pack->addonId;
|
||||||
|
auto provider = mod->pack->provider;
|
||||||
|
auto version = mod->version.fileId;
|
||||||
|
auto req = QStringList();
|
||||||
|
for (auto& smod : fullList) {
|
||||||
|
if (provider != smod->pack->provider)
|
||||||
|
continue;
|
||||||
|
auto deps = smod->version.dependencies;
|
||||||
|
if (auto dep = std::find_if(deps.begin(), deps.end(),
|
||||||
|
[addonId, provider, version](const ModPlatform::Dependency& d) {
|
||||||
|
return d.type == ModPlatform::DependencyType::REQUIRED &&
|
||||||
|
(provider == ModPlatform::ResourceProvider::MODRINTH && d.addonId.toString().isEmpty()
|
||||||
|
? version == d.version
|
||||||
|
: d.addonId == addonId);
|
||||||
|
});
|
||||||
|
dep != deps.end()) {
|
||||||
|
req.append(smod->pack->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rby[addonId.toString()] = req;
|
||||||
|
}
|
||||||
|
return rby;
|
||||||
|
}
|
@ -62,6 +62,7 @@ class GetModDependenciesTask : public SequentialTask {
|
|||||||
QList<std::shared_ptr<PackDependency>> selected);
|
QList<std::shared_ptr<PackDependency>> selected);
|
||||||
|
|
||||||
auto getDependecies() const -> QList<std::shared_ptr<PackDependency>> { return m_pack_dependencies; }
|
auto getDependecies() const -> QList<std::shared_ptr<PackDependency>> { return m_pack_dependencies; }
|
||||||
|
QHash<QString, QStringList> getRequiredBy();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
Task::Ptr prepareDependencyTask(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider, int);
|
Task::Ptr prepareDependencyTask(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider, int);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "minecraft/mod/Mod.h"
|
#include "minecraft/mod/Mod.h"
|
||||||
|
#include "minecraft/mod/tasks/GetModDependenciesTask.h"
|
||||||
#include "modplatform/ModIndex.h"
|
#include "modplatform/ModIndex.h"
|
||||||
#include "modplatform/ResourceAPI.h"
|
#include "modplatform/ResourceAPI.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
@ -40,6 +41,7 @@ class CheckUpdateTask : public Task {
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto getUpdatable() -> std::vector<UpdatableMod>&& { return std::move(m_updatable); }
|
auto getUpdatable() -> std::vector<UpdatableMod>&& { return std::move(m_updatable); }
|
||||||
|
auto getDependencies() -> QList<std::shared_ptr<GetModDependenciesTask::PackDependency>>&& { return std::move(m_deps); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool abort() override = 0;
|
bool abort() override = 0;
|
||||||
@ -57,4 +59,5 @@ class CheckUpdateTask : public Task {
|
|||||||
std::shared_ptr<ModFolderModel> m_mods_folder;
|
std::shared_ptr<ModFolderModel> m_mods_folder;
|
||||||
|
|
||||||
std::vector<UpdatableMod> m_updatable;
|
std::vector<UpdatableMod> m_updatable;
|
||||||
|
QList<std::shared_ptr<GetModDependenciesTask::PackDependency>> m_deps;
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "ResourceDownloadTask.h"
|
#include "ResourceDownloadTask.h"
|
||||||
|
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
#include "minecraft/mod/tasks/GetModDependenciesTask.h"
|
||||||
|
|
||||||
#include "net/ApiDownload.h"
|
#include "net/ApiDownload.h"
|
||||||
|
|
||||||
@ -154,7 +155,6 @@ void FlameCheckUpdate::executeTask()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!latest_ver.hash.isEmpty() && (mod->metadata()->hash != latest_ver.hash || mod->status() == ModStatus::NotInstalled)) {
|
|
||||||
// Fake pack with the necessary info to pass to the download task :)
|
// Fake pack with the necessary info to pass to the download task :)
|
||||||
auto pack = std::make_shared<ModPlatform::IndexedPack>();
|
auto pack = std::make_shared<ModPlatform::IndexedPack>();
|
||||||
pack->name = mod->name();
|
pack->name = mod->name();
|
||||||
@ -165,7 +165,7 @@ void FlameCheckUpdate::executeTask()
|
|||||||
pack->authors.append({ author });
|
pack->authors.append({ author });
|
||||||
pack->description = mod->description();
|
pack->description = mod->description();
|
||||||
pack->provider = ModPlatform::ResourceProvider::FLAME;
|
pack->provider = ModPlatform::ResourceProvider::FLAME;
|
||||||
|
if (!latest_ver.hash.isEmpty() && (mod->metadata()->hash != latest_ver.hash || mod->status() == ModStatus::NotInstalled)) {
|
||||||
auto old_version = mod->version();
|
auto old_version = mod->version();
|
||||||
if (old_version.isEmpty() && mod->status() != ModStatus::NotInstalled) {
|
if (old_version.isEmpty() && mod->status() != ModStatus::NotInstalled) {
|
||||||
auto current_ver = getFileInfo(latest_ver.addonId.toInt(), mod->metadata()->file_id.toInt());
|
auto current_ver = getFileInfo(latest_ver.addonId.toInt(), mod->metadata()->file_id.toInt());
|
||||||
@ -177,6 +177,7 @@ void FlameCheckUpdate::executeTask()
|
|||||||
api.getModFileChangelog(latest_ver.addonId.toInt(), latest_ver.fileId.toInt()),
|
api.getModFileChangelog(latest_ver.addonId.toInt(), latest_ver.fileId.toInt()),
|
||||||
ModPlatform::ResourceProvider::FLAME, download_task);
|
ModPlatform::ResourceProvider::FLAME, download_task);
|
||||||
}
|
}
|
||||||
|
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, latest_ver));
|
||||||
}
|
}
|
||||||
|
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
|
@ -144,9 +144,6 @@ void ModrinthCheckUpdate::executeTask()
|
|||||||
auto mod = *mod_iter;
|
auto mod = *mod_iter;
|
||||||
|
|
||||||
auto key = project_ver.hash;
|
auto key = project_ver.hash;
|
||||||
if ((key != hash && project_ver.is_preferred) || (mod->status() == ModStatus::NotInstalled)) {
|
|
||||||
if (mod->version() == project_ver.version_number)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Fake pack with the necessary info to pass to the download task :)
|
// Fake pack with the necessary info to pass to the download task :)
|
||||||
auto pack = std::make_shared<ModPlatform::IndexedPack>();
|
auto pack = std::make_shared<ModPlatform::IndexedPack>();
|
||||||
@ -158,12 +155,16 @@ void ModrinthCheckUpdate::executeTask()
|
|||||||
pack->authors.append({ author });
|
pack->authors.append({ author });
|
||||||
pack->description = mod->description();
|
pack->description = mod->description();
|
||||||
pack->provider = ModPlatform::ResourceProvider::MODRINTH;
|
pack->provider = ModPlatform::ResourceProvider::MODRINTH;
|
||||||
|
if ((key != hash && project_ver.is_preferred) || (mod->status() == ModStatus::NotInstalled)) {
|
||||||
|
if (mod->version() == project_ver.version_number)
|
||||||
|
continue;
|
||||||
|
|
||||||
auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_mods_folder);
|
auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_mods_folder);
|
||||||
|
|
||||||
m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.changelog,
|
m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.changelog,
|
||||||
ModPlatform::ResourceProvider::MODRINTH, download_task);
|
ModPlatform::ResourceProvider::MODRINTH, download_task);
|
||||||
}
|
}
|
||||||
|
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, project_ver));
|
||||||
}
|
}
|
||||||
} catch (Json::JsonException& e) {
|
} catch (Json::JsonException& e) {
|
||||||
failed(e.cause() + " : " + e.what());
|
failed(e.cause() + " : " + e.what());
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#include "CustomMessageBox.h"
|
#include "CustomMessageBox.h"
|
||||||
#include "ProgressDialog.h"
|
#include "ProgressDialog.h"
|
||||||
#include "ScrollMessageBox.h"
|
#include "ScrollMessageBox.h"
|
||||||
|
#include "minecraft/mod/tasks/GetModDependenciesTask.h"
|
||||||
|
#include "modplatform/ModIndex.h"
|
||||||
|
#include "modplatform/flame/FlameAPI.h"
|
||||||
#include "ui_ReviewMessageBox.h"
|
#include "ui_ReviewMessageBox.h"
|
||||||
|
|
||||||
#include "Markdown.h"
|
#include "Markdown.h"
|
||||||
@ -125,6 +128,8 @@ void ModUpdateDialog::checkCandidates()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<std::shared_ptr<GetModDependenciesTask::PackDependency>> selectedVers;
|
||||||
|
|
||||||
// Add found updates for Modrinth
|
// Add found updates for Modrinth
|
||||||
if (m_modrinth_check_task) {
|
if (m_modrinth_check_task) {
|
||||||
auto modrinth_updates = m_modrinth_check_task->getUpdatable();
|
auto modrinth_updates = m_modrinth_check_task->getUpdatable();
|
||||||
@ -134,6 +139,7 @@ void ModUpdateDialog::checkCandidates()
|
|||||||
appendMod(updatable);
|
appendMod(updatable);
|
||||||
m_tasks.insert(updatable.name, updatable.download);
|
m_tasks.insert(updatable.name, updatable.download);
|
||||||
}
|
}
|
||||||
|
selectedVers.append(m_modrinth_check_task->getDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add found updated for Flame
|
// Add found updated for Flame
|
||||||
@ -145,6 +151,7 @@ void ModUpdateDialog::checkCandidates()
|
|||||||
appendMod(updatable);
|
appendMod(updatable);
|
||||||
m_tasks.insert(updatable.name, updatable.download);
|
m_tasks.insert(updatable.name, updatable.download);
|
||||||
}
|
}
|
||||||
|
selectedVers.append(m_flame_check_task->getDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report failed update checking
|
// Report failed update checking
|
||||||
@ -179,6 +186,47 @@ void ModUpdateDialog::checkCandidates()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{ // dependencies
|
||||||
|
auto depTask = makeShared<GetModDependenciesTask>(this, m_instance, m_mod_model.get(), selectedVers);
|
||||||
|
|
||||||
|
connect(depTask.get(), &Task::failed, this,
|
||||||
|
[&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
|
||||||
|
|
||||||
|
connect(depTask.get(), &Task::succeeded, this, [&]() {
|
||||||
|
QStringList warnings = depTask->warnings();
|
||||||
|
if (warnings.count()) {
|
||||||
|
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ProgressDialog progress_dialog_deps(m_parent);
|
||||||
|
progress_dialog_deps.setSkipButton(true, tr("Abort"));
|
||||||
|
progress_dialog_deps.setWindowTitle(tr("Checking for dependencies..."));
|
||||||
|
auto dret = progress_dialog_deps.execWithTask(depTask.get());
|
||||||
|
|
||||||
|
// If the dialog was skipped / some download error happened
|
||||||
|
if (dret == QDialog::DialogCode::Rejected) {
|
||||||
|
m_aborted = true;
|
||||||
|
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
static FlameAPI api;
|
||||||
|
|
||||||
|
auto getRequiredBy = depTask->getRequiredBy();
|
||||||
|
|
||||||
|
for (auto dep : depTask->getDependecies()) {
|
||||||
|
auto changelog = dep->version.changelog;
|
||||||
|
if (dep->pack->provider == ModPlatform::ResourceProvider::FLAME)
|
||||||
|
changelog = api.getModFileChangelog(dep->version.addonId.toInt(), dep->version.fileId.toInt());
|
||||||
|
auto download_task = makeShared<ResourceDownloadTask>(dep->pack, dep->version, m_mod_model);
|
||||||
|
CheckUpdateTask::UpdatableMod updatable = { dep->pack->name, dep->version.hash, "", dep->version.version,
|
||||||
|
changelog, dep->pack->provider, download_task };
|
||||||
|
|
||||||
|
appendMod(updatable, getRequiredBy.value(dep->version.addonId.toString()));
|
||||||
|
m_tasks.insert(updatable.name, updatable.download);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If there's no mod to be updated
|
// If there's no mod to be updated
|
||||||
if (ui->modTreeWidget->topLevelItemCount() == 0) {
|
if (ui->modTreeWidget->topLevelItemCount() == 0) {
|
||||||
m_no_updates = true;
|
m_no_updates = true;
|
||||||
@ -351,7 +399,7 @@ void ModUpdateDialog::onMetadataFailed(Mod* mod, bool try_others, ModPlatform::R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info)
|
void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info, QStringList requiredBy)
|
||||||
{
|
{
|
||||||
auto item_top = new QTreeWidgetItem(ui->modTreeWidget);
|
auto item_top = new QTreeWidgetItem(ui->modTreeWidget);
|
||||||
item_top->setCheckState(0, Qt::CheckState::Checked);
|
item_top->setCheckState(0, Qt::CheckState::Checked);
|
||||||
@ -367,6 +415,21 @@ void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info)
|
|||||||
auto new_version_item = new QTreeWidgetItem(item_top);
|
auto new_version_item = new QTreeWidgetItem(item_top);
|
||||||
new_version_item->setText(0, tr("New version: %1").arg(info.new_version));
|
new_version_item->setText(0, tr("New version: %1").arg(info.new_version));
|
||||||
|
|
||||||
|
if (!requiredBy.isEmpty()) {
|
||||||
|
auto requiredByItem = new QTreeWidgetItem(item_top);
|
||||||
|
if (requiredBy.length() == 1) {
|
||||||
|
requiredByItem->setText(0, tr("Required by: %1").arg(requiredBy.back()));
|
||||||
|
} else {
|
||||||
|
requiredByItem->setText(0, tr("Required by:"));
|
||||||
|
auto i = 0;
|
||||||
|
for (auto req : requiredBy) {
|
||||||
|
auto reqItem = new QTreeWidgetItem(requiredByItem);
|
||||||
|
reqItem->setText(0, req);
|
||||||
|
reqItem->insertChildren(i++, { reqItem });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto changelog_item = new QTreeWidgetItem(item_top);
|
auto changelog_item = new QTreeWidgetItem(item_top);
|
||||||
changelog_item->setText(0, tr("Changelog of the latest version"));
|
changelog_item->setText(0, tr("Changelog of the latest version"));
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class ModUpdateDialog final : public ReviewMessageBox {
|
|||||||
|
|
||||||
void checkCandidates();
|
void checkCandidates();
|
||||||
|
|
||||||
void appendMod(const CheckUpdateTask::UpdatableMod& info);
|
void appendMod(const CheckUpdateTask::UpdatableMod& info, QStringList requiredBy = {});
|
||||||
|
|
||||||
const QList<ResourceDownloadTask::Ptr> getTasks();
|
const QList<ResourceDownloadTask::Ptr> getTasks();
|
||||||
auto indexDir() const -> QDir { return m_mod_model->indexDir(); }
|
auto indexDir() const -> QDir { return m_mod_model->indexDir(); }
|
||||||
|
@ -127,35 +127,12 @@ void ResourceDownloadDialog::connectButtons()
|
|||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
static ModPlatform::ProviderCapabilities ProviderCaps;
|
||||||
|
|
||||||
QStringList getRequiredBy(QList<ResourceDownloadDialog::DownloadTaskPtr> tasks, ResourceDownloadDialog::DownloadTaskPtr pack)
|
|
||||||
{
|
|
||||||
auto addonId = pack->getPack()->addonId;
|
|
||||||
auto provider = pack->getPack()->provider;
|
|
||||||
auto version = pack->getVersionID();
|
|
||||||
auto req = QStringList();
|
|
||||||
for (auto& task : tasks) {
|
|
||||||
if (provider != task->getPack()->provider)
|
|
||||||
continue;
|
|
||||||
auto deps = task->getVersion().dependencies;
|
|
||||||
if (auto dep = std::find_if(deps.begin(), deps.end(),
|
|
||||||
[addonId, provider, version](const ModPlatform::Dependency& d) {
|
|
||||||
return d.type == ModPlatform::DependencyType::REQUIRED &&
|
|
||||||
(provider == ModPlatform::ResourceProvider::MODRINTH && d.addonId.toString().isEmpty()
|
|
||||||
? version == d.version
|
|
||||||
: d.addonId == addonId);
|
|
||||||
});
|
|
||||||
dep != deps.end()) {
|
|
||||||
req.append(task->getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return req;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResourceDownloadDialog::confirm()
|
void ResourceDownloadDialog::confirm()
|
||||||
{
|
{
|
||||||
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
|
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
|
||||||
confirm_dialog->retranslateUi(resourcesString());
|
confirm_dialog->retranslateUi(resourcesString());
|
||||||
|
|
||||||
|
QHash<QString, QStringList> getRequiredBy;
|
||||||
if (auto task = getModDependenciesTask(); task) {
|
if (auto task = getModDependenciesTask(); task) {
|
||||||
connect(task.get(), &Task::failed, this,
|
connect(task.get(), &Task::failed, this,
|
||||||
[&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
|
[&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
|
||||||
@ -180,6 +157,7 @@ void ResourceDownloadDialog::confirm()
|
|||||||
} else {
|
} else {
|
||||||
for (auto dep : task->getDependecies())
|
for (auto dep : task->getDependecies())
|
||||||
addResource(dep->pack, dep->version);
|
addResource(dep->pack, dep->version);
|
||||||
|
getRequiredBy = task->getRequiredBy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +167,8 @@ void ResourceDownloadDialog::confirm()
|
|||||||
});
|
});
|
||||||
for (auto& task : selected) {
|
for (auto& task : selected) {
|
||||||
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(),
|
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(),
|
||||||
ProviderCaps.name(task->getProvider()), getRequiredBy(selected, task) });
|
ProviderCaps.name(task->getProvider()),
|
||||||
|
getRequiredBy.value(task->getPack()->addonId.toString()) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (confirm_dialog->exec()) {
|
if (confirm_dialog->exec()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user