summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/logic/meta/BaseEntity.cpp9
-rw-r--r--api/logic/meta/BaseEntity.h1
-rw-r--r--api/logic/meta/Index.cpp14
-rw-r--r--api/logic/meta/Index.h1
-rw-r--r--api/logic/meta/Version.cpp35
-rw-r--r--api/logic/meta/Version.h84
-rw-r--r--api/logic/meta/VersionList.cpp14
-rw-r--r--api/logic/meta/VersionList.h3
-rw-r--r--api/logic/minecraft/ProfilePatch.h4
-rw-r--r--api/logic/minecraft/onesix/OneSixProfileStrategy.cpp6
-rw-r--r--api/logic/minecraft/onesix/OneSixUpdate.cpp48
-rw-r--r--application/pages/VersionPage.cpp1
12 files changed, 162 insertions, 58 deletions
diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp
index 18b7f92f..809f88cb 100644
--- a/api/logic/meta/BaseEntity.cpp
+++ b/api/logic/meta/BaseEntity.cpp
@@ -137,4 +137,13 @@ void Meta::BaseEntity::load()
m_updateTask->start();
}
+shared_qobject_ptr<Task> Meta::BaseEntity::getCurrentTask()
+{
+ if(m_updateStatus == UpdateStatus::InProgress)
+ {
+ return m_updateTask;
+ }
+ return nullptr;
+}
+
#include "BaseEntity.moc"
diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h
index 92a39272..85051d97 100644
--- a/api/logic/meta/BaseEntity.h
+++ b/api/logic/meta/BaseEntity.h
@@ -61,6 +61,7 @@ public:
}
void load();
+ shared_qobject_ptr<Task> getCurrentTask();
protected: /* methods */
bool loadLocalFile();
diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp
index 35b9fb6f..0749651a 100644
--- a/api/logic/meta/Index.cpp
+++ b/api/logic/meta/Index.cpp
@@ -83,17 +83,19 @@ bool Index::hasUid(const QString &uid) const
VersionListPtr Index::get(const QString &uid)
{
- return m_uids.value(uid, nullptr);
+ VersionListPtr out = m_uids.value(uid, nullptr);
+ if(!out)
+ {
+ out = std::make_shared<VersionList>(uid);
+ m_uids[uid] = out;
+ }
+ return out;
}
VersionPtr Index::get(const QString &uid, const QString &version)
{
auto list = get(uid);
- if(list)
- {
- return list->getVersion(version);
- }
- return nullptr;
+ return list->getVersion(version);
}
void Index::parse(const QJsonObject& obj)
diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h
index 544a8b96..9811e152 100644
--- a/api/logic/meta/Index.h
+++ b/api/logic/meta/Index.h
@@ -68,3 +68,4 @@ private:
void connectVersionList(const int row, const VersionListPtr &list);
};
}
+
diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp
index f8c865e7..2790b2f3 100644
--- a/api/logic/meta/Version.cpp
+++ b/api/logic/meta/Version.cpp
@@ -18,38 +18,45 @@
#include <QDateTime>
#include "JsonFormat.h"
+#include "minecraft/MinecraftProfile.h"
-namespace Meta
+void Meta::Version::applyTo(MinecraftProfile* profile)
{
-Version::Version(const QString &uid, const QString &version)
+ if(m_data)
+ {
+ m_data->applyTo(profile);
+ }
+}
+
+Meta::Version::Version(const QString &uid, const QString &version)
: BaseVersion(), m_uid(uid), m_version(version)
{
}
-QString Version::descriptor()
+QString Meta::Version::descriptor()
{
return m_version;
}
-QString Version::name()
+QString Meta::Version::name()
{
return m_version;
}
-QString Version::typeString() const
+QString Meta::Version::typeString() const
{
return m_type;
}
-QDateTime Version::time() const
+QDateTime Meta::Version::time() const
{
return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC);
}
-void Version::parse(const QJsonObject& obj)
+void Meta::Version::parse(const QJsonObject& obj)
{
parseVersion(obj, this);
}
-void Version::merge(const std::shared_ptr<BaseEntity> &other)
+void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
{
VersionPtr version = std::dynamic_pointer_cast<Version>(other);
if (m_type != version->m_type)
@@ -68,28 +75,28 @@ void Version::merge(const std::shared_ptr<BaseEntity> &other)
setData(version->m_data);
}
-QString Version::localFilename() const
+QString Meta::Version::localFilename() const
{
return m_uid + '/' + m_version + ".json";
}
-void Version::setType(const QString &type)
+void Meta::Version::setType(const QString &type)
{
m_type = type;
emit typeChanged();
}
-void Version::setTime(const qint64 time)
+void Meta::Version::setTime(const qint64 time)
{
m_time = time;
emit timeChanged();
}
-void Version::setRequires(const QVector<Reference> &requires)
+void Meta::Version::setRequires(const QVector<Reference> &requires)
{
m_requires = requires;
emit requiresChanged();
}
-void Version::setData(const VersionFilePtr &data)
+void Meta::Version::setData(const VersionFilePtr &data)
{
m_data = data;
}
-}
+
diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h
index 0be2d94a..b8ea7e44 100644
--- a/api/logic/meta/Version.h
+++ b/api/logic/meta/Version.h
@@ -33,7 +33,7 @@ namespace Meta
{
using VersionPtr = std::shared_ptr<class Version>;
-class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity
+class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity, public ProfilePatch
{
Q_OBJECT
Q_PROPERTY(QString uid READ uid CONSTANT)
@@ -41,9 +41,89 @@ class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public
Q_PROPERTY(QString type READ type NOTIFY typeChanged)
Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged)
Q_PROPERTY(QVector<Reference> requires READ requires NOTIFY requiresChanged)
-public:
+
+public: /* con/des */
explicit Version(const QString &uid, const QString &version);
+// FIXME: none of this belongs here...
+public: /* ProfilePatch overrides */
+ QString getFilename() override
+ {
+ return QString();
+ }
+ QString getID() override
+ {
+ return m_uid;
+ }
+ QList<JarmodPtr> getJarMods() override
+ {
+ return {};
+ }
+ QString getName() override
+ {
+ return name();
+ }
+ QDateTime getReleaseDateTime() override
+ {
+ return time();
+ }
+ QString getVersion() override
+ {
+ return m_version;
+ }
+ std::shared_ptr<class VersionFile> getVersionFile() override
+ {
+ return m_data;
+ }
+ int getOrder() override
+ {
+ return 0;
+ }
+ VersionSource getVersionSource() override
+ {
+ return VersionSource::Local;
+ }
+ bool isVersionChangeable() override
+ {
+ return true;
+ }
+ bool isRevertible() override
+ {
+ return false;
+ }
+ bool isRemovable() override
+ {
+ return true;
+ }
+ bool isCustom() override
+ {
+ return false;
+ }
+ bool isCustomizable() override
+ {
+ return true;
+ }
+ bool isMoveable() override
+ {
+ return true;
+ }
+ bool isEditable() override
+ {
+ return false;
+ }
+ void setOrder(int) override
+ {
+ }
+ bool hasJarMods() override
+ {
+ return false;
+ }
+ bool isMinecraftVersion() override
+ {
+ return m_uid == "net.minecraft";
+ }
+ void applyTo(MinecraftProfile * profile) override;
+
QString descriptor() override;
QString name() override;
QString typeString() const override;
diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp
index a12f5418..d6bbf70f 100644
--- a/api/logic/meta/VersionList.cpp
+++ b/api/logic/meta/VersionList.cpp
@@ -125,13 +125,15 @@ QString VersionList::humanReadable() const
return m_name.isEmpty() ? m_uid : m_name;
}
-bool VersionList::hasVersion(const QString &version) const
+VersionPtr VersionList::getVersion(const QString &version)
{
- return m_lookup.contains(version);
-}
-VersionPtr VersionList::getVersion(const QString &version) const
-{
- return m_lookup.value(version);
+ VersionPtr out = m_lookup.value(version, nullptr);
+ if(!out)
+ {
+ out = std::make_shared<Version>(m_uid, version);
+ m_lookup[version] = out;
+ }
+ return out;
}
void VersionList::setName(const QString &name)
diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h
index e958475e..26fa6c5a 100644
--- a/api/logic/meta/VersionList.h
+++ b/api/logic/meta/VersionList.h
@@ -60,8 +60,7 @@ public:
QString name() const { return m_name; }
QString humanReadable() const;
- bool hasVersion(const QString &version) const;
- VersionPtr getVersion(const QString &version) const;
+ VersionPtr getVersion(const QString &version);
QVector<VersionPtr> versions() const { return m_versions; }
diff --git a/api/logic/minecraft/ProfilePatch.h b/api/logic/minecraft/ProfilePatch.h
index 26230092..b61fb8b3 100644
--- a/api/logic/minecraft/ProfilePatch.h
+++ b/api/logic/minecraft/ProfilePatch.h
@@ -92,10 +92,6 @@ public:
{
return m_problemSeverity;
}
- virtual bool hasFailed()
- {
- return getProblemSeverity() == PROBLEM_ERROR;
- }
protected:
QList<PatchProblem> m_problems;
diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
index e3d3f674..b19a2dea 100644
--- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
+++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp
@@ -12,6 +12,8 @@
#include <QJsonArray>
#include <QSaveFile>
#include <QResource>
+#include <meta/Index.h>
+#include <meta/Version.h>
OneSixProfileStrategy::OneSixProfileStrategy(OneSixInstance* instance)
{
@@ -98,7 +100,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches()
}
else
{
- auto mcversion = ENV.getVersion("net.minecraft", m_instance->intendedVersionId());
+ auto mcversion = ENV.metadataIndex()->get("net.minecraft", m_instance->intendedVersionId());
minecraftPatch = std::dynamic_pointer_cast<ProfilePatch>(mcversion);
}
if (!minecraftPatch)
@@ -121,7 +123,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches()
}
else
{
- auto lwjglversion = ENV.getVersion("org.lwjgl", "2.9.1" /*m_instance->intendedVersionId()*/);
+ auto lwjglversion = ENV.metadataIndex()->get("org.lwjgl", "2.9.1");
lwjglPatch = std::dynamic_pointer_cast<ProfilePatch>(lwjglversion);
}
if (!lwjglPatch)
diff --git a/api/logic/minecraft/onesix/OneSixUpdate.cpp b/api/logic/minecraft/onesix/OneSixUpdate.cpp
index ec40e086..5bc76b01 100644
--- a/api/logic/minecraft/onesix/OneSixUpdate.cpp
+++ b/api/logic/minecraft/onesix/OneSixUpdate.cpp
@@ -34,6 +34,9 @@
#include "update/FMLLibrariesTask.h"
#include "update/AssetUpdateTask.h"
+#include <meta/Index.h>
+#include <meta/Version.h>
+
OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
{
// create folders
@@ -44,30 +47,22 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
// add a version update task, if necessary
{
/*
- auto list = std::dynamic_pointer_cast<MinecraftVersionList>(ENV.getVersionList("net.minecraft"));
- auto version = std::dynamic_pointer_cast<MinecraftVersion>(list->findVersion(m_inst->intendedVersionId()));
- if (version == nullptr)
- {
- // don't do anything if it was invalid
- m_preFailure = tr("The specified Minecraft version is invalid. Choose a different one.");
- }
- else if (m_inst->providesVersionFile() || !version->needsUpdate())
+ * FIXME: there are some corner cases here that remain unhandled:
+ * what if local load succeeds but remote fails? The version is still usable...
+ */
+ // FIXME: derive this from the actual list of version patches...
+ auto loadVersion = [&](const QString & uid, const QString & version)
{
- qDebug() << "Instance either provides a version file or doesn't need an update.";
- }
- else
- {
- auto versionUpdateTask = list->createUpdateTask(m_inst->intendedVersionId());
- if (!versionUpdateTask)
- {
- qDebug() << "Didn't spawn an update task.";
- }
- else
+ auto obj = ENV.metadataIndex()->get(uid, version);
+ obj->load();
+ auto task = obj->getCurrentTask();
+ if(task)
{
- m_tasks.append(versionUpdateTask);
+ m_tasks.append(task.unwrap());
}
- }
- */
+ };
+ loadVersion("org.lwjgl", "2.9.1");
+ loadVersion("net.minecraft", m_inst->intendedVersionId());
}
// libraries download
@@ -118,11 +113,20 @@ void OneSixUpdate::next()
return;
}
auto task = m_tasks[m_currentTask];
+ // if the task is already finished by the time we look at it, skip it
+ if(task->isFinished())
+ {
+ next();
+ }
connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
connect(task.get(), &Task::progress, this, &OneSixUpdate::progress);
connect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
- task->start();
+ // if the task is already running, do not start it again
+ if(!task->isRunning())
+ {
+ task->start();
+ }
}
void OneSixUpdate::subtaskSucceeded()
diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp
index 42eb31de..78e2a888 100644
--- a/application/pages/VersionPage.cpp
+++ b/application/pages/VersionPage.cpp
@@ -320,6 +320,7 @@ void VersionPage::on_moveDownBtn_clicked()
void VersionPage::on_changeVersionBtn_clicked()
{
+ // FIXME: this is hilariously broken because it assumes m_inst->versionList() is a sensible thing...
VersionSelectDialog vselect(m_inst->versionList().get(), tr("Change Minecraft version"),
this);
if (!vselect.exec() || !vselect.selectedVersion())