summaryrefslogtreecommitdiffstats
path: root/api/logic/meta
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-12-29 00:37:14 +0100
committerPetr Mrázek <peterix@gmail.com>2017-12-29 00:37:14 +0100
commit719f3e863a2bdbaeaba37e837e0f6b75de124e6c (patch)
treebff005dd7e36b08d355bfec58742d44265fc0dd6 /api/logic/meta
parent50ca6cbb4daaa4acd300defc6b7ecc7ccb46cebf (diff)
downloadMultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar.gz
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar.lz
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar.xz
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.zip
NOISSUE add versioning to component metadata format and use it
Diffstat (limited to 'api/logic/meta')
-rw-r--r--api/logic/meta/JsonFormat.cpp73
-rw-r--r--api/logic/meta/JsonFormat.h10
-rw-r--r--api/logic/meta/Version.cpp10
-rw-r--r--api/logic/meta/Version.h6
-rw-r--r--api/logic/meta/VersionList.cpp26
-rw-r--r--api/logic/meta/VersionList.h6
6 files changed, 64 insertions, 67 deletions
diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp
index 832743ed..6e84597c 100644
--- a/api/logic/meta/JsonFormat.cpp
+++ b/api/logic/meta/JsonFormat.cpp
@@ -28,6 +28,11 @@ using namespace Json;
namespace Meta
{
+MetadataVersion currentFormatVersion()
+{
+ return MetadataVersion::InitialRelease;
+}
+
// Index
static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
{
@@ -49,7 +54,6 @@ 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));
version->setVolatile(ensureBoolean(obj, QString("volatile"), false));
RequireSet requires, conflicts;
@@ -86,56 +90,79 @@ static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &
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())
+ {
+ return MetadataVersion::Invalid;
+ }
+ switch(obj.value("formatVersion").toInt())
+ {
+ case 0:
+ return MetadataVersion::InitialRelease;
+ default:
+ return MetadataVersion::Invalid;
}
- if (!obj.value("formatVersion").isDouble()) {
- throw ParseException(QObject::tr("Required field has invalid type: 'formatVersion'"));
+}
+
+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!"));
}
}
diff --git a/api/logic/meta/JsonFormat.h b/api/logic/meta/JsonFormat.h
index 9b9dcd91..82ab0ce3 100644
--- a/api/logic/meta/JsonFormat.h
+++ b/api/logic/meta/JsonFormat.h
@@ -28,6 +28,12 @@ class Index;
class Version;
class VersionList;
+enum class MetadataVersion
+{
+ Invalid = -1,
+ InitialRelease = 0
+};
+
class ParseException : public Exception
{
public:
@@ -65,9 +71,13 @@ 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 55b92966..c9056547 100644
--- a/api/logic/meta/Version.cpp
+++ b/api/logic/meta/Version.cpp
@@ -79,10 +79,6 @@ void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
{
m_conflicts = other->m_conflicts;
}
- if (m_parentUid != other->m_parentUid)
- {
- setParentUid(other->m_parentUid);
- }
if(m_volatile != other->m_volatile)
{
setVolatile(other->m_volatile);
@@ -103,12 +99,6 @@ QString Meta::Version::localFilename() const
return m_uid + '/' + m_version + ".json";
}
-void Meta::Version::setParentUid(const QString& parentUid)
-{
- m_parentUid = parentUid;
- emit requiresChanged();
-}
-
void Meta::Version::setType(const QString &type)
{
m_type = type;
diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h
index debdf20a..d284da69 100644
--- a/api/logic/meta/Version.h
+++ b/api/logic/meta/Version.h
@@ -50,10 +50,6 @@ public: /* con/des */
{
return m_uid;
}
- QString parentUid() const
- {
- return m_parentUid;
- }
QString version() const
{
return m_version;
@@ -91,7 +87,6 @@ public: /* con/des */
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 Meta::RequireSet &requires, const Meta::RequireSet &conflicts);
@@ -110,7 +105,6 @@ private:
bool m_recommended = false;
QString m_name;
QString m_uid;
- QString m_parentUid;
QString m_version;
QString m_type;
qint64 m_time = 0;
diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp
index 4963f235..66dc9fd1 100644
--- a/api/logic/meta/VersionList.cpp
+++ b/api/logic/meta/VersionList.cpp
@@ -76,20 +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 = std::find_if(reqs.begin(), reqs.end(), [&parentUid](const Require & req)
+ auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Require & req)
{
- return req.uid == parentUid;
+ return req.uid == "net.minecraft";
});
if (iter != reqs.end())
{
return (*iter).equalsVersion;
}
+ return QVariant();
}
case TypeRole: return version->type();
@@ -196,11 +193,6 @@ void VersionList::mergeFromIndex(const VersionListPtr &other)
{
setName(other->m_name);
}
-
- if(m_parentUid != other->m_parentUid)
- {
- setParentUid(other->m_parentUid);
- }
}
void VersionList::merge(const VersionListPtr &other)
@@ -210,11 +202,6 @@ void VersionList::merge(const VersionListPtr &other)
setName(other->m_name);
}
- if(m_parentUid != other->m_parentUid)
- {
- setParentUid(other->m_parentUid);
- }
-
// TODO: do not reset the whole model. maybe?
beginResetModel();
m_versions.clear();
@@ -256,8 +243,3 @@ BaseVersionPtr VersionList::getRecommended() const
}
}
-
-void Meta::VersionList::setParentUid(const QString& parentUid)
-{
- m_parentUid = parentUid;
-}
diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h
index c4a2b757..f880c7fd 100644
--- a/api/logic/meta/VersionList.h
+++ b/api/logic/meta/VersionList.h
@@ -55,10 +55,6 @@ public:
QString localFilename() const override;
- QString parentUid() const
- {
- return m_parentUid;
- }
QString uid() const
{
return m_uid;
@@ -78,7 +74,6 @@ 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 VersionListPtr &other);
void mergeFromIndex(const VersionListPtr &other);
@@ -96,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;