mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2025-03-21 16:20:48 +00:00
GH-4699 Move ModrinthInstanceExportTask to modplatform/modrinth; truncate error messages in dialog
This commit is contained in:
parent
a452b7ee96
commit
aae2f23eb6
@ -36,8 +36,6 @@ set(CORE_SOURCES
|
||||
InstanceCopyTask.cpp
|
||||
InstanceImportTask.h
|
||||
InstanceImportTask.cpp
|
||||
ModrinthInstanceExportTask.h
|
||||
ModrinthInstanceExportTask.cpp
|
||||
|
||||
# Use tracking separate from memory management
|
||||
Usable.h
|
||||
@ -529,6 +527,8 @@ set(ATLAUNCHER_SOURCES
|
||||
set(MODRINTH_SOURCES
|
||||
modplatform/modrinth/ModrinthPackManifest.cpp
|
||||
modplatform/modrinth/ModrinthPackManifest.h
|
||||
modplatform/modrinth/ModrinthInstanceExportTask.h
|
||||
modplatform/modrinth/ModrinthInstanceExportTask.cpp
|
||||
)
|
||||
|
||||
add_unit_test(Index
|
||||
|
@ -17,9 +17,12 @@
|
||||
#include "JlCompress.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
ModrinthInstanceExportTask::ModrinthInstanceExportTask(InstancePtr instance, ModrinthExportSettings settings) : m_instance(instance), m_settings(settings) {}
|
||||
namespace Modrinth
|
||||
{
|
||||
|
||||
void ModrinthInstanceExportTask::executeTask()
|
||||
InstanceExportTask::InstanceExportTask(InstancePtr instance, ExportSettings settings) : m_instance(instance), m_settings(settings) {}
|
||||
|
||||
void InstanceExportTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Finding files to look up on Modrinth..."));
|
||||
|
||||
@ -83,7 +86,7 @@ void ModrinthInstanceExportTask::executeTask()
|
||||
hasher.addData(contents);
|
||||
QString hash = hasher.result().toHex();
|
||||
|
||||
m_responses.append(ModrinthLookupData {
|
||||
m_responses.append(HashLookupData{
|
||||
QFileInfo(file),
|
||||
QByteArray()
|
||||
});
|
||||
@ -96,18 +99,18 @@ void ModrinthInstanceExportTask::executeTask()
|
||||
}
|
||||
}
|
||||
|
||||
connect(m_netJob.get(), &NetJob::succeeded, this, &ModrinthInstanceExportTask::lookupSucceeded);
|
||||
connect(m_netJob.get(), &NetJob::failed, this, &ModrinthInstanceExportTask::lookupFailed);
|
||||
connect(m_netJob.get(), &NetJob::progress, this, &ModrinthInstanceExportTask::lookupProgress);
|
||||
connect(m_netJob.get(), &NetJob::succeeded, this, &InstanceExportTask::lookupSucceeded);
|
||||
connect(m_netJob.get(), &NetJob::failed, this, &InstanceExportTask::lookupFailed);
|
||||
connect(m_netJob.get(), &NetJob::progress, this, &InstanceExportTask::lookupProgress);
|
||||
|
||||
m_netJob->start();
|
||||
setStatus(tr("Looking up files on Modrinth..."));
|
||||
}
|
||||
|
||||
void ModrinthInstanceExportTask::lookupSucceeded()
|
||||
void InstanceExportTask::lookupSucceeded()
|
||||
{
|
||||
setStatus(tr("Creating modpack metadata..."));
|
||||
QList<ModrinthFile> resolvedFiles;
|
||||
QList<ExportFile> resolvedFiles;
|
||||
QFileInfoList failedFiles;
|
||||
|
||||
for (const auto &data : m_responses) {
|
||||
@ -121,7 +124,7 @@ void ModrinthInstanceExportTask::lookupSucceeded()
|
||||
QString sha512Hash = Json::requireString(hashes, "sha512");
|
||||
QString sha1Hash = Json::requireString(hashes, "sha1");
|
||||
|
||||
ModrinthFile fileData;
|
||||
ExportFile fileData;
|
||||
|
||||
QDir gameDir(m_instance->gameRoot());
|
||||
|
||||
@ -231,12 +234,14 @@ void ModrinthInstanceExportTask::lookupSucceeded()
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void ModrinthInstanceExportTask::lookupFailed(const QString &reason)
|
||||
void InstanceExportTask::lookupFailed(const QString &reason)
|
||||
{
|
||||
emitFailed(reason);
|
||||
}
|
||||
|
||||
void ModrinthInstanceExportTask::lookupProgress(qint64 current, qint64 total)
|
||||
void InstanceExportTask::lookupProgress(qint64 current, qint64 total)
|
||||
{
|
||||
setProgress(current, total);
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,11 @@
|
||||
#include "net/NetJob.h"
|
||||
#include "ui/dialogs/ModrinthExportDialog.h"
|
||||
|
||||
struct ModrinthExportSettings {
|
||||
namespace Modrinth
|
||||
{
|
||||
|
||||
struct ExportSettings
|
||||
{
|
||||
QString version;
|
||||
QString name;
|
||||
QString description;
|
||||
@ -31,13 +35,14 @@ struct ModrinthExportSettings {
|
||||
QString exportPath;
|
||||
};
|
||||
|
||||
struct ModrinthLookupData {
|
||||
struct HashLookupData
|
||||
{
|
||||
QFileInfo fileInfo;
|
||||
QByteArray response;
|
||||
};
|
||||
|
||||
// Using the existing Modrinth::File struct from the importer doesn't actually make much sense here (doesn't support multiple hashes, hash is a byte array rather than a string, no file size, etc)
|
||||
struct ModrinthFile
|
||||
struct ExportFile
|
||||
{
|
||||
QString path;
|
||||
QString sha512;
|
||||
@ -46,12 +51,12 @@ struct ModrinthFile
|
||||
qint64 fileSize;
|
||||
};
|
||||
|
||||
class ModrinthInstanceExportTask : public Task
|
||||
class InstanceExportTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ModrinthInstanceExportTask(InstancePtr instance, ModrinthExportSettings settings);
|
||||
explicit InstanceExportTask(InstancePtr instance, ExportSettings settings);
|
||||
|
||||
protected:
|
||||
//! Entry point for tasks.
|
||||
@ -64,7 +69,9 @@ private slots:
|
||||
|
||||
private:
|
||||
InstancePtr m_instance;
|
||||
ModrinthExportSettings m_settings;
|
||||
QList<ModrinthLookupData> m_responses;
|
||||
ExportSettings m_settings;
|
||||
QList<HashLookupData> m_responses;
|
||||
NetJob::Ptr m_netJob;
|
||||
};
|
||||
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
#include "ModrinthExportDialog.h"
|
||||
#include "ui_ModrinthExportDialog.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "ModrinthInstanceExportTask.h"
|
||||
#include "modplatform/modrinth/ModrinthInstanceExportTask.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "ProgressDialog.h"
|
||||
@ -71,7 +71,7 @@ void ModrinthExportDialog::on_datapackPathBrowse_clicked()
|
||||
|
||||
void ModrinthExportDialog::accept()
|
||||
{
|
||||
ModrinthExportSettings settings;
|
||||
Modrinth::ExportSettings settings;
|
||||
|
||||
settings.name = ui->name->text();
|
||||
settings.version = ui->version->text();
|
||||
@ -109,11 +109,17 @@ void ModrinthExportDialog::accept()
|
||||
|
||||
settings.exportPath = ui->file->text();
|
||||
|
||||
auto *task = new ModrinthInstanceExportTask(m_instance, settings);
|
||||
auto *task = new Modrinth::InstanceExportTask(m_instance, settings);
|
||||
|
||||
connect(task, &Task::failed, [this](QString reason)
|
||||
{
|
||||
CustomMessageBox::selectable(parentWidget(), tr("Error"), reason, QMessageBox::Critical)->show();
|
||||
QString text;
|
||||
if (reason.length() > 1000) {
|
||||
text = reason.left(1000) + "...";
|
||||
} else {
|
||||
text = reason;
|
||||
}
|
||||
CustomMessageBox::selectable(parentWidget(), tr("Error"), text, QMessageBox::Critical)->show();
|
||||
});
|
||||
connect(task, &Task::succeeded, [this, task]()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user