summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-03-12 16:00:06 +0100
committerPetr Mrázek <peterix@gmail.com>2017-04-07 00:20:01 +0200
commit8321187a20eec9871f327aa23f421e79dcfdd409 (patch)
treec765e3acdf9f01c27563e84d1fd4f27696a5996a /api/logic
parentab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c (diff)
downloadMultiMC-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')
-rw-r--r--api/logic/meta/Util.cpp2
-rw-r--r--api/logic/meta/VersionList.cpp2
-rw-r--r--api/logic/meta/format/Format.cpp28
-rw-r--r--api/logic/meta/format/FormatV1.cpp119
4 files changed, 83 insertions, 68 deletions
diff --git a/api/logic/meta/Util.cpp b/api/logic/meta/Util.cpp
index 2ccbe5c4..76941f83 100644
--- a/api/logic/meta/Util.cpp
+++ b/api/logic/meta/Util.cpp
@@ -34,7 +34,7 @@ QUrl indexUrl()
QUrl versionListUrl(const QString &uid)
{
- return rootUrl().resolved(uid + ".json");
+ return rootUrl().resolved(uid + "/index.json");
}
QUrl versionUrl(const QString &uid, const QString &version)
diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp
index 11e20c12..aab3e0f7 100644
--- a/api/logic/meta/VersionList.cpp
+++ b/api/logic/meta/VersionList.cpp
@@ -178,7 +178,7 @@ std::unique_ptr<Task> VersionList::localUpdateTask()
QString VersionList::localFilename() const
{
- return m_uid + ".json";
+ return m_uid + "/index.json";
}
QJsonObject VersionList::serialized() const
{
diff --git a/api/logic/meta/format/Format.cpp b/api/logic/meta/format/Format.cpp
index a3f9f730..e0fddb0b 100644
--- a/api/logic/meta/format/Format.cpp
+++ b/api/logic/meta/format/Format.cpp
@@ -39,46 +39,52 @@ void Format::parseIndex(const QJsonObject &obj, Index *ptr)
{
const int version = formatVersion(obj);
switch (version) {
- case 1:
+ case 0:
ptr->merge(FormatV1().parseIndexInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
-void Format::parseVersion(const QJsonObject &obj, Version *ptr)
+
+void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr)
{
const int version = formatVersion(obj);
switch (version) {
- case 1:
- ptr->merge(FormatV1().parseVersionInternal(obj));
+ case 0:
+ ptr->merge(FormatV1().parseVersionListInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
-void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr)
+
+void Format::parseVersion(const QJsonObject &obj, Version *ptr)
{
const int version = formatVersion(obj);
switch (version) {
- case 10:
- ptr->merge(FormatV1().parseVersionListInternal(obj));
+ case 0:
+ ptr->merge(FormatV1().parseVersionInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
+
QJsonObject Format::serializeIndex(const Index *ptr)
{
return FormatV1().serializeIndexInternal(ptr);
}
-QJsonObject Format::serializeVersion(const Version *ptr)
-{
- return FormatV1().serializeVersionInternal(ptr);
-}
+
QJsonObject Format::serializeVersionList(const VersionList *ptr)
{
return FormatV1().serializeVersionListInternal(ptr);
}
+
+QJsonObject Format::serializeVersion(const Version *ptr)
+{
+ return FormatV1().serializeVersionInternal(ptr);
+}
+
}
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;