mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-10 20:35:43 +02:00
Use options struct for FlamePackExportTask
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@ -41,24 +41,8 @@
|
||||
const QString FlamePackExportTask::TEMPLATE = "<li><a href=\"{url}\">{name}{authors}</a></li>\n";
|
||||
const QStringList FlamePackExportTask::FILE_EXTENSIONS({ "jar", "zip" });
|
||||
|
||||
FlamePackExportTask::FlamePackExportTask(const QString& name,
|
||||
const QString& version,
|
||||
const QString& author,
|
||||
bool optionalFiles,
|
||||
InstancePtr instance,
|
||||
const QString& output,
|
||||
MMCZip::FilterFileFunction filter,
|
||||
int recommendedRAM)
|
||||
: name(name)
|
||||
, version(version)
|
||||
, author(author)
|
||||
, optionalFiles(optionalFiles)
|
||||
, instance(instance)
|
||||
, mcInstance(dynamic_cast<MinecraftInstance*>(instance.get()))
|
||||
, gameRoot(instance->gameRoot())
|
||||
, output(output)
|
||||
, filter(filter)
|
||||
, m_recommendedRAM(recommendedRAM)
|
||||
FlamePackExportTask::FlamePackExportTask(FlamePackExportOptions&& options)
|
||||
: m_options(std::move(options)), m_gameRoot(m_options.instance->gameRoot())
|
||||
{}
|
||||
|
||||
void FlamePackExportTask::executeTask()
|
||||
@ -83,7 +67,7 @@ void FlamePackExportTask::collectFiles()
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
files.clear();
|
||||
if (!MMCZip::collectFileListRecursively(instance->gameRoot(), nullptr, &files, filter)) {
|
||||
if (!MMCZip::collectFileListRecursively(m_options.instance->gameRoot(), nullptr, &files, m_options.filter)) {
|
||||
emitFailed(tr("Could not search for files"));
|
||||
return;
|
||||
}
|
||||
@ -91,11 +75,8 @@ void FlamePackExportTask::collectFiles()
|
||||
pendingHashes.clear();
|
||||
resolvedFiles.clear();
|
||||
|
||||
if (mcInstance != nullptr) {
|
||||
mcInstance->loaderModList()->update();
|
||||
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, &FlamePackExportTask::collectHashes);
|
||||
} else
|
||||
collectHashes();
|
||||
m_options.instance->loaderModList()->update();
|
||||
connect(m_options.instance->loaderModList().get(), &ModFolderModel::updateFinished, this, &FlamePackExportTask::collectHashes);
|
||||
}
|
||||
|
||||
void FlamePackExportTask::collectHashes()
|
||||
@ -103,11 +84,11 @@ void FlamePackExportTask::collectHashes()
|
||||
setAbortable(true);
|
||||
setStatus(tr("Finding file hashes..."));
|
||||
setProgress(1, 5);
|
||||
auto allMods = mcInstance->loaderModList()->allMods();
|
||||
auto allMods = m_options.instance->loaderModList()->allMods();
|
||||
ConcurrentTask::Ptr hashingTask(new ConcurrentTask("MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
|
||||
task.reset(hashingTask);
|
||||
for (const QFileInfo& file : files) {
|
||||
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
|
||||
const QString relative = m_gameRoot.relativeFilePath(file.absoluteFilePath());
|
||||
// require sensible file types
|
||||
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
|
||||
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
|
||||
@ -337,13 +318,13 @@ void FlamePackExportTask::buildZip()
|
||||
setStatus(tr("Adding files..."));
|
||||
setProgress(4, 5);
|
||||
|
||||
auto zipTask = makeShared<MMCZip::ExportToZipTask>(output, gameRoot, files, "overrides/", true, false);
|
||||
auto zipTask = makeShared<MMCZip::ExportToZipTask>(m_options.output, m_gameRoot, files, "overrides/", true, false);
|
||||
zipTask->addExtraFile("manifest.json", generateIndex());
|
||||
zipTask->addExtraFile("modlist.html", generateHTML());
|
||||
|
||||
QStringList exclude;
|
||||
std::transform(resolvedFiles.keyBegin(), resolvedFiles.keyEnd(), std::back_insert_iterator(exclude),
|
||||
[this](QString file) { return gameRoot.relativeFilePath(file); });
|
||||
[this](QString file) { return m_gameRoot.relativeFilePath(file); });
|
||||
zipTask->setExcludeFiles(exclude);
|
||||
|
||||
auto progressStep = std::make_shared<TaskStepProgress>();
|
||||
@ -378,56 +359,56 @@ QByteArray FlamePackExportTask::generateIndex()
|
||||
QJsonObject obj;
|
||||
obj["manifestType"] = "minecraftModpack";
|
||||
obj["manifestVersion"] = 1;
|
||||
obj["name"] = name;
|
||||
obj["version"] = version;
|
||||
obj["author"] = author;
|
||||
obj["name"] = m_options.name;
|
||||
obj["version"] = m_options.version;
|
||||
obj["author"] = m_options.author;
|
||||
obj["overrides"] = "overrides";
|
||||
if (mcInstance) {
|
||||
QJsonObject version;
|
||||
auto profile = mcInstance->getPackProfile();
|
||||
// collect all supported components
|
||||
const ComponentPtr minecraft = profile->getComponent("net.minecraft");
|
||||
const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader");
|
||||
const ComponentPtr fabric = profile->getComponent("net.fabricmc.fabric-loader");
|
||||
const ComponentPtr forge = profile->getComponent("net.minecraftforge");
|
||||
const ComponentPtr neoforge = profile->getComponent("net.neoforged");
|
||||
|
||||
// convert all available components to mrpack dependencies
|
||||
if (minecraft != nullptr)
|
||||
version["version"] = minecraft->m_version;
|
||||
QString id;
|
||||
if (quilt != nullptr)
|
||||
id = "quilt-" + quilt->m_version;
|
||||
else if (fabric != nullptr)
|
||||
id = "fabric-" + fabric->m_version;
|
||||
else if (forge != nullptr)
|
||||
id = "forge-" + forge->m_version;
|
||||
else if (neoforge != nullptr) {
|
||||
id = "neoforge-";
|
||||
if (minecraft->m_version == "1.20.1")
|
||||
id += "1.20.1-";
|
||||
id += neoforge->m_version;
|
||||
}
|
||||
version["modLoaders"] = QJsonArray();
|
||||
if (!id.isEmpty()) {
|
||||
QJsonObject loader;
|
||||
loader["id"] = id;
|
||||
loader["primary"] = true;
|
||||
version["modLoaders"] = QJsonArray({ loader });
|
||||
}
|
||||
QJsonObject version;
|
||||
|
||||
if (m_recommendedRAM > 0)
|
||||
version["recommendedRam"] = m_recommendedRAM;
|
||||
auto profile = m_options.instance->getPackProfile();
|
||||
// collect all supported components
|
||||
const ComponentPtr minecraft = profile->getComponent("net.minecraft");
|
||||
const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader");
|
||||
const ComponentPtr fabric = profile->getComponent("net.fabricmc.fabric-loader");
|
||||
const ComponentPtr forge = profile->getComponent("net.minecraftforge");
|
||||
const ComponentPtr neoforge = profile->getComponent("net.neoforged");
|
||||
|
||||
obj["minecraft"] = version;
|
||||
// convert all available components to mrpack dependencies
|
||||
if (minecraft != nullptr)
|
||||
version["version"] = minecraft->m_version;
|
||||
QString id;
|
||||
if (quilt != nullptr)
|
||||
id = "quilt-" + quilt->m_version;
|
||||
else if (fabric != nullptr)
|
||||
id = "fabric-" + fabric->m_version;
|
||||
else if (forge != nullptr)
|
||||
id = "forge-" + forge->m_version;
|
||||
else if (neoforge != nullptr) {
|
||||
id = "neoforge-";
|
||||
if (minecraft->m_version == "1.20.1")
|
||||
id += "1.20.1-";
|
||||
id += neoforge->m_version;
|
||||
}
|
||||
version["modLoaders"] = QJsonArray();
|
||||
if (!id.isEmpty()) {
|
||||
QJsonObject loader;
|
||||
loader["id"] = id;
|
||||
loader["primary"] = true;
|
||||
version["modLoaders"] = QJsonArray({ loader });
|
||||
}
|
||||
|
||||
if (m_options.recommendedRAM > 0)
|
||||
version["recommendedRam"] = m_options.recommendedRAM;
|
||||
|
||||
obj["minecraft"] = version;
|
||||
|
||||
QJsonArray files;
|
||||
for (auto mod : resolvedFiles) {
|
||||
QJsonObject file;
|
||||
file["projectID"] = mod.addonId;
|
||||
file["fileID"] = mod.version;
|
||||
file["required"] = mod.enabled || !optionalFiles;
|
||||
file["required"] = mod.enabled || !m_options.optionalFiles;
|
||||
files << file;
|
||||
}
|
||||
obj["files"] = files;
|
||||
|
@ -19,23 +19,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseInstance.h"
|
||||
#include "MMCZip.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "modplatform/flame/FlameAPI.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
struct FlamePackExportOptions {
|
||||
QString name;
|
||||
QString version;
|
||||
QString author;
|
||||
bool optionalFiles;
|
||||
MinecraftInstancePtr instance;
|
||||
QString output;
|
||||
MMCZip::FilterFileFunction filter;
|
||||
int recommendedRAM;
|
||||
};
|
||||
|
||||
class FlamePackExportTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FlamePackExportTask(const QString& name,
|
||||
const QString& version,
|
||||
const QString& author,
|
||||
bool optionalFiles,
|
||||
InstancePtr instance,
|
||||
const QString& output,
|
||||
MMCZip::FilterFileFunction filter,
|
||||
int recommendedRAM);
|
||||
FlamePackExportTask(FlamePackExportOptions&& options);
|
||||
|
||||
protected:
|
||||
void executeTask() override;
|
||||
@ -46,14 +49,6 @@ class FlamePackExportTask : public Task {
|
||||
static const QStringList FILE_EXTENSIONS;
|
||||
|
||||
// inputs
|
||||
const QString name, version, author;
|
||||
const bool optionalFiles;
|
||||
const InstancePtr instance;
|
||||
MinecraftInstance* mcInstance;
|
||||
const QDir gameRoot;
|
||||
const QString output;
|
||||
const MMCZip::FilterFileFunction filter;
|
||||
const int m_recommendedRAM;
|
||||
|
||||
struct ResolvedFile {
|
||||
int addonId;
|
||||
@ -72,6 +67,9 @@ class FlamePackExportTask : public Task {
|
||||
bool isMod;
|
||||
};
|
||||
|
||||
FlamePackExportOptions m_options;
|
||||
QDir m_gameRoot;
|
||||
|
||||
FlameAPI api;
|
||||
|
||||
QFileInfoList files;
|
||||
|
@ -71,6 +71,7 @@
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
#include <QWidgetAction>
|
||||
#include <memory>
|
||||
|
||||
#include <BaseInstance.h>
|
||||
#include <BuildConfig.h>
|
||||
@ -1419,15 +1420,18 @@ void MainWindow::on_actionExportInstanceZip_triggered()
|
||||
void MainWindow::on_actionExportInstanceMrPack_triggered()
|
||||
{
|
||||
if (m_selectedInstance) {
|
||||
ExportPackDialog dlg(m_selectedInstance, this);
|
||||
dlg.exec();
|
||||
auto instance = std::dynamic_pointer_cast<MinecraftInstance>(m_selectedInstance);
|
||||
if (instance != nullptr) {
|
||||
ExportPackDialog dlg(instance, this);
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionExportInstanceFlamePack_triggered()
|
||||
{
|
||||
if (m_selectedInstance) {
|
||||
auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance.get());
|
||||
auto instance = std::dynamic_pointer_cast<MinecraftInstance>(m_selectedInstance);
|
||||
if (instance) {
|
||||
if (auto cmp = instance->getPackProfile()->getComponent("net.minecraft");
|
||||
cmp && cmp->getVersionFile() && cmp->getVersionFile()->type == "snapshot") {
|
||||
@ -1436,7 +1440,7 @@ void MainWindow::on_actionExportInstanceFlamePack_triggered()
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
ExportPackDialog dlg(m_selectedInstance, this, ModPlatform::ResourceProvider::FLAME);
|
||||
ExportPackDialog dlg(instance, this, ModPlatform::ResourceProvider::FLAME);
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "ExportPackDialog.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
#include "minecraft/mod/ResourceFolderModel.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "modplatform/flame/FlamePackExportTask.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
@ -33,7 +33,7 @@
|
||||
#include "MMCZip.h"
|
||||
#include "modplatform/modrinth/ModrinthPackExportTask.h"
|
||||
|
||||
ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider)
|
||||
ExportPackDialog::ExportPackDialog(MinecraftInstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider)
|
||||
: QDialog(parent), m_instance(instance), m_ui(new Ui::ExportPackDialog), m_provider(provider)
|
||||
{
|
||||
Q_ASSERT(m_provider == ModPlatform::ResourceProvider::MODRINTH || m_provider == ModPlatform::ResourceProvider::FLAME);
|
||||
@ -172,10 +172,18 @@ void ExportPackDialog::done(int result)
|
||||
task = new ModrinthPackExportTask(name, m_ui->version->text(), m_ui->summary->toPlainText(), m_ui->optionalFiles->isChecked(),
|
||||
m_instance, output, std::bind(&FileIgnoreProxy::filterFile, m_proxy, std::placeholders::_1));
|
||||
} else {
|
||||
int recommendedRAM = m_ui->recommendedMemoryCheckBox->isChecked() ? m_ui->recommendedMemory->value() : 0;
|
||||
FlamePackExportOptions options{};
|
||||
|
||||
task = new FlamePackExportTask(name, m_ui->version->text(), m_ui->author->text(), m_ui->optionalFiles->isChecked(), m_instance,
|
||||
output, std::bind(&FileIgnoreProxy::filterFile, m_proxy, std::placeholders::_1), recommendedRAM);
|
||||
options.name = name;
|
||||
options.version = m_ui->version->text();
|
||||
options.author = m_ui->author->text();
|
||||
options.optionalFiles = m_ui->optionalFiles->isChecked();
|
||||
options.instance = m_instance;
|
||||
options.output = output;
|
||||
options.filter = std::bind(&FileIgnoreProxy::filterFile, m_proxy, std::placeholders::_1);
|
||||
options.recommendedRAM = m_ui->recommendedMemoryCheckBox->isChecked() ? m_ui->recommendedMemory->value() : 0;
|
||||
|
||||
task = new FlamePackExportTask(std::move(options));
|
||||
}
|
||||
|
||||
connect(task, &Task::failed,
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "BaseInstance.h"
|
||||
#include "FastFileIconProvider.h"
|
||||
#include "FileIgnoreProxy.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -32,7 +33,7 @@ class ExportPackDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExportPackDialog(InstancePtr instance,
|
||||
explicit ExportPackDialog(MinecraftInstancePtr instance,
|
||||
QWidget* parent = nullptr,
|
||||
ModPlatform::ResourceProvider provider = ModPlatform::ResourceProvider::MODRINTH);
|
||||
~ExportPackDialog();
|
||||
@ -44,7 +45,7 @@ class ExportPackDialog : public QDialog {
|
||||
QString ignoreFileName();
|
||||
|
||||
private:
|
||||
const InstancePtr m_instance;
|
||||
const MinecraftInstancePtr m_instance;
|
||||
Ui::ExportPackDialog* m_ui;
|
||||
FileIgnoreProxy* m_proxy;
|
||||
FastFileIconProvider m_icons;
|
||||
|
Reference in New Issue
Block a user