feat:managed packs can update from file

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-07-18 23:40:03 +03:00
parent b9568279dc
commit 5eec0f5901
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
3 changed files with 61 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include "ManagedPackPage.h"
#include "ui_ManagedPackPage.h"
#include <QFileDialog>
#include <QListView>
#include <QProxyStyle>
#include <QStyleFactory>
@ -205,6 +206,7 @@ ModrinthManagedPackPage::ModrinthManagedPackPage(BaseInstance* inst, InstanceWin
Q_ASSERT(inst->isManagedPack());
connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion()));
connect(ui->updateButton, &QPushButton::clicked, this, &ModrinthManagedPackPage::update);
connect(ui->updateFromFileButton, &QPushButton::clicked, this, &ModrinthManagedPackPage::updateFromFile);
}
// MODRINTH
@ -332,6 +334,27 @@ void ModrinthManagedPackPage::update()
m_instance_window->close();
}
void ModrinthManagedPackPage::updateFromFile()
{
auto output = QFileDialog::getOpenFileUrl(this, tr("Choose update file"), QDir::homePath(), "Modrinth pack (*.mrpack *.zip)");
QMap<QString, QString> extra_info;
extra_info.insert("pack_id", m_inst->getManagedPackID());
extra_info.insert("pack_version_id", QString());
extra_info.insert("original_instance_id", m_inst->id());
auto extracted = new InstanceImportTask(output, this, std::move(extra_info));
extracted->setName(m_inst->name());
extracted->setGroup(APPLICATION->instances()->getInstanceGroup(m_inst->id()));
extracted->setIcon(m_inst->iconKey());
extracted->setConfirmUpdate(false);
auto did_succeed = runUpdateTask(extracted);
if (m_instance_window && did_succeed)
m_instance_window->close();
}
// FLAME
FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent)
@ -340,6 +363,7 @@ FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* i
Q_ASSERT(inst->isManagedPack());
connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion()));
connect(ui->updateButton, &QPushButton::clicked, this, &FlameManagedPackPage::update);
connect(ui->updateFromFileButton, &QPushButton::clicked, this, &FlameManagedPackPage::updateFromFile);
}
void FlameManagedPackPage::parseManagedPack()
@ -474,4 +498,25 @@ void FlameManagedPackPage::update()
m_instance_window->close();
}
void FlameManagedPackPage::updateFromFile()
{
auto output = QFileDialog::getOpenFileUrl(this, tr("Choose update file"), QDir::homePath(), "CurseForge pack (*.zip)");
QMap<QString, QString> extra_info;
extra_info.insert("pack_id", m_inst->getManagedPackID());
extra_info.insert("pack_version_id", QString());
extra_info.insert("original_instance_id", m_inst->id());
auto extracted = new InstanceImportTask(output, this, std::move(extra_info));
extracted->setName(m_inst->name());
extracted->setGroup(APPLICATION->instances()->getInstanceGroup(m_inst->id()));
extracted->setIcon(m_inst->iconKey());
extracted->setConfirmUpdate(false);
auto did_succeed = runUpdateTask(extracted);
if (m_instance_window && did_succeed)
m_instance_window->close();
}
#include "ManagedPackPage.moc"

View File

@ -65,6 +65,7 @@ class ManagedPackPage : public QWidget, public BasePage {
virtual void suggestVersion();
virtual void update(){};
virtual void updateFromFile(){};
protected slots:
/** Does the necessary UI changes for when something failed.
@ -123,6 +124,7 @@ class ModrinthManagedPackPage final : public ManagedPackPage {
void suggestVersion() override;
void update() override;
void updateFromFile() override;
private:
NetJob::Ptr m_fetch_job = nullptr;
@ -145,6 +147,7 @@ class FlameManagedPackPage final : public ManagedPackPage {
void suggestVersion() override;
void update() override;
void updateFromFile() override;
private:
NetJob::Ptr m_fetch_job = nullptr;

View File

@ -153,6 +153,19 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateFromFileButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Update from file</string>
</property>
</widget>
</item>
</layout>
</item>
<item>