Improvements and refinements to pack export
- Persist fields - Toggle optional files Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
3aba7f8fec
commit
5056a51c18
@ -194,6 +194,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);
|
||||||
|
@ -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())
|
||||||
@ -407,7 +409,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;
|
||||||
|
@ -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;
|
||||||
|
@ -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())
|
||||||
@ -267,16 +269,18 @@ QByteArray ModrinthPackExportTask::generateIndex()
|
|||||||
QString path = iterator.key();
|
QString path = iterator.key();
|
||||||
const ResolvedFile& value = iterator.value();
|
const ResolvedFile& value = iterator.value();
|
||||||
|
|
||||||
// detect disabled mod
|
if (optionalFiles) {
|
||||||
const QFileInfo pathInfo(path);
|
// detect disabled mod
|
||||||
if (pathInfo.suffix() == "disabled") {
|
const QFileInfo pathInfo(path);
|
||||||
// rename it
|
if (pathInfo.suffix() == "disabled") {
|
||||||
path = pathInfo.dir().filePath(pathInfo.completeBaseName());
|
// rename it
|
||||||
// ...and make it optional
|
path = pathInfo.dir().filePath(pathInfo.completeBaseName());
|
||||||
QJsonObject env;
|
// ...and make it optional
|
||||||
env["client"] = "optional";
|
QJsonObject env;
|
||||||
env["server"] = "optional";
|
env["client"] = "optional";
|
||||||
fileOut["env"] = env;
|
env["server"] = "optional";
|
||||||
|
fileOut["env"] = env;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileOut["path"] = path;
|
fileOut["path"] = path;
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
@ -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>&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>&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>&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>&Version</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>version</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -57,31 +63,52 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="filesLabel">
|
<widget class="QGroupBox" name="options">
|
||||||
<property name="text">
|
<property name="title">
|
||||||
<string>Files</string>
|
<string>&Options</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
</item>
|
<item>
|
||||||
<item>
|
<widget class="QLabel" name="filesLabel">
|
||||||
<widget class="QTreeView" name="treeView">
|
<property name="text">
|
||||||
<property name="alternatingRowColors">
|
<string>&Files</string>
|
||||||
<bool>true</bool>
|
</property>
|
||||||
</property>
|
<property name="buddy">
|
||||||
<property name="selectionMode">
|
<cstring>files</cstring>
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
<property name="sortingEnabled">
|
</item>
|
||||||
<bool>true</bool>
|
<item>
|
||||||
</property>
|
<widget class="QTreeView" name="files">
|
||||||
<attribute name="headerStretchLastSection">
|
<property name="alternatingRowColors">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</attribute>
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sortingEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="headerStretchLastSection">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="optionalFiles">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Mark disabled files as optional</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user