summaryrefslogtreecommitdiffstats
path: root/api/logic/meta/VersionList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/meta/VersionList.cpp')
-rw-r--r--api/logic/meta/VersionList.cpp71
1 files changed, 42 insertions, 29 deletions
diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp
index 44687d3c..9ae02301 100644
--- a/api/logic/meta/VersionList.cpp
+++ b/api/logic/meta/VersionList.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2015-2017 MultiMC Contributors
+/* Copyright 2015-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
#include "Version.h"
#include "JsonFormat.h"
+#include "Version.h"
namespace Meta
{
@@ -30,7 +31,7 @@ VersionList::VersionList(const QString &uid, QObject *parent)
shared_qobject_ptr<Task> VersionList::getLoadTask()
{
- load();
+ load(Net::Mode::Online);
return getCurrentTask();
}
@@ -75,17 +76,17 @@ QVariant VersionList::data(const QModelIndex &index, int role) const
return version->version();
case ParentVersionRole:
{
- auto parentUid = this->parentUid();
- if(parentUid.isEmpty())
- {
- return QVariant();
- }
+ // FIXME: HACK: this should be generic and be replaced by something else. Anything that is a hard 'equals' dep is a 'parent uid'.
auto & reqs = version->requires();
- auto iter = reqs.find(parentUid);
+ auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Require & req)
+ {
+ return req.uid == "net.minecraft";
+ });
if (iter != reqs.end())
{
- return iter.value();
+ return (*iter).equalsVersion;
}
+ return QVariant();
}
case TypeRole: return version->type();
@@ -159,6 +160,7 @@ void VersionList::setVersions(const QVector<VersionPtr> &versions)
setupAddedVersion(i, m_versions.at(i));
}
+ // FIXME: this is dumb, we have 'recommended' as part of the metadata already...
auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const VersionPtr &ptr) { return ptr->type() == "release"; });
m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt;
endResetModel();
@@ -169,28 +171,50 @@ void VersionList::parse(const QJsonObject& obj)
parseVersionList(obj, this);
}
-void VersionList::merge(const BaseEntity::Ptr &other)
+// FIXME: this is dumb, we have 'recommended' as part of the metadata already...
+static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const Meta::VersionPtr &b)
{
- const VersionListPtr list = std::dynamic_pointer_cast<VersionList>(other);
- if (m_name != list->m_name)
+ if(!a)
+ return b;
+ if(!b)
+ return a;
+ if(a->type() == b->type())
{
- setName(list->m_name);
+ // newer of same type wins
+ return (a->rawTime() > b->rawTime() ? a : b);
}
+ // 'release' type wins
+ return (a->type() == "release" ? a : b);
+}
- if(m_parentUid != list->m_parentUid)
+void VersionList::mergeFromIndex(const VersionListPtr &other)
+{
+ if (m_name != other->m_name)
{
- setParentUid(list->m_parentUid);
+ setName(other->m_name);
+ }
+}
+
+void VersionList::merge(const VersionListPtr &other)
+{
+ if (m_name != other->m_name)
+ {
+ setName(other->m_name);
}
// TODO: do not reset the whole model. maybe?
beginResetModel();
m_versions.clear();
- for (const VersionPtr &version : list->m_versions)
+ if(other->m_versions.isEmpty())
+ {
+ qWarning() << "Empty list loaded ...";
+ }
+ for (const VersionPtr &version : other->m_versions)
{
// we already have the version. merge the contents
if (m_lookup.contains(version->version()))
{
- m_lookup.value(version->version())->merge(version);
+ m_lookup.value(version->version())->mergeFromList(version);
}
else
{
@@ -199,10 +223,7 @@ void VersionList::merge(const BaseEntity::Ptr &other)
// connect it.
setupAddedVersion(m_versions.size(), version);
m_versions.append(version);
- if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime()))
- {
- m_recommended = version;
- }
+ m_recommended = getBetterVersion(m_recommended, version);
}
endResetModel();
}
@@ -222,11 +243,3 @@ BaseVersionPtr VersionList::getRecommended() const
}
}
-
-void Meta::VersionList::setParentUid(const QString& parentUid)
-{
- m_parentUid = parentUid;
-}
-
-
-#include "VersionList.moc"