Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring amount of concurrent tasks #1363

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)

m_settings->registerSetting("MenuBarInsteadOfToolBar", false);

m_settings->registerSetting("NumberOfConcurrentTasks", 6);

QString defaultMonospace;
int defaultSize = 11;
#ifdef Q_OS_WIN32
Expand Down
2 changes: 1 addition & 1 deletion launcher/modplatform/EnsureMetadataTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EnsureMetadataTask::EnsureMetadataTask(Mod* mod, QDir dir, ModPlatform::Resource
EnsureMetadataTask::EnsureMetadataTask(QList<Mod*>& mods, QDir dir, ModPlatform::ResourceProvider prov)
: Task(nullptr), m_index_dir(dir), m_provider(prov), m_current_task(nullptr)
{
m_hashing_task.reset(new ConcurrentTask(this, "MakeHashesTask", 10));
m_hashing_task.reset(new ConcurrentTask(this, "MakeHashesTask"));
for (auto* mod : mods) {
auto hash_task = createNewHash(mod);
if (!hash_task)
Expand Down
2 changes: 1 addition & 1 deletion launcher/modplatform/flame/FlamePackExportTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FlamePackExportTask::collectHashes()
setStatus(tr("Finding file hashes..."));
setProgress(1, 5);
auto allMods = mcInstance->loaderModList()->allMods();
ConcurrentTask::Ptr hashingTask(new ConcurrentTask(this, "MakeHashesTask", 10));
ConcurrentTask::Ptr hashingTask(new ConcurrentTask(this, "MakeHashesTask"));
task.reset(hashingTask);
for (const QFileInfo& file : files) {
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
Expand Down
2 changes: 1 addition & 1 deletion launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void ModrinthCheckUpdate::executeTask()
QStringList hashes;
auto best_hash_type = ProviderCaps.hashType(ModPlatform::ResourceProvider::MODRINTH).first();

ConcurrentTask hashing_task(this, "MakeModrinthHashesTask", 10);
ConcurrentTask hashing_task(this, "MakeModrinthHashesTask");
for (auto* mod : m_mods) {
if (!mod->enabled()) {
emit checkFailed(mod, tr("Disabled mods won't be updated, to prevent mod duplication issues!"));
Expand Down
5 changes: 4 additions & 1 deletion launcher/tasks/ConcurrentTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@
#include <QUuid>
#include <memory>

#include "Application.h"
#include "tasks/Task.h"

class ConcurrentTask : public Task {
Q_OBJECT
public:
using Ptr = shared_qobject_ptr<ConcurrentTask>;

explicit ConcurrentTask(QObject* parent = nullptr, QString task_name = "", int max_concurrent = 6);
explicit ConcurrentTask(QObject* parent = nullptr,
QString task_name = "",
int max_concurrent = APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
Scrumplex marked this conversation as resolved.
Show resolved Hide resolved
~ConcurrentTask() override;

bool canAbort() const override { return true; }
Expand Down
4 changes: 2 additions & 2 deletions launcher/ui/dialogs/BlockedModsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
: QDialog(parent), ui(new Ui::BlockedModsDialog), m_mods(mods)
{
m_hashing_task = shared_qobject_ptr<ConcurrentTask>(new ConcurrentTask(this, "MakeHashesTask", 10));
m_hashing_task = shared_qobject_ptr<ConcurrentTask>(new ConcurrentTask(this, "MakeHashesTask"));
connect(m_hashing_task.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished);

ui->setupUi(this);
Expand Down Expand Up @@ -313,7 +313,7 @@ bool BlockedModsDialog::checkValidPath(QString path)
// efectivly compare two strings ignoring all separators and case
auto laxCompare = [](QString fsfilename, QString metadataFilename) {
// allowed character seperators
QList<QChar> allowedSeperators = { '-', '+', '.' , '_'};
QList<QChar> allowedSeperators = { '-', '+', '.', '_' };

// copy in lowercase
auto fsName = fsfilename.toLower();
Expand Down
4 changes: 4 additions & 0 deletions launcher/ui/pages/global/LauncherPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ void LauncherPage::applySettings()

s->set("MenuBarInsteadOfToolBar", ui->preferMenuBarCheckBox->isChecked());

s->set("NumberOfConcurrentTasks", ui->numberOfConcurrentTasksSpinBox->value());

// Console settings
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
Expand Down Expand Up @@ -251,6 +253,8 @@ void LauncherPage::loadSettings()
#endif
ui->preferMenuBarCheckBox->setChecked(s->get("MenuBarInsteadOfToolBar").toBool());

ui->numberOfConcurrentTasksSpinBox->setValue(s->get("NumberOfConcurrentTasks").toInt());

// Console settings
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
Expand Down
23 changes: 23 additions & 0 deletions launcher/ui/pages/global/LauncherPage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,29 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="miscellaneousGroupBox">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="numberOfConcurrentTasksLabel">
<property name="text">
<string>Number of concurrent tasks</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="numberOfConcurrentTasksSpinBox">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down