diff options
author | Jan Dalheimer <jan@dalheimer.de> | 2014-03-14 20:48:57 +0100 |
---|---|---|
committer | Jan Dalheimer <jan@dalheimer.de> | 2014-03-14 20:48:57 +0100 |
commit | e95619fa67239b709522a66b8bb7403bb7b84098 (patch) | |
tree | edee0bdc771e1a958c239abfc8d112c38539aa42 /logic | |
parent | e5b4dee1c05d0d6ebc0d7b2dd802b93cb8765e63 (diff) | |
download | MultiMC-e95619fa67239b709522a66b8bb7403bb7b84098.tar MultiMC-e95619fa67239b709522a66b8bb7403bb7b84098.tar.gz MultiMC-e95619fa67239b709522a66b8bb7403bb7b84098.tar.lz MultiMC-e95619fa67239b709522a66b8bb7403bb7b84098.tar.xz MultiMC-e95619fa67239b709522a66b8bb7403bb7b84098.zip |
Pull in BaseInstaller related changes from quickmod
Diffstat (limited to 'logic')
-rw-r--r-- | logic/BaseInstaller.h | 6 | ||||
-rw-r--r-- | logic/ForgeInstaller.cpp | 105 | ||||
-rw-r--r-- | logic/ForgeInstaller.h | 5 | ||||
-rw-r--r-- | logic/LiteLoaderInstaller.cpp | 68 | ||||
-rw-r--r-- | logic/LiteLoaderInstaller.h | 5 |
5 files changed, 182 insertions, 7 deletions
diff --git a/logic/BaseInstaller.h b/logic/BaseInstaller.h index c572e004..d59833cc 100644 --- a/logic/BaseInstaller.h +++ b/logic/BaseInstaller.h @@ -20,6 +20,10 @@ class OneSixInstance; class QDir; class QString; +class QObject; +class ProgressProvider; +class BaseVersion; +typedef std::shared_ptr<BaseVersion> BaseVersionPtr; class BaseInstaller { @@ -31,6 +35,8 @@ public: virtual bool add(OneSixInstance *to); virtual bool remove(OneSixInstance *from); + virtual ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) = 0; + protected: virtual QString id() const = 0; QString filename(const QString &root) const; diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index 6f238c21..48bfb8a3 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -24,17 +24,24 @@ #include <QRegularExpression> #include <QRegularExpressionMatch> #include "MultiMC.h" +#include "tasks/Task.h" #include "OneSixInstance.h" +#include "lists/ForgeVersionList.h" +#include "gui/dialogs/ProgressDialog.h" #include <QJsonDocument> #include <QJsonArray> #include <QSaveFile> #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; - m_universal_url = universal_url; + m_universal_url = universalUrl; QuaZip zip(filename); if (!zip.open(QuaZip::mdUnzip)) @@ -111,7 +118,6 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url) m_forge_version = newVersion; realVersionId = m_forge_version->id = installObj.value("minecraft").toString(); } - bool ForgeInstaller::add(OneSixInstance *to) { if (!BaseInstaller::add(to)) @@ -226,3 +232,96 @@ bool ForgeInstaller::add(OneSixInstance *to) 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" diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index df029f38..05cc994b 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -25,12 +25,15 @@ class VersionFinal; class ForgeInstaller : public BaseInstaller { public: - ForgeInstaller(QString filename, QString universal_url); + ForgeInstaller(); + void prepare(const QString &filename, const QString &universalUrl); bool add(OneSixInstance *to) override; QString id() const override { return "net.minecraftforge"; } + ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; + private: // the version, read from the installer std::shared_ptr<VersionFinal> m_forge_version; diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp index bb4b07ca..99cc5643 100644 --- a/logic/LiteLoaderInstaller.cpp +++ b/logic/LiteLoaderInstaller.cpp @@ -23,12 +23,17 @@ #include "VersionFinal.h" #include "OneSixLibrary.h" #include "OneSixInstance.h" +#include "MultiMC.h" +#include "lists/LiteLoaderVersionList.h" -LiteLoaderInstaller::LiteLoaderInstaller(LiteLoaderVersionPtr version) - : BaseInstaller(), m_version(version) +LiteLoaderInstaller::LiteLoaderInstaller() : BaseInstaller() { } +void LiteLoaderInstaller::prepare(LiteLoaderVersionPtr version) +{ + m_version = version; +} bool LiteLoaderInstaller::add(OneSixInstance *to) { if (!BaseInstaller::add(to)) @@ -84,3 +89,62 @@ bool LiteLoaderInstaller::add(OneSixInstance *to) 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" diff --git a/logic/LiteLoaderInstaller.h b/logic/LiteLoaderInstaller.h index 2e0de64a..3ab5acb2 100644 --- a/logic/LiteLoaderInstaller.h +++ b/logic/LiteLoaderInstaller.h @@ -25,10 +25,13 @@ class LiteLoaderInstaller : public BaseInstaller { public: - LiteLoaderInstaller(LiteLoaderVersionPtr version); + LiteLoaderInstaller(); + void prepare(LiteLoaderVersionPtr version); bool add(OneSixInstance *to) override; + ProgressProvider *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; + private: virtual QString id() const override { |