Merge pull request #1519 from TheKodeToad/better-export-pack

This commit is contained in:
Sefa Eyeoglu 2023-08-28 10:29:32 +02:00 committed by GitHub
commit fbf6833124
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 129 additions and 66 deletions

View File

@ -195,6 +195,12 @@ void MinecraftInstance::loadSpecificSettings()
m_settings->registerSetting("UseAccountForInstance", false); m_settings->registerSetting("UseAccountForInstance", false);
m_settings->registerSetting("InstanceAccountId", ""); m_settings->registerSetting("InstanceAccountId", "");
m_settings->registerSetting("ExportName", "");
m_settings->registerSetting("ExportVersion", "1.0.0");
m_settings->registerSetting("ExportSummary", "");
m_settings->registerSetting("ExportAuthor", "");
m_settings->registerSetting("ExportOptionalFiles", true);
qDebug() << "Instance-type specific settings were loaded!"; qDebug() << "Instance-type specific settings were loaded!";
setSpecificSettingsLoaded(true); setSpecificSettingsLoaded(true);

View File

@ -43,12 +43,14 @@ const QStringList FlamePackExportTask::FILE_EXTENSIONS({ "jar", "zip" });
FlamePackExportTask::FlamePackExportTask(const QString& name, FlamePackExportTask::FlamePackExportTask(const QString& name,
const QString& version, const QString& version,
const QString& author, const QString& author,
bool optionalFiles,
InstancePtr instance, InstancePtr instance,
const QString& output, const QString& output,
MMCZip::FilterFunction filter) MMCZip::FilterFunction filter)
: name(name) : name(name)
, version(version) , version(version)
, author(author) , author(author)
, optionalFiles(optionalFiles)
, instance(instance) , instance(instance)
, mcInstance(dynamic_cast<MinecraftInstance*>(instance.get())) , mcInstance(dynamic_cast<MinecraftInstance*>(instance.get()))
, gameRoot(instance->gameRoot()) , gameRoot(instance->gameRoot())
@ -410,7 +412,7 @@ QByteArray FlamePackExportTask::generateIndex()
QJsonObject file; QJsonObject file;
file["projectID"] = mod.addonId; file["projectID"] = mod.addonId;
file["fileID"] = mod.version; file["fileID"] = mod.version;
file["required"] = mod.enabled; file["required"] = mod.enabled || !optionalFiles;
files << file; files << file;
} }
obj["files"] = files; obj["files"] = files;

View File

@ -30,6 +30,7 @@ class FlamePackExportTask : public Task {
FlamePackExportTask(const QString& name, FlamePackExportTask(const QString& name,
const QString& version, const QString& version,
const QString& author, const QString& author,
bool optionalFiles,
InstancePtr instance, InstancePtr instance,
const QString& output, const QString& output,
MMCZip::FilterFunction filter); MMCZip::FilterFunction filter);
@ -44,6 +45,7 @@ class FlamePackExportTask : public Task {
// inputs // inputs
const QString name, version, author; const QString name, version, author;
const bool optionalFiles;
const InstancePtr instance; const InstancePtr instance;
MinecraftInstance* mcInstance; MinecraftInstance* mcInstance;
const QDir gameRoot; const QDir gameRoot;

View File

@ -33,12 +33,14 @@ const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "z
ModrinthPackExportTask::ModrinthPackExportTask(const QString& name, ModrinthPackExportTask::ModrinthPackExportTask(const QString& name,
const QString& version, const QString& version,
const QString& summary, const QString& summary,
bool optionalFiles,
InstancePtr instance, InstancePtr instance,
const QString& output, const QString& output,
MMCZip::FilterFunction filter) MMCZip::FilterFunction filter)
: name(name) : name(name)
, version(version) , version(version)
, summary(summary) , summary(summary)
, optionalFiles(optionalFiles)
, instance(instance) , instance(instance)
, mcInstance(dynamic_cast<MinecraftInstance*>(instance.get())) , mcInstance(dynamic_cast<MinecraftInstance*>(instance.get()))
, gameRoot(instance->gameRoot()) , gameRoot(instance->gameRoot())
@ -270,6 +272,7 @@ QByteArray ModrinthPackExportTask::generateIndex()
QString path = iterator.key(); QString path = iterator.key();
const ResolvedFile& value = iterator.value(); const ResolvedFile& value = iterator.value();
if (optionalFiles) {
// detect disabled mod // detect disabled mod
const QFileInfo pathInfo(path); const QFileInfo pathInfo(path);
if (pathInfo.suffix() == "disabled") { if (pathInfo.suffix() == "disabled") {
@ -281,6 +284,7 @@ QByteArray ModrinthPackExportTask::generateIndex()
env["server"] = "optional"; env["server"] = "optional";
fileOut["env"] = env; fileOut["env"] = env;
} }
}
fileOut["path"] = path; fileOut["path"] = path;
fileOut["downloads"] = QJsonArray{ iterator.value().url }; fileOut["downloads"] = QJsonArray{ iterator.value().url };

View File

@ -31,6 +31,7 @@ class ModrinthPackExportTask : public Task {
ModrinthPackExportTask(const QString& name, ModrinthPackExportTask(const QString& name,
const QString& version, const QString& version,
const QString& summary, const QString& summary,
bool optionalFiles,
InstancePtr instance, InstancePtr instance,
const QString& output, const QString& output,
MMCZip::FilterFunction filter); MMCZip::FilterFunction filter);
@ -50,6 +51,7 @@ class ModrinthPackExportTask : public Task {
// inputs // inputs
const QString name, version, summary; const QString name, version, summary;
const bool optionalFiles;
const InstancePtr instance; const InstancePtr instance;
MinecraftInstance* mcInstance; MinecraftInstance* mcInstance;
const QDir gameRoot; const QDir gameRoot;

View File

@ -37,15 +37,21 @@
ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider) ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider)
: QDialog(parent), instance(instance), ui(new Ui::ExportPackDialog), m_provider(provider) : QDialog(parent), instance(instance), ui(new Ui::ExportPackDialog), m_provider(provider)
{ {
Q_ASSERT(m_provider == ModPlatform::ResourceProvider::MODRINTH || m_provider == ModPlatform::ResourceProvider::FLAME);
ui->setupUi(this); ui->setupUi(this);
ui->name->setText(instance->name()); ui->name->setPlaceholderText(instance->name());
ui->name->setText(instance->settings()->get("ExportName").toString());
ui->version->setText(instance->settings()->get("ExportVersion").toString());
ui->optionalFiles->setChecked(instance->settings()->get("ExportOptionalFiles").toBool());
if (m_provider == ModPlatform::ResourceProvider::MODRINTH) { if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
ui->summary->setText(instance->notes().split(QRegularExpression("\\r?\\n"))[0]); setWindowTitle(tr("Export Modrinth Pack"));
setWindowTitle("Export Modrinth Pack"); ui->summary->setText(instance->settings()->get("ExportSummary").toString());
} else { } else {
setWindowTitle("Export CurseForge Pack"); setWindowTitle(tr("Export CurseForge Pack"));
ui->version->setText(""); ui->summaryLabel->setText(tr("&Author"));
ui->summaryLabel->setText("Author"); ui->summary->setText(instance->settings()->get("ExportAuthor").toString());
} }
// ensure a valid pack is generated // ensure a valid pack is generated
@ -81,14 +87,14 @@ ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPla
proxy->blockedPaths().insert(root.relativeFilePath(index.absolutePath())); proxy->blockedPaths().insert(root.relativeFilePath(index.absolutePath()));
} }
ui->treeView->setModel(proxy); ui->files->setModel(proxy);
ui->treeView->setRootIndex(proxy->mapFromSource(model->index(instance->gameRoot()))); ui->files->setRootIndex(proxy->mapFromSource(model->index(instance->gameRoot())));
ui->treeView->sortByColumn(0, Qt::AscendingOrder); ui->files->sortByColumn(0, Qt::AscendingOrder);
model->setFilter(filter); model->setFilter(filter);
model->setRootPath(instance->gameRoot()); model->setRootPath(instance->gameRoot());
QHeaderView* headerView = ui->treeView->header(); QHeaderView* headerView = ui->files->header();
headerView->setSectionResizeMode(QHeaderView::ResizeToContents); headerView->setSectionResizeMode(QHeaderView::ResizeToContents);
headerView->setSectionResizeMode(0, QHeaderView::Stretch); headerView->setSectionResizeMode(0, QHeaderView::Stretch);
} }
@ -100,26 +106,40 @@ ExportPackDialog::~ExportPackDialog()
void ExportPackDialog::done(int result) void ExportPackDialog::done(int result)
{ {
auto settings = instance->settings();
settings->set("ExportName", ui->name->text());
settings->set("ExportVersion", ui->version->text());
settings->set(m_provider == ModPlatform::ResourceProvider::FLAME ? "ExportAuthor" : "ExportSummary", ui->summary->text());
settings->set("ExportOptionalFiles", ui->optionalFiles->isChecked());
if (result == Accepted) { if (result == Accepted) {
const QString filename = FS::RemoveInvalidFilenameChars(ui->name->text()); const QString name = ui->name->text().isEmpty() ? instance->name() : ui->name->text();
const QString filename = FS::RemoveInvalidFilenameChars(name);
QString output; QString output;
if (m_provider == ModPlatform::ResourceProvider::MODRINTH) if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()), output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + ".mrpack"),
FS::PathCombine(QDir::homePath(), filename + ".mrpack"), "Modrinth pack (*.mrpack *.zip)", "Modrinth pack (*.mrpack *.zip)", nullptr);
nullptr); if (!(output.endsWith(".zip") || output.endsWith(".mrpack")))
else output.append(".mrpack");
output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()), } else {
FS::PathCombine(QDir::homePath(), filename + ".zip"), "CurseForge pack (*.zip)", nullptr); output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + ".zip"),
"CurseForge pack (*.zip)", nullptr);
if (!output.endsWith(".zip"))
output.append(".zip");
}
if (output.isEmpty()) if (output.isEmpty())
return; return;
Task* task; Task* task;
if (m_provider == ModPlatform::ResourceProvider::MODRINTH) if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
task = new ModrinthPackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output, task = new ModrinthPackExportTask(name, ui->version->text(), ui->summary->text(), ui->optionalFiles->isChecked(), instance,
std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1)); output, std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
else } else {
task = new FlamePackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output, task = new FlamePackExportTask(name, ui->version->text(), ui->summary->text(), ui->optionalFiles->isChecked(), instance, output,
std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1)); std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
}
connect(task, &Task::failed, connect(task, &Task::failed,
[this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); [this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
@ -140,7 +160,6 @@ void ExportPackDialog::done(int result)
void ExportPackDialog::validate() void ExportPackDialog::validate()
{ {
const bool invalid = ui->buttonBox->button(QDialogButtonBox::Ok)
ui->name->text().isEmpty() || ((m_provider == ModPlatform::ResourceProvider::MODRINTH) && ui->version->text().isEmpty()); ->setDisabled(m_provider == ModPlatform::ResourceProvider::MODRINTH && ui->version->text().isEmpty());
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(invalid);
} }

View File

@ -7,12 +7,9 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>650</width> <width>650</width>
<height>413</height> <height>510</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Export Pack</string>
</property>
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -20,13 +17,16 @@
<item> <item>
<widget class="QGroupBox" name="information"> <widget class="QGroupBox" name="information">
<property name="title"> <property name="title">
<string>Information</string> <string>&amp;Description</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="summaryLabel"> <widget class="QLabel" name="summaryLabel">
<property name="text"> <property name="text">
<string>Summary</string> <string>&amp;Summary</string>
</property>
<property name="buddy">
<cstring>summary</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -36,14 +36,20 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="nameLabel"> <widget class="QLabel" name="nameLabel">
<property name="text"> <property name="text">
<string>Name</string> <string>&amp;Name</string>
</property>
<property name="buddy">
<cstring>name</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="versionLabel"> <widget class="QLabel" name="versionLabel">
<property name="text"> <property name="text">
<string>Version</string> <string>&amp;Version</string>
</property>
<property name="buddy">
<cstring>version</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -57,19 +63,27 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="options">
<property name="title">
<string>&amp;Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="filesLabel"> <widget class="QLabel" name="filesLabel">
<property name="text"> <property name="text">
<string>Files</string> <string>&amp;Files</string>
</property>
<property name="buddy">
<cstring>files</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTreeView" name="treeView"> <widget class="QTreeView" name="files">
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -84,6 +98,19 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="optionalFiles">
<property name="text">
<string>&amp;Mark disabled files as optional</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">
@ -97,7 +124,8 @@
<tabstop>name</tabstop> <tabstop>name</tabstop>
<tabstop>version</tabstop> <tabstop>version</tabstop>
<tabstop>summary</tabstop> <tabstop>summary</tabstop>
<tabstop>treeView</tabstop> <tabstop>files</tabstop>
<tabstop>optionalFiles</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>