From 0060b506257b906d40ef53d1e23404dba76afcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 17 Mar 2017 01:48:54 +0100 Subject: NOISSUE simplify. --- api/logic/meta/format/FormatV1.cpp | 170 ------------------------------------- 1 file changed, 170 deletions(-) delete mode 100644 api/logic/meta/format/FormatV1.cpp (limited to 'api/logic/meta/format/FormatV1.cpp') diff --git a/api/logic/meta/format/FormatV1.cpp b/api/logic/meta/format/FormatV1.cpp deleted file mode 100644 index ee2c5291..00000000 --- a/api/logic/meta/format/FormatV1.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "FormatV1.h" -#include - -#include "Json.h" - -#include "meta/Index.h" -#include "meta/Version.h" -#include "meta/VersionList.h" -#include "Env.h" - -using namespace Json; - -namespace Meta -{ - -static const int currentFormatVersion = 0; - -// Index - -BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const -{ - const QVector objects = requireIsArrayOf(obj, "packages"); - QVector lists; - lists.reserve(objects.size()); - std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) - { - VersionListPtr list = std::make_shared(requireString(obj, "uid")); - list->setName(ensureString(obj, "name", QString())); - return list; - }); - return std::make_shared(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 requiresRaw = obj.contains("requires") ? requireIsArrayOf(obj, "requires") : QVector(); - QVector requires; - requires.reserve(requiresRaw.size()); - std::transform(requiresRaw.begin(), requiresRaw.end(), std::back_inserter(requires), [](const QJsonObject &rObj) - { - Reference ref(requireString(rObj, "uid")); - ref.setVersion(ensureString(rObj, "version", QString())); - return ref; - }); - - VersionPtr version = std::make_shared(uid, requireString(obj, "version")); - 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; - for (const Reference &ref : version->requires()) - { - if (ref.version().isEmpty()) - { - QJsonObject out; - out["uid"] = ref.uid(); - requires.append(out); - } - else - { - QJsonObject out; - out["uid"] = ref.uid(); - out["version"] = ref.version(); - requires.append(out); - } - } - - obj.insert("version", version->version()); - obj.insert("type", version->type()); - obj.insert("releaseTime", version->time().toString(Qt::ISODate)); - obj.insert("requires", requires); -} - -QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const -{ - 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()); - - return obj; -} - - -// Version list / package - -BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const -{ - const QString uid = requireString(obj, "uid"); - - const QVector versionsRaw = requireIsArrayOf(obj, "versions"); - QVector versions; - versions.reserve(versionsRaw.size()); - std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [this, uid](const QJsonObject &vObj) - { return parseCommonVersion(uid, vObj); }); - - VersionListPtr list = std::make_shared(uid); - list->setName(ensureString(obj, "name", QString())); - list->setVersions(versions); - return list; -} - -QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const -{ - QJsonArray versions; - for (const VersionPtr &version : ptr->versions()) - { - QJsonObject obj; - serializeCommonVersion(version.get(), obj); - versions.append(obj); - } - QJsonObject out; - out["formatVersion"] = currentFormatVersion; - out["uid"] = ptr->uid(); - out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name(); - out["versions"] = versions; - return out; -} -} -- cgit v1.2.3