2022-06-04 20:22:46 +01:00
|
|
|
#include "ModUpdateDialog.h"
|
|
|
|
#include "ChooseProviderDialog.h"
|
|
|
|
#include "CustomMessageBox.h"
|
|
|
|
#include "ProgressDialog.h"
|
|
|
|
#include "ScrollMessageBox.h"
|
|
|
|
#include "ui_ReviewMessageBox.h"
|
|
|
|
|
2023-01-06 20:26:26 +00:00
|
|
|
#include "Markdown.h"
|
2022-06-04 20:22:46 +01:00
|
|
|
|
2022-07-01 20:17:05 +01:00
|
|
|
#include "tasks/ConcurrentTask.h"
|
|
|
|
|
2022-06-04 20:22:46 +01:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
|
|
|
|
|
|
|
#include "modplatform/EnsureMetadataTask.h"
|
|
|
|
#include "modplatform/flame/FlameCheckUpdate.h"
|
|
|
|
#include "modplatform/modrinth/ModrinthCheckUpdate.h"
|
|
|
|
|
2022-06-20 17:01:49 +01:00
|
|
|
#include <QTextBrowser>
|
2022-06-04 20:22:46 +01:00
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2022-06-04 20:22:46 +01:00
|
|
|
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
|
|
|
|
|
|
static std::list<Version> mcVersions(BaseInstance* inst)
|
|
|
|
{
|
|
|
|
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getComponent("net.minecraft")->getVersion() };
|
|
|
|
}
|
|
|
|
|
2023-08-23 08:26:57 +01:00
|
|
|
static std::optional<ModPlatform::ModLoaderTypes> mcLoaders(BaseInstance* inst)
|
2022-06-04 20:22:46 +01:00
|
|
|
{
|
2023-08-23 10:52:51 +01:00
|
|
|
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getSupportedModLoaders() };
|
2022-06-04 20:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ModUpdateDialog::ModUpdateDialog(QWidget* parent,
|
|
|
|
BaseInstance* instance,
|
2022-06-16 15:45:29 +01:00
|
|
|
const std::shared_ptr<ModFolderModel> mods,
|
2022-08-11 22:24:26 +01:00
|
|
|
QList<Mod*>& search_for)
|
2022-06-04 20:22:46 +01:00
|
|
|
: ReviewMessageBox(parent, tr("Confirm mods to update"), "")
|
|
|
|
, m_parent(parent)
|
|
|
|
, m_mod_model(mods)
|
|
|
|
, m_candidates(search_for)
|
2022-07-01 20:17:05 +01:00
|
|
|
, m_second_try_metadata(new ConcurrentTask())
|
2022-06-04 20:22:46 +01:00
|
|
|
, m_instance(instance)
|
|
|
|
{
|
|
|
|
ReviewMessageBox::setGeometry(0, 0, 800, 600);
|
|
|
|
|
|
|
|
ui->explainLabel->setText(tr("You're about to update the following mods:"));
|
|
|
|
ui->onlyCheckedLabel->setText(tr("Only mods with a check will be updated!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModUpdateDialog::checkCandidates()
|
|
|
|
{
|
|
|
|
// Ensure mods have valid metadata
|
|
|
|
auto went_well = ensureMetadata();
|
|
|
|
if (!went_well) {
|
|
|
|
m_aborted = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report failed metadata generation
|
|
|
|
if (!m_failed_metadata.empty()) {
|
|
|
|
QString text;
|
2022-06-20 12:55:35 +01:00
|
|
|
for (const auto& failed : m_failed_metadata) {
|
|
|
|
const auto& mod = std::get<0>(failed);
|
|
|
|
const auto& reason = std::get<1>(failed);
|
2022-06-26 18:17:15 +01:00
|
|
|
text += tr("Mod name: %1<br>File name: %2<br>Reason: %3<br><br>").arg(mod->name(), mod->fileinfo().fileName(), reason);
|
2022-06-04 20:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScrollMessageBox message_dialog(m_parent, tr("Metadata generation failed"),
|
2022-06-20 17:01:49 +01:00
|
|
|
tr("Could not generate metadata for the following mods:<br>"
|
|
|
|
"Do you wish to proceed without those mods?"),
|
|
|
|
text);
|
2022-06-04 20:22:46 +01:00
|
|
|
message_dialog.setModal(true);
|
|
|
|
if (message_dialog.exec() == QDialog::Rejected) {
|
|
|
|
m_aborted = true;
|
|
|
|
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto versions = mcVersions(m_instance);
|
|
|
|
auto loaders = mcLoaders(m_instance);
|
|
|
|
|
2022-06-20 17:01:49 +01:00
|
|
|
SequentialTask check_task(m_parent, tr("Checking for updates"));
|
2022-06-16 15:45:29 +01:00
|
|
|
|
2022-06-04 20:22:46 +01:00
|
|
|
if (!m_modrinth_to_update.empty()) {
|
2023-01-24 19:52:09 +00:00
|
|
|
m_modrinth_check_task.reset(new ModrinthCheckUpdate(m_modrinth_to_update, versions, loaders, m_mod_model));
|
2023-08-02 17:35:35 +01:00
|
|
|
connect(m_modrinth_check_task.get(), &CheckUpdateTask::checkFailed, this, [this](Mod* mod, QString reason, QUrl recover_url) {
|
|
|
|
m_failed_check_update.append({ mod, reason, recover_url });
|
|
|
|
});
|
2022-06-16 15:45:29 +01:00
|
|
|
check_task.addTask(m_modrinth_check_task);
|
2022-06-04 20:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_flame_to_update.empty()) {
|
2023-01-24 19:52:09 +00:00
|
|
|
m_flame_check_task.reset(new FlameCheckUpdate(m_flame_to_update, versions, loaders, m_mod_model));
|
2023-08-02 17:35:35 +01:00
|
|
|
connect(m_flame_check_task.get(), &CheckUpdateTask::checkFailed, this, [this](Mod* mod, QString reason, QUrl recover_url) {
|
|
|
|
m_failed_check_update.append({ mod, reason, recover_url });
|
|
|
|
});
|
2022-06-16 15:45:29 +01:00
|
|
|
check_task.addTask(m_flame_check_task);
|
2022-06-04 20:22:46 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 15:45:29 +01:00
|
|
|
connect(&check_task, &Task::failed, this,
|
|
|
|
[&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
|
|
|
|
|
|
|
|
connect(&check_task, &Task::succeeded, this, [&]() {
|
|
|
|
QStringList warnings = check_task.warnings();
|
|
|
|
if (warnings.count()) {
|
|
|
|
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-04 20:22:46 +01:00
|
|
|
// Check for updates
|
|
|
|
ProgressDialog progress_dialog(m_parent);
|
|
|
|
progress_dialog.setSkipButton(true, tr("Abort"));
|
|
|
|
progress_dialog.setWindowTitle(tr("Checking for updates..."));
|
2022-06-16 15:45:29 +01:00
|
|
|
auto ret = progress_dialog.execWithTask(&check_task);
|
2022-06-04 20:22:46 +01:00
|
|
|
|
|
|
|
// If the dialog was skipped / some download error happened
|
|
|
|
if (ret == QDialog::DialogCode::Rejected) {
|
|
|
|
m_aborted = true;
|
|
|
|
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add found updates for Modrinth
|
|
|
|
if (m_modrinth_check_task) {
|
|
|
|
auto modrinth_updates = m_modrinth_check_task->getUpdatable();
|
|
|
|
for (auto& updatable : modrinth_updates) {
|
|
|
|
qDebug() << QString("Mod %1 has an update available!").arg(updatable.name);
|
|
|
|
|
|
|
|
appendMod(updatable);
|
|
|
|
m_tasks.insert(updatable.name, updatable.download);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add found updated for Flame
|
|
|
|
if (m_flame_check_task) {
|
|
|
|
auto flame_updates = m_flame_check_task->getUpdatable();
|
|
|
|
for (auto& updatable : flame_updates) {
|
|
|
|
qDebug() << QString("Mod %1 has an update available!").arg(updatable.name);
|
|
|
|
|
|
|
|
appendMod(updatable);
|
|
|
|
m_tasks.insert(updatable.name, updatable.download);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report failed update checking
|
|
|
|
if (!m_failed_check_update.empty()) {
|
|
|
|
QString text;
|
|
|
|
for (const auto& failed : m_failed_check_update) {
|
|
|
|
const auto& mod = std::get<0>(failed);
|
|
|
|
const auto& reason = std::get<1>(failed);
|
|
|
|
const auto& recover_url = std::get<2>(failed);
|
|
|
|
|
2022-06-26 18:17:15 +01:00
|
|
|
qDebug() << mod->name() << " failed to check for updates!";
|
2022-06-04 20:22:46 +01:00
|
|
|
|
2022-06-26 18:17:15 +01:00
|
|
|
text += tr("Mod name: %1").arg(mod->name()) + "<br>";
|
2022-06-04 20:22:46 +01:00
|
|
|
if (!reason.isEmpty())
|
|
|
|
text += tr("Reason: %1").arg(reason) + "<br>";
|
|
|
|
if (!recover_url.isEmpty())
|
2022-07-20 09:14:51 +01:00
|
|
|
//: %1 is the link to download it manually
|
|
|
|
text += tr("Possible solution: Getting the latest version manually:<br>%1<br>")
|
2023-08-02 17:35:35 +01:00
|
|
|
.arg(QString("<a href='%1'>%1</a>").arg(recover_url.toString()));
|
2022-06-04 20:22:46 +01:00
|
|
|
text += "<br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollMessageBox message_dialog(m_parent, tr("Failed to check for updates"),
|
2022-06-20 17:01:49 +01:00
|
|
|
tr("Could not check or get the following mods for updates:<br>"
|
|
|
|
"Do you wish to proceed without those mods?"),
|
|
|
|
text);
|
2022-06-04 20:22:46 +01:00
|
|
|
message_dialog.setModal(true);
|
|
|
|
if (message_dialog.exec() == QDialog::Rejected) {
|
|
|
|
m_aborted = true;
|
|
|
|
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no mod to be updated
|
2022-06-20 17:01:49 +01:00
|
|
|
if (ui->modTreeWidget->topLevelItemCount() == 0) {
|
2022-06-04 20:22:46 +01:00
|
|
|
m_no_updates = true;
|
2022-06-20 17:01:49 +01:00
|
|
|
} else {
|
|
|
|
// FIXME: Find a more efficient way of doing this!
|
|
|
|
|
|
|
|
// Sort major items in alphabetical order (also sorts the children unfortunately)
|
|
|
|
ui->modTreeWidget->sortItems(0, Qt::SortOrder::AscendingOrder);
|
|
|
|
|
|
|
|
// Re-sort the children
|
|
|
|
auto* item = ui->modTreeWidget->topLevelItem(0);
|
|
|
|
for (int i = 1; item != nullptr; ++i) {
|
|
|
|
item->sortChildren(0, Qt::SortOrder::DescendingOrder);
|
|
|
|
item = ui->modTreeWidget->topLevelItem(i);
|
|
|
|
}
|
|
|
|
}
|
2022-06-04 20:22:46 +01:00
|
|
|
|
|
|
|
if (m_aborted || m_no_updates)
|
|
|
|
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Part 1: Ensure we have a valid metadata
|
|
|
|
auto ModUpdateDialog::ensureMetadata() -> bool
|
|
|
|
{
|
|
|
|
auto index_dir = indexDir();
|
|
|
|
|
2022-06-16 15:45:29 +01:00
|
|
|
SequentialTask seq(m_parent, tr("Looking for metadata"));
|
|
|
|
|
|
|
|
// A better use of data structures here could remove the need for this QHash
|
|
|
|
QHash<QString, bool> should_try_others;
|
2022-07-10 19:15:25 +01:00
|
|
|
QList<Mod*> modrinth_tmp;
|
|
|
|
QList<Mod*> flame_tmp;
|
2022-06-04 20:22:46 +01:00
|
|
|
|
|
|
|
bool confirm_rest = false;
|
|
|
|
bool try_others_rest = false;
|
|
|
|
bool skip_rest = false;
|
2022-11-25 12:23:46 +00:00
|
|
|
ModPlatform::ResourceProvider provider_rest = ModPlatform::ResourceProvider::MODRINTH;
|
2022-06-04 20:22:46 +01:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
auto addToTmp = [&](Mod* m, ModPlatform::ResourceProvider p) {
|
2022-06-16 15:45:29 +01:00
|
|
|
switch (p) {
|
2022-11-25 12:23:46 +00:00
|
|
|
case ModPlatform::ResourceProvider::MODRINTH:
|
2022-06-16 15:45:29 +01:00
|
|
|
modrinth_tmp.push_back(m);
|
|
|
|
break;
|
2022-11-25 12:23:46 +00:00
|
|
|
case ModPlatform::ResourceProvider::FLAME:
|
2022-06-16 15:45:29 +01:00
|
|
|
flame_tmp.push_back(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-26 18:17:15 +01:00
|
|
|
for (auto candidate : m_candidates) {
|
|
|
|
if (candidate->status() != ModStatus::NoMetadata) {
|
2022-08-11 22:24:26 +01:00
|
|
|
onMetadataEnsured(candidate);
|
2022-06-04 20:22:46 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip_rest)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (confirm_rest) {
|
2022-08-11 22:24:26 +01:00
|
|
|
addToTmp(candidate, provider_rest);
|
2022-06-26 18:17:15 +01:00
|
|
|
should_try_others.insert(candidate->internal_id(), try_others_rest);
|
2022-06-04 20:22:46 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChooseProviderDialog chooser(this);
|
2022-07-19 17:03:45 +01:00
|
|
|
chooser.setDescription(tr("The mod '%1' does not have a metadata yet. We need to generate it in order to track relevant "
|
|
|
|
"information on how to update this mod. "
|
|
|
|
"To do this, please select a mod provider which we can use to check for updates for this mod.")
|
2022-06-26 18:17:15 +01:00
|
|
|
.arg(candidate->name()));
|
2022-06-04 20:22:46 +01:00
|
|
|
auto confirmed = chooser.exec() == QDialog::DialogCode::Accepted;
|
|
|
|
|
|
|
|
auto response = chooser.getResponse();
|
|
|
|
|
|
|
|
if (response.skip_all)
|
|
|
|
skip_rest = true;
|
|
|
|
if (response.confirm_all) {
|
|
|
|
confirm_rest = true;
|
|
|
|
provider_rest = response.chosen;
|
|
|
|
try_others_rest = response.try_others;
|
|
|
|
}
|
|
|
|
|
2022-06-26 18:17:15 +01:00
|
|
|
should_try_others.insert(candidate->internal_id(), response.try_others);
|
2022-06-16 15:45:29 +01:00
|
|
|
|
|
|
|
if (confirmed)
|
2022-08-11 22:24:26 +01:00
|
|
|
addToTmp(candidate, response.chosen);
|
2022-06-04 20:22:46 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 15:45:29 +01:00
|
|
|
if (!modrinth_tmp.empty()) {
|
2023-01-24 19:52:09 +00:00
|
|
|
auto modrinth_task = makeShared<EnsureMetadataTask>(modrinth_tmp, index_dir, ModPlatform::ResourceProvider::MODRINTH);
|
|
|
|
connect(modrinth_task.get(), &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
|
|
|
|
connect(modrinth_task.get(), &EnsureMetadataTask::metadataFailed, [this, &should_try_others](Mod* candidate) {
|
2022-11-25 12:23:46 +00:00
|
|
|
onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::ResourceProvider::MODRINTH);
|
2022-06-16 15:45:29 +01:00
|
|
|
});
|
2022-07-24 19:14:31 +01:00
|
|
|
|
|
|
|
if (modrinth_task->getHashingTask())
|
|
|
|
seq.addTask(modrinth_task->getHashingTask());
|
|
|
|
|
2022-06-16 15:45:29 +01:00
|
|
|
seq.addTask(modrinth_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flame_tmp.empty()) {
|
2023-01-24 19:52:09 +00:00
|
|
|
auto flame_task = makeShared<EnsureMetadataTask>(flame_tmp, index_dir, ModPlatform::ResourceProvider::FLAME);
|
|
|
|
connect(flame_task.get(), &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
|
|
|
|
connect(flame_task.get(), &EnsureMetadataTask::metadataFailed, [this, &should_try_others](Mod* candidate) {
|
2022-11-25 12:23:46 +00:00
|
|
|
onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::ResourceProvider::FLAME);
|
2022-06-16 15:45:29 +01:00
|
|
|
});
|
2022-07-24 19:14:31 +01:00
|
|
|
|
|
|
|
if (flame_task->getHashingTask())
|
|
|
|
seq.addTask(flame_task->getHashingTask());
|
|
|
|
|
2022-06-16 15:45:29 +01:00
|
|
|
seq.addTask(flame_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
seq.addTask(m_second_try_metadata);
|
|
|
|
|
2022-06-04 20:22:46 +01:00
|
|
|
ProgressDialog checking_dialog(m_parent);
|
|
|
|
checking_dialog.setSkipButton(true, tr("Abort"));
|
|
|
|
checking_dialog.setWindowTitle(tr("Generating metadata..."));
|
2022-06-16 15:45:29 +01:00
|
|
|
auto ret_metadata = checking_dialog.execWithTask(&seq);
|
2022-06-04 20:22:46 +01:00
|
|
|
|
|
|
|
return (ret_metadata != QDialog::DialogCode::Rejected);
|
|
|
|
}
|
|
|
|
|
2022-06-26 18:17:15 +01:00
|
|
|
void ModUpdateDialog::onMetadataEnsured(Mod* mod)
|
2022-06-04 20:22:46 +01:00
|
|
|
{
|
|
|
|
// When the mod is a folder, for instance
|
2022-06-26 18:17:15 +01:00
|
|
|
if (!mod->metadata())
|
2022-06-04 20:22:46 +01:00
|
|
|
return;
|
|
|
|
|
2022-06-26 18:17:15 +01:00
|
|
|
switch (mod->metadata()->provider) {
|
2022-11-25 12:23:46 +00:00
|
|
|
case ModPlatform::ResourceProvider::MODRINTH:
|
2022-06-04 20:22:46 +01:00
|
|
|
m_modrinth_to_update.push_back(mod);
|
|
|
|
break;
|
2022-11-25 12:23:46 +00:00
|
|
|
case ModPlatform::ResourceProvider::FLAME:
|
2022-06-04 20:22:46 +01:00
|
|
|
m_flame_to_update.push_back(mod);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
ModPlatform::ResourceProvider next(ModPlatform::ResourceProvider p)
|
2022-06-04 20:22:46 +01:00
|
|
|
{
|
2022-06-16 15:45:29 +01:00
|
|
|
switch (p) {
|
2022-11-25 12:23:46 +00:00
|
|
|
case ModPlatform::ResourceProvider::MODRINTH:
|
|
|
|
return ModPlatform::ResourceProvider::FLAME;
|
|
|
|
case ModPlatform::ResourceProvider::FLAME:
|
|
|
|
return ModPlatform::ResourceProvider::MODRINTH;
|
2022-06-16 15:45:29 +01:00
|
|
|
}
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
return ModPlatform::ResourceProvider::FLAME;
|
2022-06-16 15:45:29 +01:00
|
|
|
}
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
void ModUpdateDialog::onMetadataFailed(Mod* mod, bool try_others, ModPlatform::ResourceProvider first_choice)
|
2022-06-16 15:45:29 +01:00
|
|
|
{
|
|
|
|
if (try_others) {
|
|
|
|
auto index_dir = indexDir();
|
|
|
|
|
2023-01-24 19:52:09 +00:00
|
|
|
auto task = makeShared<EnsureMetadataTask>(mod, index_dir, next(first_choice));
|
|
|
|
connect(task.get(), &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); });
|
|
|
|
connect(task.get(), &EnsureMetadataTask::metadataFailed, [this](Mod* candidate) { onMetadataFailed(candidate, false); });
|
2022-06-16 15:45:29 +01:00
|
|
|
|
|
|
|
m_second_try_metadata->addTask(task);
|
|
|
|
} else {
|
2022-07-19 17:03:45 +01:00
|
|
|
QString reason{ tr("Couldn't find a valid version on the selected mod provider(s)") };
|
2022-06-20 12:55:35 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
m_failed_metadata.append({ mod, reason });
|
2022-06-16 15:45:29 +01:00
|
|
|
}
|
2022-06-04 20:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info)
|
|
|
|
{
|
|
|
|
auto item_top = new QTreeWidgetItem(ui->modTreeWidget);
|
|
|
|
item_top->setCheckState(0, Qt::CheckState::Checked);
|
|
|
|
item_top->setText(0, info.name);
|
|
|
|
item_top->setExpanded(true);
|
|
|
|
|
|
|
|
auto provider_item = new QTreeWidgetItem(item_top);
|
|
|
|
provider_item->setText(0, tr("Provider: %1").arg(ProviderCaps.readableName(info.provider)));
|
|
|
|
|
|
|
|
auto old_version_item = new QTreeWidgetItem(item_top);
|
|
|
|
old_version_item->setText(0, tr("Old version: %1").arg(info.old_version.isEmpty() ? tr("Not installed") : info.old_version));
|
|
|
|
|
|
|
|
auto new_version_item = new QTreeWidgetItem(item_top);
|
|
|
|
new_version_item->setText(0, tr("New version: %1").arg(info.new_version));
|
|
|
|
|
|
|
|
auto changelog_item = new QTreeWidgetItem(item_top);
|
|
|
|
changelog_item->setText(0, tr("Changelog of the latest version"));
|
|
|
|
|
|
|
|
auto changelog = new QTreeWidgetItem(changelog_item);
|
2022-06-20 17:01:49 +01:00
|
|
|
auto changelog_area = new QTextBrowser();
|
2022-06-04 20:22:46 +01:00
|
|
|
|
2022-10-21 18:07:43 +01:00
|
|
|
QString text = info.changelog;
|
2022-06-20 17:01:49 +01:00
|
|
|
switch (info.provider) {
|
2022-11-25 12:23:46 +00:00
|
|
|
case ModPlatform::ResourceProvider::MODRINTH: {
|
2023-01-06 20:26:26 +00:00
|
|
|
text = markdownToHTML(info.changelog.toUtf8());
|
2022-06-20 17:01:49 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-10-21 18:07:43 +01:00
|
|
|
default:
|
2022-06-20 17:01:49 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-06-04 20:22:46 +01:00
|
|
|
|
2022-10-21 18:07:43 +01:00
|
|
|
changelog_area->setHtml(text);
|
2022-06-20 17:01:49 +01:00
|
|
|
changelog_area->setOpenExternalLinks(true);
|
2022-10-21 18:07:43 +01:00
|
|
|
changelog_area->setLineWrapMode(QTextBrowser::LineWrapMode::WidgetWidth);
|
2022-07-01 15:54:32 +01:00
|
|
|
changelog_area->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
|
|
|
|
|
2022-06-20 17:01:49 +01:00
|
|
|
ui->modTreeWidget->setItemWidget(changelog, 0, changelog_area);
|
2022-06-04 20:22:46 +01:00
|
|
|
|
|
|
|
ui->modTreeWidget->addTopLevelItem(item_top);
|
|
|
|
}
|
|
|
|
|
2023-01-24 19:52:09 +00:00
|
|
|
auto ModUpdateDialog::getTasks() -> const QList<ResourceDownloadTask::Ptr>
|
2022-06-04 20:22:46 +01:00
|
|
|
{
|
2023-01-24 19:52:09 +00:00
|
|
|
QList<ResourceDownloadTask::Ptr> list;
|
2022-06-04 20:22:46 +01:00
|
|
|
|
|
|
|
auto* item = ui->modTreeWidget->topLevelItem(0);
|
|
|
|
|
2022-06-10 20:40:39 +01:00
|
|
|
for (int i = 1; item != nullptr; ++i) {
|
2022-06-04 20:22:46 +01:00
|
|
|
if (item->checkState(0) == Qt::CheckState::Checked) {
|
|
|
|
list.push_back(m_tasks.find(item->text(0)).value());
|
|
|
|
}
|
|
|
|
|
|
|
|
item = ui->modTreeWidget->topLevelItem(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|