diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-03-12 16:00:06 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-04-07 00:20:01 +0200 |
commit | 8321187a20eec9871f327aa23f421e79dcfdd409 (patch) | |
tree | c765e3acdf9f01c27563e84d1fd4f27696a5996a /api/logic/meta/format/FormatV1.cpp | |
parent | ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c (diff) | |
download | MultiMC-8321187a20eec9871f327aa23f421e79dcfdd409.tar MultiMC-8321187a20eec9871f327aa23f421e79dcfdd409.tar.gz MultiMC-8321187a20eec9871f327aa23f421e79dcfdd409.tar.lz MultiMC-8321187a20eec9871f327aa23f421e79dcfdd409.tar.xz MultiMC-8321187a20eec9871f327aa23f421e79dcfdd409.zip |
NOISSUE fix downloading of metadata files
Diffstat (limited to 'api/logic/meta/format/FormatV1.cpp')
-rw-r--r-- | api/logic/meta/format/FormatV1.cpp | 119 |
1 files changed, 64 insertions, 55 deletions
diff --git a/api/logic/meta/format/FormatV1.cpp b/api/logic/meta/format/FormatV1.cpp index 23f57100..ee2c5291 100644 --- a/api/logic/meta/format/FormatV1.cpp +++ b/api/logic/meta/format/FormatV1.cpp @@ -27,6 +27,44 @@ using namespace Json; namespace Meta { + +static const int currentFormatVersion = 0; + +// Index + +BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const +{ + const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages"); + QVector<VersionListPtr> lists; + lists.reserve(objects.size()); + std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) + { + VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid")); + list->setName(ensureString(obj, "name", QString())); + return list; + }); + return std::make_shared<Index>(lists); +} + +QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const +{ + QJsonArray packages; + for (const VersionListPtr &list : ptr->lists()) + { + QJsonObject out; + out["uid"] = list->uid(); + out["name"] = list->name(); + packages.append(out); + } + QJsonObject out; + out["formatVersion"] = currentFormatVersion; + out["packages"] = packages; + return out; +} + + +// Version + static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) { const QVector<QJsonObject> requiresRaw = obj.contains("requires") ? requireIsArrayOf<QJsonObject>(obj, "requires") : QVector<QJsonObject>(); @@ -40,18 +78,22 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) }); VersionPtr version = std::make_shared<Version>(uid, requireString(obj, "version")); - if (obj.value("time").isString()) - { - version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000); - } - else - { - version->setTime(requireInteger(obj, "time")); - } + version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000); version->setType(ensureString(obj, "type", QString())); version->setRequires(requires); return version; } + +BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const +{ + VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); + + version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), + QString("%1/%2.json").arg(version->uid(), version->version()), + obj.contains("order"))); + return version; +} + static void serializeCommonVersion(const Version *version, QJsonObject &obj) { QJsonArray requires; @@ -74,32 +116,25 @@ static void serializeCommonVersion(const Version *version, QJsonObject &obj) obj.insert("version", version->version()); obj.insert("type", version->type()); - obj.insert("time", version->time().toString(Qt::ISODate)); + obj.insert("releaseTime", version->time().toString(Qt::ISODate)); obj.insert("requires", requires); } -BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const -{ - const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "index"); - QVector<VersionListPtr> lists; - lists.reserve(objects.size()); - std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) - { - VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid")); - list->setName(ensureString(obj, "name", QString())); - return list; - }); - return std::make_shared<Index>(lists); -} -BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const +QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const { - VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); + QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); + serializeCommonVersion(ptr, obj); + obj.insert("formatVersion", currentFormatVersion); + obj.insert("uid", ptr->uid()); + // TODO: the name should be looked up in the UI based on the uid + obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name()); - version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), - QString("%1/%2.json").arg(version->uid(), version->version()), - obj.contains("order"))); - return version; + return obj; } + + +// Version list / package + BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const { const QString uid = requireString(obj, "uid"); @@ -116,32 +151,6 @@ BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const return list; } -QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const -{ - QJsonArray index; - for (const VersionListPtr &list : ptr->lists()) - { - QJsonObject out; - out["uid"] = list->uid(); - out["version"] = list->name(); - index.append(out); - } - QJsonObject out; - out["formatVersion"] = 1; - out["index"] = index; - return out; -} -QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const -{ - QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); - serializeCommonVersion(ptr, obj); - obj.insert("formatVersion", 1); - obj.insert("uid", ptr->uid()); - // TODO: the name should be looked up in the UI based on the uid - obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name()); - - return obj; -} QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const { QJsonArray versions; @@ -152,7 +161,7 @@ QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const versions.append(obj); } QJsonObject out; - out["formatVersion"] = 10; + out["formatVersion"] = currentFormatVersion; out["uid"] = ptr->uid(); out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name(); out["versions"] = versions; |