Skip to content

Commit

Permalink
Merge pull request PrismLauncher#3216 from Trial97/fix_auto_mod_provider
Browse files Browse the repository at this point in the history
Fix automatically choose mod provider option
  • Loading branch information
Trial97 authored Dec 19, 2024
2 parents f17faad + 0412ed3 commit 0b6ce55
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
17 changes: 9 additions & 8 deletions launcher/modplatform/EnsureMetadataTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,28 @@ static ModrinthAPI modrinth_api;
static FlameAPI flame_api;

EnsureMetadataTask::EnsureMetadataTask(Resource* resource, QDir dir, ModPlatform::ResourceProvider prov)
: Task(), m_index_dir(dir), m_provider(prov), m_hashing_task(nullptr), m_current_task(nullptr)
: Task(), m_index_dir(dir), m_provider(prov), m_hashingTask(nullptr), m_current_task(nullptr)
{
auto hash_task = createNewHash(resource);
if (!hash_task)
auto hashTask = createNewHash(resource);
if (!hashTask)
return;
connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, resource](QString hash) { m_resources.insert(hash, resource); });
connect(hash_task.get(), &Task::failed, [this, resource] { emitFail(resource, "", RemoveFromList::No); });
hash_task->start();
connect(hashTask.get(), &Hashing::Hasher::resultsReady, [this, resource](QString hash) { m_resources.insert(hash, resource); });
connect(hashTask.get(), &Task::failed, [this, resource] { emitFail(resource, "", RemoveFromList::No); });
m_hashingTask = hashTask;
}

EnsureMetadataTask::EnsureMetadataTask(QList<Resource*>& resources, QDir dir, ModPlatform::ResourceProvider prov)
: Task(), m_index_dir(dir), m_provider(prov), m_current_task(nullptr)
{
m_hashing_task.reset(new ConcurrentTask("MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
auto hashTask = makeShared<ConcurrentTask>("MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
m_hashingTask = hashTask;
for (auto* resource : resources) {
auto hash_task = createNewHash(resource);
if (!hash_task)
continue;
connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, resource](QString hash) { m_resources.insert(hash, resource); });
connect(hash_task.get(), &Task::failed, [this, resource] { emitFail(resource, "", RemoveFromList::No); });
m_hashing_task->addTask(hash_task);
hashTask->addTask(hash_task);
}
}

Expand Down
4 changes: 2 additions & 2 deletions launcher/modplatform/EnsureMetadataTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EnsureMetadataTask : public Task {

~EnsureMetadataTask() = default;

Task::Ptr getHashingTask() { return m_hashing_task; }
Task::Ptr getHashingTask() { return m_hashingTask; }

public slots:
bool abort() override;
Expand Down Expand Up @@ -59,6 +59,6 @@ class EnsureMetadataTask : public Task {
ModPlatform::ResourceProvider m_provider;

QHash<QString, ModPlatform::IndexedVersion> m_temp_versions;
ConcurrentTask::Ptr m_hashing_task;
Task::Ptr m_hashingTask;
Task::Ptr m_current_task;
};
11 changes: 9 additions & 2 deletions launcher/ui/dialogs/ResourceUpdateDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "minecraft/mod/tasks/GetModDependenciesTask.h"
#include "modplatform/ModIndex.h"
#include "modplatform/flame/FlameAPI.h"
#include "tasks/SequentialTask.h"
#include "ui_ReviewMessageBox.h"

#include "Markdown.h"
Expand Down Expand Up @@ -412,8 +413,14 @@ void ResourceUpdateDialog::onMetadataFailed(Resource* resource, bool try_others,
connect(task.get(), &EnsureMetadataTask::metadataFailed, [this](Resource* candidate) { onMetadataFailed(candidate, false); });
connect(task.get(), &EnsureMetadataTask::failed,
[this](const QString& reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });

m_second_try_metadata->addTask(task);
if (task->getHashingTask()) {
auto seq = makeShared<SequentialTask>();
seq->addTask(task->getHashingTask());
seq->addTask(task);
m_second_try_metadata->addTask(seq);
} else {
m_second_try_metadata->addTask(task);
}
} else {
QString reason{ tr("Couldn't find a valid version on the selected mod provider(s)") };

Expand Down

0 comments on commit 0b6ce55

Please sign in to comment.