summaryrefslogtreecommitdiffstats
path: root/api/logic/meta
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/meta')
-rw-r--r--api/logic/meta/BaseEntity.cpp10
-rw-r--r--api/logic/meta/BaseEntity.h6
-rw-r--r--api/logic/meta/Index.cpp6
-rw-r--r--api/logic/meta/Index.h4
-rw-r--r--api/logic/meta/JsonFormat.cpp150
-rw-r--r--api/logic/meta/JsonFormat.h45
-rw-r--r--api/logic/meta/Version.cpp55
-rw-r--r--api/logic/meta/Version.h26
-rw-r--r--api/logic/meta/VersionList.cpp71
-rw-r--r--api/logic/meta/VersionList.h11
10 files changed, 258 insertions, 126 deletions
diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp
index 439256b5..5c2339cb 100644
--- a/api/logic/meta/BaseEntity.cpp
+++ b/api/logic/meta/BaseEntity.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.
@@ -74,7 +74,7 @@ Meta::BaseEntity::~BaseEntity()
QUrl Meta::BaseEntity::url() const
{
- return QUrl("https://meta.multimc.org").resolved(localFilename());
+ return QUrl("https://v1.meta.multimc.org").resolved(localFilename());
}
bool Meta::BaseEntity::loadLocalFile()
@@ -99,7 +99,7 @@ bool Meta::BaseEntity::loadLocalFile()
}
}
-void Meta::BaseEntity::load()
+void Meta::BaseEntity::load(Net::Mode loadType)
{
// load local file if nothing is loaded yet
if(!isLoaded())
@@ -110,7 +110,7 @@ void Meta::BaseEntity::load()
}
}
// if we need remote update, run the update task
- if(!shouldStartRemoteUpdate())
+ if(loadType == Net::Mode::Offline || !shouldStartRemoteUpdate())
{
return;
}
@@ -160,5 +160,3 @@ shared_qobject_ptr<Task> Meta::BaseEntity::getCurrentTask()
}
return nullptr;
}
-
-#include "BaseEntity.moc"
diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h
index 4483beab..418c979f 100644
--- a/api/logic/meta/BaseEntity.h
+++ b/api/logic/meta/BaseEntity.h
@@ -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.
@@ -20,6 +20,7 @@
#include "QObjectPtr.h"
#include "multimc_logic_export.h"
+#include "net/Mode.h"
class Task;
namespace Meta
@@ -45,7 +46,6 @@ public: /* types */
public:
virtual ~BaseEntity();
- virtual void merge(const std::shared_ptr<BaseEntity> &other) = 0;
virtual void parse(const QJsonObject &obj) = 0;
virtual QString localFilename() const = 0;
@@ -54,7 +54,7 @@ public:
bool isLoaded() const;
bool shouldStartRemoteUpdate() const;
- void load();
+ void load(Net::Mode loadType);
shared_qobject_ptr<Task> getCurrentTask();
protected: /* methods */
diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp
index 0749651a..6e1e34cd 100644
--- a/api/logic/meta/Index.cpp
+++ b/api/logic/meta/Index.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.
@@ -103,7 +103,7 @@ void Index::parse(const QJsonObject& obj)
parseIndex(obj, this);
}
-void Index::merge(const Ptr &other)
+void Index::merge(const std::shared_ptr<Index> &other)
{
const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
// initial load, no need to merge
@@ -124,7 +124,7 @@ void Index::merge(const Ptr &other)
{
if (m_uids.contains(list->uid()))
{
- m_uids[list->uid()]->merge(list);
+ m_uids[list->uid()]->mergeFromIndex(list);
}
else
{
diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h
index 9811e152..0ec43f96 100644
--- a/api/logic/meta/Index.h
+++ b/api/logic/meta/Index.h
@@ -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.
@@ -58,7 +58,7 @@ public:
QVector<VersionListPtr> lists() const { return m_lists; }
public: // for usage by parsers only
- void merge(const BaseEntity::Ptr &other) override;
+ void merge(const std::shared_ptr<Index> &other);
void parse(const QJsonObject &obj) override;
private:
diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp
index fb78941f..2183e579 100644
--- a/api/logic/meta/JsonFormat.cpp
+++ b/api/logic/meta/JsonFormat.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.
@@ -16,7 +16,7 @@
#include "JsonFormat.h"
// FIXME: remove this from here... somehow
-#include "minecraft/onesix/OneSixVersionFormat.h"
+#include "minecraft/OneSixVersionFormat.h"
#include "Json.h"
#include "Index.h"
@@ -28,8 +28,13 @@ using namespace Json;
namespace Meta
{
+MetadataVersion currentFormatVersion()
+{
+ return MetadataVersion::InitialRelease;
+}
+
// Index
-static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj)
+static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
{
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages");
QVector<VersionListPtr> lists;
@@ -49,24 +54,16 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
VersionPtr version = std::make_shared<Version>(uid, requireString(obj, "version"));
version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
version->setType(ensureString(obj, "type", QString()));
- version->setParentUid(ensureString(obj, "parentUid", QString()));
version->setRecommended(ensureBoolean(obj, QString("recommended"), false));
- if(obj.contains("requires"))
- {
- QHash<QString, QString> requires;
- auto reqobj = requireObject(obj, "requires");
- auto iter = reqobj.begin();
- while(iter != reqobj.end())
- {
- requires[iter.key()] = requireString(iter.value());
- iter++;
- }
- version->setRequires(requires);
- }
+ version->setVolatile(ensureBoolean(obj, QString("volatile"), false));
+ RequireSet requires, conflicts;
+ parseRequires(obj, &requires, "requires");
+ parseRequires(obj, &conflicts, "conflicts");
+ version->setRequires(requires, conflicts);
return version;
}
-static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj)
+static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj)
{
VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj);
@@ -77,7 +74,7 @@ static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj)
}
// Version list / package
-static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj)
+static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &obj)
{
const QString uid = requireString(obj, "uid");
@@ -93,56 +90,129 @@ static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj)
VersionListPtr list = std::make_shared<VersionList>(uid);
list->setName(ensureString(obj, "name", QString()));
- list->setParentUid(ensureString(obj, "parentUid", QString()));
list->setVersions(versions);
return list;
}
-static int formatVersion(const QJsonObject &obj)
+MetadataVersion parseFormatVersion(const QJsonObject &obj, bool required)
{
- if (!obj.contains("formatVersion")) {
- throw ParseException(QObject::tr("Missing required field: 'formatVersion'"));
+ if (!obj.contains("formatVersion"))
+ {
+ if(required)
+ {
+ return MetadataVersion::Invalid;
+ }
+ return MetadataVersion::InitialRelease;
}
- if (!obj.value("formatVersion").isDouble()) {
- throw ParseException(QObject::tr("Required field has invalid type: 'formatVersion'"));
+ if (!obj.value("formatVersion").isDouble())
+ {
+ return MetadataVersion::Invalid;
+ }
+ switch(obj.value("formatVersion").toInt())
+ {
+ case 0:
+ case 1:
+ return MetadataVersion::InitialRelease;
+ default:
+ return MetadataVersion::Invalid;
+ }
+}
+
+void serializeFormatVersion(QJsonObject& obj, Meta::MetadataVersion version)
+{
+ if(version == MetadataVersion::Invalid)
+ {
+ return;
}
- return obj.value("formatVersion").toInt();
+ obj.insert("formatVersion", int(version));
}
void parseIndex(const QJsonObject &obj, Index *ptr)
{
- const int version = formatVersion(obj);
- switch (version) {
- case 0:
+ const MetadataVersion version = parseFormatVersion(obj);
+ switch (version)
+ {
+ case MetadataVersion::InitialRelease:
ptr->merge(parseIndexInternal(obj));
break;
- default:
- throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
+ case MetadataVersion::Invalid:
+ throw ParseException(QObject::tr("Unknown format version!"));
}
}
void parseVersionList(const QJsonObject &obj, VersionList *ptr)
{
- const int version = formatVersion(obj);
- switch (version) {
- case 0:
+ const MetadataVersion version = parseFormatVersion(obj);
+ switch (version)
+ {
+ case MetadataVersion::InitialRelease:
ptr->merge(parseVersionListInternal(obj));
break;
- default:
- throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
+ case MetadataVersion::Invalid:
+ throw ParseException(QObject::tr("Unknown format version!"));
}
}
void parseVersion(const QJsonObject &obj, Version *ptr)
{
- const int version = formatVersion(obj);
- switch (version) {
- case 0:
+ const MetadataVersion version = parseFormatVersion(obj);
+ switch (version)
+ {
+ case MetadataVersion::InitialRelease:
ptr->merge(parseVersionInternal(obj));
break;
- default:
- throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
+ case MetadataVersion::Invalid:
+ throw ParseException(QObject::tr("Unknown format version!"));
}
}
+
+/*
+[
+{"uid":"foo", "equals":"version"}
+]
+*/
+void parseRequires(const QJsonObject& obj, RequireSet* ptr, const char * keyName)
+{
+ if(obj.contains(keyName))
+ {
+ QSet<QString> requires;
+ auto reqArray = requireArray(obj, keyName);
+ auto iter = reqArray.begin();
+ while(iter != reqArray.end())
+ {
+ auto reqObject = requireObject(*iter);
+ auto uid = requireString(reqObject, "uid");
+ auto equals = ensureString(reqObject, "equals", QString());
+ auto suggests = ensureString(reqObject, "suggests", QString());
+ ptr->insert({uid, equals, suggests});
+ iter++;
+ }
+ }
}
+void serializeRequires(QJsonObject& obj, RequireSet* ptr, const char * keyName)
+{
+ if(!ptr || ptr->empty())
+ {
+ return;
+ }
+ QJsonArray arrOut;
+ for(auto &iter: *ptr)
+ {
+ QJsonObject reqOut;
+ reqOut.insert("uid", iter.uid);
+ if(!iter.equalsVersion.isEmpty())
+ {
+ reqOut.insert("equals", iter.equalsVersion);
+ }
+ if(!iter.suggests.isEmpty())
+ {
+ reqOut.insert("suggests", iter.suggests);
+ }
+ arrOut.append(reqOut);
+ }
+ obj.insert(keyName, arrOut);
+}
+
+}
+
diff --git a/api/logic/meta/JsonFormat.h b/api/logic/meta/JsonFormat.h
index aaed07fc..762a36f6 100644
--- a/api/logic/meta/JsonFormat.h
+++ b/api/logic/meta/JsonFormat.h
@@ -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.
@@ -20,6 +20,7 @@
#include "Exception.h"
#include "meta/BaseEntity.h"
+#include <set>
namespace Meta
{
@@ -27,14 +28,56 @@ class Index;
class Version;
class VersionList;
+enum class MetadataVersion
+{
+ Invalid = -1,
+ InitialRelease = 1
+};
+
class ParseException : public Exception
{
public:
using Exception::Exception;
};
+struct Require
+{
+ bool operator==(const Require & rhs) const
+ {
+ return uid == rhs.uid;
+ }
+ bool operator<(const Require & rhs) const
+ {
+ return uid < rhs.uid;
+ }
+ bool deepEquals(const Require & rhs) const
+ {
+ return uid == rhs.uid
+ && equalsVersion == rhs.equalsVersion
+ && suggests == rhs.suggests;
+ }
+ QString uid;
+ QString equalsVersion;
+ QString suggests;
+};
+
+inline Q_DECL_PURE_FUNCTION uint qHash(const Require &key, uint seed = 0) Q_DECL_NOTHROW
+{
+ return qHash(key.uid, seed);
+}
+
+using RequireSet = std::set<Require>;
void parseIndex(const QJsonObject &obj, Index *ptr);
void parseVersion(const QJsonObject &obj, Version *ptr);
void parseVersionList(const QJsonObject &obj, VersionList *ptr);
+MetadataVersion parseFormatVersion(const QJsonObject &obj, bool required = true);
+void serializeFormatVersion(QJsonObject &obj, MetadataVersion version);
+
+// FIXME: this has a different shape than the others...FIX IT!?
+void parseRequires(const QJsonObject &obj, RequireSet * ptr, const char * keyName = "requires");
+void serializeRequires(QJsonObject & objOut, RequireSet* ptr, const char * keyName = "requires");
+MetadataVersion currentFormatVersion();
}
+
+Q_DECLARE_METATYPE(std::set<Meta::Require>); \ No newline at end of file
diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp
index b00a29e7..edc70f33 100644
--- a/api/logic/meta/Version.cpp
+++ b/api/logic/meta/Version.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.
@@ -18,7 +18,7 @@
#include <QDateTime>
#include "JsonFormat.h"
-#include "minecraft/MinecraftProfile.h"
+#include "minecraft/ComponentList.h"
Meta::Version::Version(const QString &uid, const QString &version)
: BaseVersion(), m_uid(uid), m_version(version)
@@ -54,47 +54,49 @@ void Meta::Version::parse(const QJsonObject& obj)
parseVersion(obj, this);
}
-void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
+void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
{
- VersionPtr version = std::dynamic_pointer_cast<Version>(other);
- if(version->m_providesRecommendations)
+ if(other->m_providesRecommendations)
{
- if(m_recommended != version->m_recommended)
+ if(m_recommended != other->m_recommended)
{
- setRecommended(version->m_recommended);
+ setRecommended(other->m_recommended);
}
}
- if (m_type != version->m_type)
+ if (m_type != other->m_type)
{
- setType(version->m_type);
+ setType(other->m_type);
}
- if (m_time != version->m_time)
+ if (m_time != other->m_time)
{
- setTime(version->m_time);
+ setTime(other->m_time);
}
- if (m_requires != version->m_requires)
+ if (m_requires != other->m_requires)
{
- setRequires(version->m_requires);
+ m_requires = other->m_requires;
}
- if (m_parentUid != version->m_parentUid)
+ if (m_conflicts != other->m_conflicts)
{
- setParentUid(version->m_parentUid);
+ m_conflicts = other->m_conflicts;
}
- if(version->m_data)
+ if(m_volatile != other->m_volatile)
{
- setData(version->m_data);
+ setVolatile(other->m_volatile);
}
}
-QString Meta::Version::localFilename() const
+void Meta::Version::merge(const VersionPtr &other)
{
- return m_uid + '/' + m_version + ".json";
+ mergeFromList(other);
+ if(other->m_data)
+ {
+ setData(other->m_data);
+ }
}
-void Meta::Version::setParentUid(const QString& parentUid)
+QString Meta::Version::localFilename() const
{
- m_parentUid = parentUid;
- emit requiresChanged();
+ return m_uid + '/' + m_version + ".json";
}
void Meta::Version::setType(const QString &type)
@@ -109,12 +111,19 @@ void Meta::Version::setTime(const qint64 time)
emit timeChanged();
}
-void Meta::Version::setRequires(const QHash<QString, QString> &requires)
+void Meta::Version::setRequires(const Meta::RequireSet &requires, const Meta::RequireSet &conflicts)
{
m_requires = requires;
+ m_conflicts = conflicts;
emit requiresChanged();
}
+void Meta::Version::setVolatile(bool volatile_)
+{
+ m_volatile = volatile_;
+}
+
+
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 2f92ee9f..33bd5b35 100644
--- a/api/logic/meta/Version.h
+++ b/api/logic/meta/Version.h
@@ -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.
@@ -28,6 +28,8 @@
#include "multimc_logic_export.h"
+#include "JsonFormat.h"
+
namespace Meta
{
using VersionPtr = std::shared_ptr<class Version>;
@@ -48,10 +50,6 @@ public: /* con/des */
{
return m_uid;
}
- QString parentUid() const
- {
- return m_parentUid;
- }
QString version() const
{
return m_version;
@@ -65,7 +63,7 @@ public: /* con/des */
{
return m_time;
}
- const QHash<QString, QString> &requires() const
+ const Meta::RequireSet &requires() const
{
return m_requires;
}
@@ -77,17 +75,22 @@ public: /* con/des */
{
return m_recommended;
}
+ bool isLoaded() const
+ {
+ return m_data != nullptr;
+ }
- void merge(const std::shared_ptr<BaseEntity> &other) override;
+ void merge(const VersionPtr &other);
+ void mergeFromList(const VersionPtr &other);
void parse(const QJsonObject &obj) override;
QString localFilename() const override;
public: // for usage by format parsers only
- void setParentUid(const QString &parentUid);
void setType(const QString &type);
void setTime(const qint64 time);
- void setRequires(const QHash<QString, QString> &requires);
+ void setRequires(const Meta::RequireSet &requires, const Meta::RequireSet &conflicts);
+ void setVolatile(bool volatile_);
void setRecommended(bool recommended);
void setProvidesRecommendations();
void setData(const VersionFilePtr &data);
@@ -102,11 +105,12 @@ private:
bool m_recommended = false;
QString m_name;
QString m_uid;
- QString m_parentUid;
QString m_version;
QString m_type;
qint64 m_time = 0;
- QHash<QString, QString> m_requires;
+ Meta::RequireSet m_requires;
+ Meta::RequireSet m_conflicts;
+ bool m_volatile = false;
VersionFilePtr m_data;
};
}
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"
diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h
index e8016314..ad8733cc 100644
--- a/api/logic/meta/VersionList.h
+++ b/api/logic/meta/VersionList.h
@@ -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.
@@ -55,10 +55,6 @@ public:
QString localFilename() const override;
- QString parentUid() const
- {
- return m_parentUid;
- }
QString uid() const
{
return m_uid;
@@ -78,9 +74,9 @@ public:
public: // for usage only by parsers
void setName(const QString &name);
- void setParentUid(const QString &parentUid);
void setVersions(const QVector<VersionPtr> &versions);
- void merge(const BaseEntity::Ptr &other) override;
+ void merge(const VersionListPtr &other);
+ void mergeFromIndex(const VersionListPtr &other);
void parse(const QJsonObject &obj) override;
signals:
@@ -95,7 +91,6 @@ private:
QVector<VersionPtr> m_versions;
QHash<QString, VersionPtr> m_lookup;
QString m_uid;
- QString m_parentUid;
QString m_name;
VersionPtr m_recommended;