Pull in BaseInstaller related changes from quickmod
This commit is contained in:
parent
e5b4dee1c0
commit
e95619fa67
@ -221,45 +221,10 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
|
|||||||
m_inst->currentVersionId());
|
m_inst->currentVersionId());
|
||||||
if (vselect.exec() && vselect.selectedVersion())
|
if (vselect.exec() && vselect.selectedVersion())
|
||||||
{
|
{
|
||||||
ForgeVersionPtr forgeVersion =
|
ProgressDialog dialog(this);
|
||||||
std::dynamic_pointer_cast<ForgeVersion>(vselect.selectedVersion());
|
dialog.exec(ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
|
||||||
if (!forgeVersion)
|
|
||||||
return;
|
|
||||||
auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename);
|
|
||||||
if (entry->stale)
|
|
||||||
{
|
|
||||||
NetJob *fjob = new NetJob("Forge download");
|
|
||||||
fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry));
|
|
||||||
ProgressDialog dlg(this);
|
|
||||||
dlg.exec(fjob);
|
|
||||||
if (dlg.result() == QDialog::Accepted)
|
|
||||||
{
|
|
||||||
// install
|
|
||||||
QString forgePath = entry->getFullPath();
|
|
||||||
ForgeInstaller forge(forgePath, forgeVersion->universal_url);
|
|
||||||
if (!forge.add(m_inst))
|
|
||||||
{
|
|
||||||
QLOG_ERROR() << "Failure installing forge";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// failed to download forge :/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// install
|
|
||||||
QString forgePath = entry->getFullPath();
|
|
||||||
ForgeInstaller forge(forgePath, forgeVersion->universal_url);
|
|
||||||
if (!forge.add(m_inst))
|
|
||||||
{
|
|
||||||
QLOG_ERROR() << "Failure installing forge";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reloadInstanceVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OneSixModEditDialog::on_liteloaderBtn_clicked()
|
void OneSixModEditDialog::on_liteloaderBtn_clicked()
|
||||||
{
|
{
|
||||||
@ -281,21 +246,8 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
|
|||||||
m_inst->currentVersionId());
|
m_inst->currentVersionId());
|
||||||
if (vselect.exec() && vselect.selectedVersion())
|
if (vselect.exec() && vselect.selectedVersion())
|
||||||
{
|
{
|
||||||
LiteLoaderVersionPtr liteloaderVersion =
|
ProgressDialog dialog(this);
|
||||||
std::dynamic_pointer_cast<LiteLoaderVersion>(vselect.selectedVersion());
|
dialog.exec(LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
|
||||||
if (!liteloaderVersion)
|
|
||||||
return;
|
|
||||||
LiteLoaderInstaller liteloader(liteloaderVersion);
|
|
||||||
if (!liteloader.add(m_inst))
|
|
||||||
{
|
|
||||||
QMessageBox::critical(this, tr("LiteLoader"),
|
|
||||||
tr("For reasons unknown, the LiteLoader installation failed. "
|
|
||||||
"Check your MultiMC log files for details."));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reloadInstanceVersion();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
class OneSixInstance;
|
class OneSixInstance;
|
||||||
class QDir;
|
class QDir;
|
||||||
class QString;
|
class QString;
|
||||||
|
class QObject;
|
||||||
|
class ProgressProvider;
|
||||||
|
class BaseVersion;
|
||||||
|
typedef std::shared_ptr<BaseVersion> BaseVersionPtr;
|
||||||
|
|
||||||
class BaseInstaller
|
class BaseInstaller
|
||||||
{
|
{
|
||||||
@ -31,6 +35,8 @@ public:
|
|||||||
virtual bool add(OneSixInstance *to);
|
virtual bool add(OneSixInstance *to);
|
||||||
virtual bool remove(OneSixInstance *from);
|
virtual bool remove(OneSixInstance *from);
|
||||||
|
|
||||||
|
virtual ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QString id() const = 0;
|
virtual QString id() const = 0;
|
||||||
QString filename(const QString &root) const;
|
QString filename(const QString &root) const;
|
||||||
|
@ -24,17 +24,24 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
#include "MultiMC.h"
|
#include "MultiMC.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
#include "OneSixInstance.h"
|
#include "OneSixInstance.h"
|
||||||
|
#include "lists/ForgeVersionList.h"
|
||||||
|
#include "gui/dialogs/ProgressDialog.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
|
ForgeInstaller::ForgeInstaller()
|
||||||
|
: BaseInstaller()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void ForgeInstaller::prepare(const QString &filename, const QString &universalUrl)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VersionFinal> newVersion;
|
std::shared_ptr<VersionFinal> newVersion;
|
||||||
m_universal_url = universal_url;
|
m_universal_url = universalUrl;
|
||||||
|
|
||||||
QuaZip zip(filename);
|
QuaZip zip(filename);
|
||||||
if (!zip.open(QuaZip::mdUnzip))
|
if (!zip.open(QuaZip::mdUnzip))
|
||||||
@ -111,7 +118,6 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
|
|||||||
m_forge_version = newVersion;
|
m_forge_version = newVersion;
|
||||||
realVersionId = m_forge_version->id = installObj.value("minecraft").toString();
|
realVersionId = m_forge_version->id = installObj.value("minecraft").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ForgeInstaller::add(OneSixInstance *to)
|
bool ForgeInstaller::add(OneSixInstance *to)
|
||||||
{
|
{
|
||||||
if (!BaseInstaller::add(to))
|
if (!BaseInstaller::add(to))
|
||||||
@ -226,3 +232,96 @@ bool ForgeInstaller::add(OneSixInstance *to)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ForgeInstallTask : public Task
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ForgeInstallTask(ForgeInstaller *installer, OneSixInstance *instance, BaseVersionPtr version, QObject *parent = 0)
|
||||||
|
: Task(parent), m_installer(installer), m_instance(instance), m_version(version)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void executeTask() override
|
||||||
|
{
|
||||||
|
{
|
||||||
|
setStatus(tr("Installing forge..."));
|
||||||
|
ForgeVersionPtr forgeVersion =
|
||||||
|
std::dynamic_pointer_cast<ForgeVersion>(m_version);
|
||||||
|
if (!forgeVersion)
|
||||||
|
{
|
||||||
|
emitFailed(tr("Unknown error occured"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename);
|
||||||
|
if (entry->stale)
|
||||||
|
{
|
||||||
|
NetJob *fjob = new NetJob("Forge download");
|
||||||
|
fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry));
|
||||||
|
connect(fjob, &NetJob::progress, [this](qint64 current, qint64 total){setProgress(100 * current / qMax((qint64)1, total));});
|
||||||
|
connect(fjob, &NetJob::status, [this](const QString &msg){setStatus(msg);});
|
||||||
|
connect(fjob, &NetJob::failed, [this](){emitFailed(tr("Failure to download forge"));});
|
||||||
|
connect(fjob, &NetJob::succeeded, [this, entry, forgeVersion]()
|
||||||
|
{
|
||||||
|
if (!install(entry, forgeVersion))
|
||||||
|
{
|
||||||
|
QLOG_ERROR() << "Failure installing forge";
|
||||||
|
emitFailed(tr("Failure to install forge"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!install(entry, forgeVersion))
|
||||||
|
{
|
||||||
|
QLOG_ERROR() << "Failure installing forge";
|
||||||
|
emitFailed(tr("Failure to install forge"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool install(const std::shared_ptr<MetaEntry> &entry, const ForgeVersionPtr &forgeVersion)
|
||||||
|
{
|
||||||
|
QString forgePath = entry->getFullPath();
|
||||||
|
m_installer->prepare(forgePath, forgeVersion->universal_url);
|
||||||
|
return m_installer->add(m_instance);
|
||||||
|
}
|
||||||
|
void reload()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_instance->reloadVersion();
|
||||||
|
emitSucceeded();
|
||||||
|
}
|
||||||
|
catch (MMCError &e)
|
||||||
|
{
|
||||||
|
emitFailed(e.cause());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
emitFailed(tr("Failed to load the version description file for reasons unknown."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ForgeInstaller *m_installer;
|
||||||
|
OneSixInstance *m_instance;
|
||||||
|
BaseVersionPtr m_version;
|
||||||
|
};
|
||||||
|
|
||||||
|
ProgressProvider *ForgeInstaller::createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent)
|
||||||
|
{
|
||||||
|
return new ForgeInstallTask(this, instance, version, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "ForgeInstaller.moc"
|
||||||
|
@ -25,12 +25,15 @@ class VersionFinal;
|
|||||||
class ForgeInstaller : public BaseInstaller
|
class ForgeInstaller : public BaseInstaller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ForgeInstaller(QString filename, QString universal_url);
|
ForgeInstaller();
|
||||||
|
|
||||||
|
void prepare(const QString &filename, const QString &universalUrl);
|
||||||
bool add(OneSixInstance *to) override;
|
bool add(OneSixInstance *to) override;
|
||||||
|
|
||||||
QString id() const override { return "net.minecraftforge"; }
|
QString id() const override { return "net.minecraftforge"; }
|
||||||
|
|
||||||
|
ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// the version, read from the installer
|
// the version, read from the installer
|
||||||
std::shared_ptr<VersionFinal> m_forge_version;
|
std::shared_ptr<VersionFinal> m_forge_version;
|
||||||
|
@ -23,12 +23,17 @@
|
|||||||
#include "VersionFinal.h"
|
#include "VersionFinal.h"
|
||||||
#include "OneSixLibrary.h"
|
#include "OneSixLibrary.h"
|
||||||
#include "OneSixInstance.h"
|
#include "OneSixInstance.h"
|
||||||
|
#include "MultiMC.h"
|
||||||
|
#include "lists/LiteLoaderVersionList.h"
|
||||||
|
|
||||||
LiteLoaderInstaller::LiteLoaderInstaller(LiteLoaderVersionPtr version)
|
LiteLoaderInstaller::LiteLoaderInstaller() : BaseInstaller()
|
||||||
: BaseInstaller(), m_version(version)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LiteLoaderInstaller::prepare(LiteLoaderVersionPtr version)
|
||||||
|
{
|
||||||
|
m_version = version;
|
||||||
|
}
|
||||||
bool LiteLoaderInstaller::add(OneSixInstance *to)
|
bool LiteLoaderInstaller::add(OneSixInstance *to)
|
||||||
{
|
{
|
||||||
if (!BaseInstaller::add(to))
|
if (!BaseInstaller::add(to))
|
||||||
@ -84,3 +89,62 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LiteLoaderInstallTask : public Task
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
LiteLoaderInstallTask(LiteLoaderInstaller *installer, OneSixInstance *instance,
|
||||||
|
BaseVersionPtr version, QObject *parent)
|
||||||
|
: Task(parent), m_installer(installer), m_instance(instance), m_version(version)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void executeTask() override
|
||||||
|
{
|
||||||
|
LiteLoaderVersionPtr liteloaderVersion =
|
||||||
|
std::dynamic_pointer_cast<LiteLoaderVersion>(m_version);
|
||||||
|
if (!liteloaderVersion)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_installer->prepare(liteloaderVersion);
|
||||||
|
if (!m_installer->add(m_instance))
|
||||||
|
{
|
||||||
|
emitFailed(tr("For reasons unknown, the LiteLoader installation failed. Check your "
|
||||||
|
"MultiMC log files for details."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_instance->reloadVersion();
|
||||||
|
emitSucceeded();
|
||||||
|
}
|
||||||
|
catch (MMCError &e)
|
||||||
|
{
|
||||||
|
emitFailed(e.cause());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
emitFailed(
|
||||||
|
tr("Failed to load the version description file for reasons unknown."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
LiteLoaderInstaller *m_installer;
|
||||||
|
OneSixInstance *m_instance;
|
||||||
|
BaseVersionPtr m_version;
|
||||||
|
};
|
||||||
|
|
||||||
|
ProgressProvider *LiteLoaderInstaller::createInstallTask(OneSixInstance *instance,
|
||||||
|
BaseVersionPtr version,
|
||||||
|
QObject *parent)
|
||||||
|
{
|
||||||
|
return new LiteLoaderInstallTask(this, instance, version, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "LiteLoaderInstaller.moc"
|
||||||
|
@ -25,10 +25,13 @@
|
|||||||
class LiteLoaderInstaller : public BaseInstaller
|
class LiteLoaderInstaller : public BaseInstaller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LiteLoaderInstaller(LiteLoaderVersionPtr version);
|
LiteLoaderInstaller();
|
||||||
|
|
||||||
|
void prepare(LiteLoaderVersionPtr version);
|
||||||
bool add(OneSixInstance *to) override;
|
bool add(OneSixInstance *to) override;
|
||||||
|
|
||||||
|
ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual QString id() const override
|
virtual QString id() const override
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user