Merge pull request #1405 from Trial97/update_file

Allow updating managed packs from local file
This commit is contained in:
Alexandru Ionut Tripon 2023-10-10 16:17:08 +01:00 committed by GitHub
commit ca4b58d5d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <QUrlQuery> #include <QUrlQuery>
#include "ui_ManagedPackPage.h" #include "ui_ManagedPackPage.h"
#include <QFileDialog>
#include <QListView> #include <QListView>
#include <QProxyStyle> #include <QProxyStyle>
#include <QStyleFactory> #include <QStyleFactory>
@ -223,6 +224,7 @@ ModrinthManagedPackPage::ModrinthManagedPackPage(BaseInstance* inst, InstanceWin
Q_ASSERT(inst->isManagedPack()); Q_ASSERT(inst->isManagedPack());
connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion())); connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion()));
connect(ui->updateButton, &QPushButton::clicked, this, &ModrinthManagedPackPage::update); connect(ui->updateButton, &QPushButton::clicked, this, &ModrinthManagedPackPage::update);
connect(ui->updateFromFileButton, &QPushButton::clicked, this, &ModrinthManagedPackPage::updateFromFile);
} }
// MODRINTH // MODRINTH
@ -350,6 +352,27 @@ void ModrinthManagedPackPage::update()
m_instance_window->close(); 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 // FLAME
FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent) FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent)
@ -358,6 +381,7 @@ FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* i
Q_ASSERT(inst->isManagedPack()); Q_ASSERT(inst->isManagedPack());
connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion())); connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion()));
connect(ui->updateButton, &QPushButton::clicked, this, &FlameManagedPackPage::update); connect(ui->updateButton, &QPushButton::clicked, this, &FlameManagedPackPage::update);
connect(ui->updateFromFileButton, &QPushButton::clicked, this, &FlameManagedPackPage::updateFromFile);
} }
void FlameManagedPackPage::parseManagedPack() void FlameManagedPackPage::parseManagedPack()
@ -492,4 +516,25 @@ void FlameManagedPackPage::update()
m_instance_window->close(); 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" #include "ManagedPackPage.moc"

View File

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

View File

@ -153,6 +153,19 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
<item> <item>