mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2025-03-22 19:20:45 +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
|
InstanceCopyTask.cpp
|
||||||
InstanceImportTask.h
|
InstanceImportTask.h
|
||||||
InstanceImportTask.cpp
|
InstanceImportTask.cpp
|
||||||
ModrinthInstanceExportTask.h
|
|
||||||
ModrinthInstanceExportTask.cpp
|
|
||||||
|
|
||||||
# Use tracking separate from memory management
|
# Use tracking separate from memory management
|
||||||
Usable.h
|
Usable.h
|
||||||
@ -529,6 +527,8 @@ set(ATLAUNCHER_SOURCES
|
|||||||
set(MODRINTH_SOURCES
|
set(MODRINTH_SOURCES
|
||||||
modplatform/modrinth/ModrinthPackManifest.cpp
|
modplatform/modrinth/ModrinthPackManifest.cpp
|
||||||
modplatform/modrinth/ModrinthPackManifest.h
|
modplatform/modrinth/ModrinthPackManifest.h
|
||||||
|
modplatform/modrinth/ModrinthInstanceExportTask.h
|
||||||
|
modplatform/modrinth/ModrinthInstanceExportTask.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(Index
|
add_unit_test(Index
|
||||||
|
@ -17,9 +17,12 @@
|
|||||||
#include "JlCompress.h"
|
#include "JlCompress.h"
|
||||||
#include "FileSystem.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..."));
|
setStatus(tr("Finding files to look up on Modrinth..."));
|
||||||
|
|
||||||
@ -83,9 +86,9 @@ void ModrinthInstanceExportTask::executeTask()
|
|||||||
hasher.addData(contents);
|
hasher.addData(contents);
|
||||||
QString hash = hasher.result().toHex();
|
QString hash = hasher.result().toHex();
|
||||||
|
|
||||||
m_responses.append(ModrinthLookupData {
|
m_responses.append(HashLookupData{
|
||||||
QFileInfo(file),
|
QFileInfo(file),
|
||||||
QByteArray()
|
QByteArray()
|
||||||
});
|
});
|
||||||
|
|
||||||
m_netJob->addNetAction(Net::Download::makeByteArray(
|
m_netJob->addNetAction(Net::Download::makeByteArray(
|
||||||
@ -96,18 +99,18 @@ void ModrinthInstanceExportTask::executeTask()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_netJob.get(), &NetJob::succeeded, this, &ModrinthInstanceExportTask::lookupSucceeded);
|
connect(m_netJob.get(), &NetJob::succeeded, this, &InstanceExportTask::lookupSucceeded);
|
||||||
connect(m_netJob.get(), &NetJob::failed, this, &ModrinthInstanceExportTask::lookupFailed);
|
connect(m_netJob.get(), &NetJob::failed, this, &InstanceExportTask::lookupFailed);
|
||||||
connect(m_netJob.get(), &NetJob::progress, this, &ModrinthInstanceExportTask::lookupProgress);
|
connect(m_netJob.get(), &NetJob::progress, this, &InstanceExportTask::lookupProgress);
|
||||||
|
|
||||||
m_netJob->start();
|
m_netJob->start();
|
||||||
setStatus(tr("Looking up files on Modrinth..."));
|
setStatus(tr("Looking up files on Modrinth..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModrinthInstanceExportTask::lookupSucceeded()
|
void InstanceExportTask::lookupSucceeded()
|
||||||
{
|
{
|
||||||
setStatus(tr("Creating modpack metadata..."));
|
setStatus(tr("Creating modpack metadata..."));
|
||||||
QList<ModrinthFile> resolvedFiles;
|
QList<ExportFile> resolvedFiles;
|
||||||
QFileInfoList failedFiles;
|
QFileInfoList failedFiles;
|
||||||
|
|
||||||
for (const auto &data : m_responses) {
|
for (const auto &data : m_responses) {
|
||||||
@ -121,7 +124,7 @@ void ModrinthInstanceExportTask::lookupSucceeded()
|
|||||||
QString sha512Hash = Json::requireString(hashes, "sha512");
|
QString sha512Hash = Json::requireString(hashes, "sha512");
|
||||||
QString sha1Hash = Json::requireString(hashes, "sha1");
|
QString sha1Hash = Json::requireString(hashes, "sha1");
|
||||||
|
|
||||||
ModrinthFile fileData;
|
ExportFile fileData;
|
||||||
|
|
||||||
QDir gameDir(m_instance->gameRoot());
|
QDir gameDir(m_instance->gameRoot());
|
||||||
|
|
||||||
@ -231,12 +234,14 @@ void ModrinthInstanceExportTask::lookupSucceeded()
|
|||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModrinthInstanceExportTask::lookupFailed(const QString &reason)
|
void InstanceExportTask::lookupFailed(const QString &reason)
|
||||||
{
|
{
|
||||||
emitFailed(reason);
|
emitFailed(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModrinthInstanceExportTask::lookupProgress(qint64 current, qint64 total)
|
void InstanceExportTask::lookupProgress(qint64 current, qint64 total)
|
||||||
{
|
{
|
||||||
setProgress(current, total);
|
setProgress(current, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,11 @@
|
|||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
#include "ui/dialogs/ModrinthExportDialog.h"
|
#include "ui/dialogs/ModrinthExportDialog.h"
|
||||||
|
|
||||||
struct ModrinthExportSettings {
|
namespace Modrinth
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ExportSettings
|
||||||
|
{
|
||||||
QString version;
|
QString version;
|
||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
@ -31,13 +35,14 @@ struct ModrinthExportSettings {
|
|||||||
QString exportPath;
|
QString exportPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModrinthLookupData {
|
struct HashLookupData
|
||||||
|
{
|
||||||
QFileInfo fileInfo;
|
QFileInfo fileInfo;
|
||||||
QByteArray response;
|
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)
|
// 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 path;
|
||||||
QString sha512;
|
QString sha512;
|
||||||
@ -46,12 +51,12 @@ struct ModrinthFile
|
|||||||
qint64 fileSize;
|
qint64 fileSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ModrinthInstanceExportTask : public Task
|
class InstanceExportTask : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ModrinthInstanceExportTask(InstancePtr instance, ModrinthExportSettings settings);
|
explicit InstanceExportTask(InstancePtr instance, ExportSettings settings);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Entry point for tasks.
|
//! Entry point for tasks.
|
||||||
@ -64,7 +69,9 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
InstancePtr m_instance;
|
InstancePtr m_instance;
|
||||||
ModrinthExportSettings m_settings;
|
ExportSettings m_settings;
|
||||||
QList<ModrinthLookupData> m_responses;
|
QList<HashLookupData> m_responses;
|
||||||
NetJob::Ptr m_netJob;
|
NetJob::Ptr m_netJob;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,7 @@
|
|||||||
#include "ModrinthExportDialog.h"
|
#include "ModrinthExportDialog.h"
|
||||||
#include "ui_ModrinthExportDialog.h"
|
#include "ui_ModrinthExportDialog.h"
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
#include "ModrinthInstanceExportTask.h"
|
#include "modplatform/modrinth/ModrinthInstanceExportTask.h"
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
#include "ProgressDialog.h"
|
#include "ProgressDialog.h"
|
||||||
@ -71,7 +71,7 @@ void ModrinthExportDialog::on_datapackPathBrowse_clicked()
|
|||||||
|
|
||||||
void ModrinthExportDialog::accept()
|
void ModrinthExportDialog::accept()
|
||||||
{
|
{
|
||||||
ModrinthExportSettings settings;
|
Modrinth::ExportSettings settings;
|
||||||
|
|
||||||
settings.name = ui->name->text();
|
settings.name = ui->name->text();
|
||||||
settings.version = ui->version->text();
|
settings.version = ui->version->text();
|
||||||
@ -109,11 +109,17 @@ void ModrinthExportDialog::accept()
|
|||||||
|
|
||||||
settings.exportPath = ui->file->text();
|
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)
|
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]()
|
connect(task, &Task::succeeded, [this, task]()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user