mirror of
https://github.com/UltimMC/Launcher.git
synced 2026-01-02 05:28:19 +00:00
GH-4699 Modrinth pack exporter (WIP)
This commit is contained in:
@@ -84,7 +84,7 @@
|
||||
#include "ui/dialogs/EditAccountDialog.h"
|
||||
#include "ui/dialogs/NotificationDialog.h"
|
||||
#include "ui/dialogs/CreateShortcutDialog.h"
|
||||
#include "ui/dialogs/ExportInstanceDialog.h"
|
||||
#include "ui/dialogs/SelectInstanceExportFormatDialog.h"
|
||||
|
||||
#include "UpdateController.h"
|
||||
#include "KonamiCode.h"
|
||||
@@ -1756,7 +1756,7 @@ void MainWindow::on_actionExportInstance_triggered()
|
||||
{
|
||||
if (m_selectedInstance)
|
||||
{
|
||||
ExportInstanceDialog dlg(m_selectedInstance, this);
|
||||
SelectInstanceExportFormatDialog dlg(m_selectedInstance, this);
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
|
||||
114
launcher/ui/dialogs/ModrinthExportDialog.cpp
Normal file
114
launcher/ui/dialogs/ModrinthExportDialog.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2023 arthomnix
|
||||
*
|
||||
* This source is subject to the Microsoft Public License (MS-PL).
|
||||
* Please see the COPYING.md file for more information.
|
||||
*/
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QProgressDialog>
|
||||
#include <QMessageBox>
|
||||
#include "ModrinthExportDialog.h"
|
||||
#include "ui_ModrinthExportDialog.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "ModrinthInstanceExportTask.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "CustomMessageBox.h"
|
||||
|
||||
|
||||
ModrinthExportDialog::ModrinthExportDialog(InstancePtr instance, QWidget *parent) :
|
||||
QDialog(parent), ui(new Ui::ModrinthExportDialog), m_instance(instance)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->name->setText(m_instance->name());
|
||||
ui->version->setText("1.0");
|
||||
}
|
||||
|
||||
void ModrinthExportDialog::updateDialogState()
|
||||
{
|
||||
ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled(
|
||||
!ui->name->text().isEmpty()
|
||||
&& !ui->version->text().isEmpty()
|
||||
&& !ui->file->text().isEmpty()
|
||||
);
|
||||
}
|
||||
|
||||
void ModrinthExportDialog::on_fileBrowseButton_clicked()
|
||||
{
|
||||
QFileDialog dialog(this, tr("Select modpack file"), QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||
dialog.setDefaultSuffix("mrpack");
|
||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
dialog.selectFile(ui->name->text() + ".mrpack");
|
||||
|
||||
if (dialog.exec()) {
|
||||
ui->file->setText(dialog.selectedFiles().at(0));
|
||||
}
|
||||
|
||||
updateDialogState();
|
||||
}
|
||||
|
||||
void ModrinthExportDialog::accept()
|
||||
{
|
||||
ModrinthExportSettings settings;
|
||||
|
||||
settings.name = ui->name->text();
|
||||
settings.version = ui->version->text();
|
||||
settings.description = ui->description->text();
|
||||
|
||||
settings.includeGameConfig = ui->includeGameConfig->isChecked();
|
||||
settings.includeModConfigs = ui->includeModConfigs->isChecked();
|
||||
settings.includeResourcePacks = ui->includeResourcePacks->isChecked();
|
||||
settings.includeShaderPacks = ui->includeShaderPacks->isChecked();
|
||||
|
||||
MinecraftInstancePtr minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(m_instance);
|
||||
minecraftInstance->getPackProfile()->reload(Net::Mode::Offline);
|
||||
|
||||
auto minecraftComponent = minecraftInstance->getPackProfile()->getComponent("net.minecraft");
|
||||
auto forgeComponent = minecraftInstance->getPackProfile()->getComponent("net.minecraftforge");
|
||||
auto fabricComponent = minecraftInstance->getPackProfile()->getComponent("net.fabricmc.fabric-loader");
|
||||
auto quiltComponent = minecraftInstance->getPackProfile()->getComponent("org.quiltmc.quilt-loader");
|
||||
|
||||
if (minecraftComponent) {
|
||||
settings.gameVersion = minecraftComponent->getVersion();
|
||||
}
|
||||
if (forgeComponent) {
|
||||
settings.forgeVersion = forgeComponent->getVersion();
|
||||
}
|
||||
if (fabricComponent) {
|
||||
settings.fabricVersion = fabricComponent->getVersion();
|
||||
}
|
||||
if (quiltComponent) {
|
||||
settings.quiltVersion = quiltComponent->getVersion();
|
||||
}
|
||||
|
||||
settings.exportPath = ui->file->text();
|
||||
|
||||
auto *task = new ModrinthInstanceExportTask(m_instance, settings);
|
||||
|
||||
connect(task, &Task::failed, [this](QString reason)
|
||||
{
|
||||
CustomMessageBox::selectable(parentWidget(), tr("Error"), reason, QMessageBox::Critical)->show();
|
||||
});
|
||||
connect(task, &Task::succeeded, [this, task]()
|
||||
{
|
||||
QStringList warnings = task->warnings();
|
||||
if(warnings.count())
|
||||
{
|
||||
CustomMessageBox::selectable(parentWidget(), tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
|
||||
}
|
||||
});
|
||||
ProgressDialog loadDialog(this);
|
||||
loadDialog.setSkipButton(true, tr("Abort"));
|
||||
loadDialog.execWithTask(task);
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
ModrinthExportDialog::~ModrinthExportDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
37
launcher/ui/dialogs/ModrinthExportDialog.h
Normal file
37
launcher/ui/dialogs/ModrinthExportDialog.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2023 arthomnix
|
||||
*
|
||||
* This source is subject to the Microsoft Public License (MS-PL).
|
||||
* Please see the COPYING.md file for more information.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "ExportInstanceDialog.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
class ModrinthExportDialog;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class ModrinthExportDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ModrinthExportDialog(InstancePtr instance, QWidget *parent = nullptr);
|
||||
|
||||
~ModrinthExportDialog() override;
|
||||
|
||||
private slots:
|
||||
void on_fileBrowseButton_clicked();
|
||||
void accept() override;
|
||||
void updateDialogState();
|
||||
|
||||
private:
|
||||
Ui::ModrinthExportDialog *ui;
|
||||
InstancePtr m_instance;
|
||||
};
|
||||
277
launcher/ui/dialogs/ModrinthExportDialog.ui
Normal file
277
launcher/ui/dialogs/ModrinthExportDialog.ui
Normal file
@@ -0,0 +1,277 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ModrinthExportDialog</class>
|
||||
<widget class="QDialog" name="ModrinthExportDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>679</width>
|
||||
<height>559</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ModrinthExportDialog</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>661</width>
|
||||
<height>541</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Export Modrinth modpack</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="metadataGroupBox">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Metadata</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>641</width>
|
||||
<height>151</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="metadataVLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="metadataFormLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="name"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="versionLabel">
|
||||
<property name="text">
|
||||
<string>Version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="descriptionLabel">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="version"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="description"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="optionsGroupBox">
|
||||
<property name="title">
|
||||
<string>Export Options</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>29</y>
|
||||
<width>641</width>
|
||||
<height>221</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="optionsLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="fileLabel">
|
||||
<property name="text">
|
||||
<string>File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="file"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="fileBrowseButton">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="includeGameConfig">
|
||||
<property name="text">
|
||||
<string>Include Minecraft config</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="includeModConfigs">
|
||||
<property name="text">
|
||||
<string>Include mod configs</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="includeResourcePacks">
|
||||
<property name="text">
|
||||
<string>Include resource packs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="includeShaderPacks">
|
||||
<property name="text">
|
||||
<string>Include shader packs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ModrinthExportDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>340</x>
|
||||
<y>532</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>338</x>
|
||||
<y>279</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ModrinthExportDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>340</x>
|
||||
<y>532</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>338</x>
|
||||
<y>279</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>name</sender>
|
||||
<signal>textChanged(QString)</signal>
|
||||
<receiver>ModrinthExportDialog</receiver>
|
||||
<slot>updateDialogState()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>395</x>
|
||||
<y>90</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>339</x>
|
||||
<y>279</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>version</sender>
|
||||
<signal>textChanged(QString)</signal>
|
||||
<receiver>ModrinthExportDialog</receiver>
|
||||
<slot>updateDialogState()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>395</x>
|
||||
<y>129</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>339</x>
|
||||
<y>279</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>file</sender>
|
||||
<signal>textChanged(QString)</signal>
|
||||
<receiver>ModrinthExportDialog</receiver>
|
||||
<slot>updateDialogState()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>309</x>
|
||||
<y>329</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>339</x>
|
||||
<y>279</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>updateDialogState()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
37
launcher/ui/dialogs/SelectInstanceExportFormatDialog.cpp
Normal file
37
launcher/ui/dialogs/SelectInstanceExportFormatDialog.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2023 arthomnix
|
||||
*
|
||||
* This source is subject to the Microsoft Public License (MS-PL).
|
||||
* Please see the COPYING.md file for more information.
|
||||
*/
|
||||
|
||||
#include "SelectInstanceExportFormatDialog.h"
|
||||
#include "ui_SelectInstanceExportFormatDialog.h"
|
||||
#include "BuildConfig.h"
|
||||
#include "ModrinthExportDialog.h"
|
||||
|
||||
|
||||
SelectInstanceExportFormatDialog::SelectInstanceExportFormatDialog(InstancePtr instance, QWidget *parent) :
|
||||
QDialog(parent), ui(new Ui::SelectInstanceExportFormatDialog), m_instance(instance)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->mmcFormat->setText(BuildConfig.LAUNCHER_NAME);
|
||||
}
|
||||
|
||||
void SelectInstanceExportFormatDialog::accept()
|
||||
{
|
||||
if (ui->mmcFormat->isChecked()) {
|
||||
ExportInstanceDialog dlg(m_instance, parentWidget());
|
||||
QDialog::accept();
|
||||
dlg.exec();
|
||||
} else if (ui->modrinthFormat->isChecked()) {
|
||||
ModrinthExportDialog dlg(m_instance, parentWidget());
|
||||
QDialog::accept();
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
|
||||
SelectInstanceExportFormatDialog::~SelectInstanceExportFormatDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
36
launcher/ui/dialogs/SelectInstanceExportFormatDialog.h
Normal file
36
launcher/ui/dialogs/SelectInstanceExportFormatDialog.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2023 arthomnix
|
||||
*
|
||||
* This source is subject to the Microsoft Public License (MS-PL).
|
||||
* Please see the COPYING.md file for more information.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "ExportInstanceDialog.h"
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
class SelectInstanceExportFormatDialog;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class SelectInstanceExportFormatDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SelectInstanceExportFormatDialog(InstancePtr instance, QWidget *parent = nullptr);
|
||||
|
||||
~SelectInstanceExportFormatDialog() override;
|
||||
|
||||
private slots:
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
Ui::SelectInstanceExportFormatDialog *ui;
|
||||
InstancePtr m_instance;
|
||||
};
|
||||
95
launcher/ui/dialogs/SelectInstanceExportFormatDialog.ui
Normal file
95
launcher/ui/dialogs/SelectInstanceExportFormatDialog.ui
Normal file
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SelectInstanceExportFormatDialog</class>
|
||||
<widget class="QDialog" name="SelectInstanceExportFormatDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>446</width>
|
||||
<height>181</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select Instance Export Format</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>421</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Select export format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="mmcFormat">
|
||||
<property name="text">
|
||||
<string>Launcher</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="modrinthFormat">
|
||||
<property name="text">
|
||||
<string>Modrinth (WIP)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SelectInstanceExportFormatDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>220</x>
|
||||
<y>152</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>222</x>
|
||||
<y>90</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SelectInstanceExportFormatDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>220</x>
|
||||
<y>152</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>222</x>
|
||||
<y>90</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user