aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/dialogs/ResourceDownloadDialog.cpp69
-rw-r--r--launcher/ui/dialogs/ResourceDownloadDialog.h15
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.cpp42
-rw-r--r--launcher/ui/pages/modplatform/ResourceModel.h2
-rw-r--r--launcher/ui/pages/modplatform/ResourcePage.cpp5
-rw-r--r--launcher/ui/pages/modplatform/ResourcePage.h2
6 files changed, 57 insertions, 78 deletions
diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.cpp b/launcher/ui/dialogs/ResourceDownloadDialog.cpp
index 610f2449..03466bba 100644
--- a/launcher/ui/dialogs/ResourceDownloadDialog.cpp
+++ b/launcher/ui/dialogs/ResourceDownloadDialog.cpp
@@ -23,8 +23,10 @@
#include <QPushButton>
#include <algorithm>
+#include <memory>
#include "Application.h"
+#include "QObjectPtr.h"
#include "ResourceDownloadTask.h"
#include "minecraft/mod/ModFolderModel.h"
@@ -32,7 +34,10 @@
#include "minecraft/mod/ShaderPackFolderModel.h"
#include "minecraft/mod/TexturePackFolderModel.h"
+#include "minecraft/mod/tasks/GetModDependenciesTask.h"
#include "modplatform/ModIndex.h"
+#include "ui/dialogs/CustomMessageBox.h"
+#include "ui/dialogs/ProgressDialog.h"
#include "ui/dialogs/ReviewMessageBox.h"
#include "ui/pages/modplatform/ResourcePage.h"
@@ -122,30 +127,38 @@ void ResourceDownloadDialog::connectButtons()
void ResourceDownloadDialog::confirm()
{
- auto keys = m_selected.keys();
- keys.sort(Qt::CaseInsensitive);
-
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
confirm_dialog->retranslateUi(resourcesString());
- if (auto model = dynamic_cast<ModFolderModel*>(getBaseModel().get()); model) {
- QList<ModPlatform::IndexedVersion> selectedVers;
- for (auto& task : keys) {
- auto selected = m_selected.constFind(task).value();
- selectedVers.append(selected->getVersion());
- }
-
- auto dir = model->indexDir();
- auto dependencies = m_selectedPage->getDependecies(dir, selectedVers);
-
- for (auto dep : dependencies) {
- dep.is_currently_selected = true;
- auto pack = ModPlatform::IndexedPack{ dep.addonId, ModPlatform::ResourceProvider::FLAME, dep.fileName, dep.fileName };
- m_selected.insert(dep.fileName, makeShared<ResourceDownloadTask>(pack, dep, getBaseModel(), true));
- }
-
- keys = m_selected.keys();
+ if (auto task = getModDependenciesTask(); task) {
+ connect(task.get(), &Task::failed, this,
+ [&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
+
+ connect(task.get(), &Task::succeeded, this, [&]() {
+ QStringList warnings = task->warnings();
+ if (warnings.count()) {
+ CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec();
+ }
+ });
+
+ // Check for updates
+ ProgressDialog progress_dialog(this);
+ progress_dialog.setSkipButton(true, tr("Abort"));
+ progress_dialog.setWindowTitle(tr("Checking for dependencies..."));
+ auto ret = progress_dialog.execWithTask(task.get());
+
+ // If the dialog was skipped / some download error happened
+ if (ret == QDialog::DialogCode::Rejected) {
+ QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
+ return;
+ } else
+ for (auto dep : task->getDependecies()) {
+ addResource(dep->pack, dep->version, true);
+ }
}
+
+ auto keys = m_selected.keys();
+ keys.sort(Qt::CaseInsensitive);
for (auto& task : keys) {
auto selected = m_selected.constFind(task).value();
confirm_dialog->appendResource({ task, selected->getFilename(), selected->getCustomPath() });
@@ -173,6 +186,7 @@ ResourcePage* ResourceDownloadDialog::getSelectedPage()
void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver, bool is_indexed)
{
+ qWarning() << "DebugName: " << pack.name;
removeResource(pack, ver);
ver.is_currently_selected = true;
@@ -256,6 +270,21 @@ QList<BasePage*> ModDownloadDialog::getPages()
return pages;
}
+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;
+ for (auto& task : keys) {
+ auto selected = m_selected.constFind(task).value();
+ selectedVers.append(std::make_shared<GetModDependenciesTask::PackDependecny>(selected->getPack(), selected->getVersion()));
+ }
+
+ return makeShared<GetModDependenciesTask>(this, m_instance, model, selectedVers);
+ }
+ return nullptr;
+};
+
ResourcePackDownloadDialog::ResourcePackDownloadDialog(QWidget* parent,
const std::shared_ptr<ResourcePackFolderModel>& resource_packs,
BaseInstance* instance)
diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.h b/launcher/ui/dialogs/ResourceDownloadDialog.h
index 5678dc8b..f498df01 100644
--- a/launcher/ui/dialogs/ResourceDownloadDialog.h
+++ b/launcher/ui/dialogs/ResourceDownloadDialog.h
@@ -25,7 +25,9 @@
#include <QLayout>
#include "QObjectPtr.h"
+#include "minecraft/mod/tasks/GetModDependenciesTask.h"
#include "modplatform/ModIndex.h"
+#include "tasks/Task.h"
#include "ui/pages/BasePageProvider.h"
class BaseInstance;
@@ -80,6 +82,8 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
protected:
[[nodiscard]] virtual QString geometrySaveKey() const { return ""; }
+ [[nodiscard]] virtual GetModDependenciesTask::Ptr getModDependenciesTask() { return nullptr; }
+
protected:
const std::shared_ptr<ResourceFolderModel> m_base_model;
@@ -92,8 +96,6 @@ class ResourceDownloadDialog : public QDialog, public BasePageProvider {
QHash<QString, DownloadTaskPtr> m_selected;
};
-
-
class ModDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
@@ -106,6 +108,7 @@ class ModDownloadDialog final : public ResourceDownloadDialog {
[[nodiscard]] QString geometrySaveKey() const override { return "ModDownloadGeometry"; }
QList<BasePage*> getPages() override;
+ GetModDependenciesTask::Ptr getModDependenciesTask() override;
private:
BaseInstance* m_instance;
@@ -135,8 +138,8 @@ class TexturePackDownloadDialog final : public ResourceDownloadDialog {
public:
explicit TexturePackDownloadDialog(QWidget* parent,
- const std::shared_ptr<TexturePackFolderModel>& resource_packs,
- BaseInstance* instance);
+ const std::shared_ptr<TexturePackFolderModel>& resource_packs,
+ BaseInstance* instance);
~TexturePackDownloadDialog() override = default;
//: String that gets appended to the texture pack download dialog title ("Download " + resourcesString())
@@ -153,9 +156,7 @@ class ShaderPackDownloadDialog final : public ResourceDownloadDialog {
Q_OBJECT
public:
- explicit ShaderPackDownloadDialog(QWidget* parent,
- const std::shared_ptr<ShaderPackFolderModel>& shader_packs,
- BaseInstance* instance);
+ explicit ShaderPackDownloadDialog(QWidget* parent, const std::shared_ptr<ShaderPackFolderModel>& shader_packs, BaseInstance* instance);
~ShaderPackDownloadDialog() override = default;
//: String that gets appended to the shader pack download dialog title ("Download " + resourcesString())
diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp
index c1746d41..97b9efa9 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.cpp
+++ b/launcher/ui/pages/modplatform/ResourceModel.cpp
@@ -449,46 +449,4 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
emit projectInfoUpdated();
}
-QList<ModPlatform::IndexedVersion> ResourceModel::getDependecies(QDir& dir, QList<ModPlatform::IndexedVersion> selected)
-{
- auto task = std::make_unique<GetModDependenciesTask>(
- dir, selected,
- [this](const ModPlatform::Dependency& dependency, std::function<void(const ModPlatform::IndexedVersion&)> succeeded) -> Task::Ptr {
- auto args{ createDependecyArguments(dependency) };
- auto callbacks{ createDependecyCallbacks() };
-
- // Use default if no callbacks are set
- if (!callbacks.on_succeed)
- callbacks.on_succeed = [this, dependency, succeeded](auto& doc, auto& pack) {
- ModPlatform::IndexedVersion ver;
- try {
- QJsonArray arr;
- if (dependency.version.length() != 0 && doc.isObject()) {
- arr.append(doc.object());
- } else {
- arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
- }
- ver = loadDependencyVersions(dependency, arr);
- if (!ver.addonId.isValid()) {
- qWarning() << "Error while reading " << debugName() << " resource version empty ";
- qDebug() << doc;
- return;
- }
- } catch (const JSONValidationError& e) {
- qDebug() << doc;
- qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
- return;
- }
-
- succeeded(ver);
- };
-
- return m_api->getDependencyVersion(std::move(args), std::move(callbacks));
- });
-
- task->start();
-
- return task->getDependecies();
-};
-
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ResourceModel.h b/launcher/ui/pages/modplatform/ResourceModel.h
index 3b1f4748..3ea567af 100644
--- a/launcher/ui/pages/modplatform/ResourceModel.h
+++ b/launcher/ui/pages/modplatform/ResourceModel.h
@@ -85,8 +85,6 @@ class ResourceModel : public QAbstractListModel {
/** Gets the icon at the URL for the given index. If it's not fetched yet, fetch it and update when fisinhed. */
std::optional<QIcon> getIcon(QModelIndex&, const QUrl&);
- QList<ModPlatform::IndexedVersion> getDependecies(QDir& dir, QList<ModPlatform::IndexedVersion> m_selected);
-
protected:
/** Resets the model's data. */
void clearData();
diff --git a/launcher/ui/pages/modplatform/ResourcePage.cpp b/launcher/ui/pages/modplatform/ResourcePage.cpp
index 02412fd9..1baa24ee 100644
--- a/launcher/ui/pages/modplatform/ResourcePage.cpp
+++ b/launcher/ui/pages/modplatform/ResourcePage.cpp
@@ -405,9 +405,4 @@ void ResourcePage::openUrl(const QUrl& url)
QDesktopServices::openUrl(url);
}
-QList<ModPlatform::IndexedVersion> ResourcePage::getDependecies(QDir& dir, QList<ModPlatform::IndexedVersion> selected)
-{
- return m_model->getDependecies(dir, selected);
-};
-
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ResourcePage.h b/launcher/ui/pages/modplatform/ResourcePage.h
index 4fffd506..a8299728 100644
--- a/launcher/ui/pages/modplatform/ResourcePage.h
+++ b/launcher/ui/pages/modplatform/ResourcePage.h
@@ -75,8 +75,6 @@ class ResourcePage : public QWidget, public BasePage {
virtual void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
virtual void removeResourceFromDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
- QList<ModPlatform::IndexedVersion> getDependecies(QDir& dir, QList<ModPlatform::IndexedVersion> m_selected);
-
protected slots:
virtual void triggerSearch() {}