aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2023-03-03 11:14:57 +0000
committerTheKodeToad <TheKodeToad@proton.me>2023-03-03 11:24:36 +0000
commitadcdf28d64abbe16304c2d377488af1898f9b2af (patch)
treeee2ee00c592210deba9418a463814531d0579ace
parentf28a7b9d083a9181c04c7100f50152c116e72cb6 (diff)
downloadPrismLauncher-adcdf28d64abbe16304c2d377488af1898f9b2af.tar.gz
PrismLauncher-adcdf28d64abbe16304c2d377488af1898f9b2af.tar.bz2
PrismLauncher-adcdf28d64abbe16304c2d377488af1898f9b2af.zip
Move task to another thread
I don't know whether this is the prefered method. Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackExportTask.cpp79
-rw-r--r--launcher/ui/dialogs/ExportMrPackDialog.cpp32
-rw-r--r--launcher/ui/dialogs/ExportMrPackDialog.h2
3 files changed, 55 insertions, 58 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
index 029b47a5..331fbf94 100644
--- a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
+++ b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp
@@ -17,6 +17,7 @@
*/
#include "ModrinthPackExportTask.h"
+#include <qtconcurrentrun.h>
#include <QFileInfoList>
#include <QMessageBox>
#include "MMCZip.h"
@@ -34,57 +35,59 @@ ModrinthPackExportTask::ModrinthPackExportTask(const QString& name,
void ModrinthPackExportTask::executeTask()
{
- QFileInfoList files;
- if (!MMCZip::collectFileListRecursively(instance->gameRoot(), nullptr, &files, filter)) {
- emitFailed(tr("Could not collect list of files"));
- return;
- }
-
- setStatus("Adding files...");
+ QtConcurrent::run(QThreadPool::globalInstance(), [this] {
+ QFileInfoList files;
+ if (!MMCZip::collectFileListRecursively(instance->gameRoot(), nullptr, &files, filter)) {
+ emitFailed(tr("Could not collect list of files"));
+ return;
+ }
- QuaZip zip(output);
- if (!zip.open(QuaZip::mdCreate)) {
- QFile::remove(output);
- emitFailed(tr("Could not create file"));
- return;
- }
+ setStatus("Adding files...");
- {
- QuaZipFile indexFile(&zip);
- if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("modrinth.index.json"))) {
+ QuaZip zip(output);
+ if (!zip.open(QuaZip::mdCreate)) {
QFile::remove(output);
-
- emitFailed(tr("Could not create index"));
+ emitFailed(tr("Could not create file"));
return;
}
- indexFile.write(generateIndex());
- }
- // should exist
- QDir dotMinecraft(instance->gameRoot());
+ {
+ QuaZipFile indexFile(&zip);
+ if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("modrinth.index.json"))) {
+ QFile::remove(output);
- {
- size_t i = 0;
- for (const QFileInfo& file : files) {
- setProgress(i, files.length());
- if (!JlCompress::compressFile(&zip, file.absoluteFilePath(),
- "overrides/" + dotMinecraft.relativeFilePath(file.absoluteFilePath()))) {
- emitFailed(tr("Could not compress %1").arg(file.absoluteFilePath()));
+ emitFailed(tr("Could not create index"));
return;
}
- i++;
+ indexFile.write(generateIndex());
}
- }
- zip.close();
+ // should exist
+ QDir dotMinecraft(instance->gameRoot());
+
+ {
+ size_t i = 0;
+ for (const QFileInfo& file : files) {
+ setProgress(i, files.length());
+ if (!JlCompress::compressFile(&zip, file.absoluteFilePath(),
+ "overrides/" + dotMinecraft.relativeFilePath(file.absoluteFilePath()))) {
+ emitFailed(tr("Could not compress %1").arg(file.absoluteFilePath()));
+ return;
+ }
+ i++;
+ }
+ }
- if (zip.getZipError() != 0) {
- QFile::remove(output);
- emitFailed(tr("A zip error occured"));
- return;
- }
+ zip.close();
+
+ if (zip.getZipError() != 0) {
+ QFile::remove(output);
+ emitFailed(tr("A zip error occured"));
+ return;
+ }
- emitSucceeded();
+ emitSucceeded();
+ });
}
QByteArray ModrinthPackExportTask::generateIndex()
diff --git a/launcher/ui/dialogs/ExportMrPackDialog.cpp b/launcher/ui/dialogs/ExportMrPackDialog.cpp
index 4c2e5593..81663c9a 100644
--- a/launcher/ui/dialogs/ExportMrPackDialog.cpp
+++ b/launcher/ui/dialogs/ExportMrPackDialog.cpp
@@ -56,26 +56,22 @@ ExportMrPackDialog::~ExportMrPackDialog()
void ExportMrPackDialog::done(int result)
{
- if (result == Accepted)
- runExport();
+ if (result == Accepted) {
+ const QString filename = FS::RemoveInvalidFilenameChars(ui->name->text());
+ const QString output =
+ QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()), FS::PathCombine(QDir::homePath(), filename + ".mrpack"),
+ "Modrinth modpack (*.mrpack *.zip)", nullptr);
- QDialog::done(result);
-}
+ if (output.isEmpty())
+ return;
-void ExportMrPackDialog::runExport()
-{
- const QString filename = FS::RemoveInvalidFilenameChars(ui->name->text());
- const QString output =
- QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()), FS::PathCombine(QDir::homePath(), filename + ".mrpack"),
- "Modrinth modpack (*.mrpack *.zip)", nullptr);
+ ModrinthPackExportTask task(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
+ [this](const QString& path) { return proxy->blockedPaths().covers(path); });
- if (output.isEmpty())
- return;
+ ProgressDialog progress(this);
+ progress.setSkipButton(true, tr("Abort"));
+ progress.execWithTask(&task);
+ }
- ModrinthPackExportTask task(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
- [this](const QString& path) { return proxy->blockedPaths().covers(path); });
-
- ProgressDialog progress(this);
- progress.setSkipButton(true, tr("Abort"));
- progress.execWithTask(&task);
+ QDialog::done(result);
} \ No newline at end of file
diff --git a/launcher/ui/dialogs/ExportMrPackDialog.h b/launcher/ui/dialogs/ExportMrPackDialog.h
index 89263fc6..3ded4887 100644
--- a/launcher/ui/dialogs/ExportMrPackDialog.h
+++ b/launcher/ui/dialogs/ExportMrPackDialog.h
@@ -39,6 +39,4 @@ class ExportMrPackDialog : public QDialog {
const InstancePtr instance;
Ui::ExportMrPackDialog* ui;
PackIgnoreProxy* proxy;
-
- void runExport();
};