From ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 11 Mar 2017 01:39:45 +0100 Subject: NOISSUE Wonko is the new Meta And then Wonko was the Meta. --- api/logic/meta/Version.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 api/logic/meta/Version.h (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h new file mode 100644 index 00000000..4a791880 --- /dev/null +++ b/api/logic/meta/Version.h @@ -0,0 +1,87 @@ +/* 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. + */ + +#pragma once + +#include "BaseVersion.h" + +#include +#include +#include +#include + +#include "minecraft/VersionFile.h" + +#include "BaseEntity.h" +#include "Reference.h" + +#include "multimc_logic_export.h" + +namespace Meta +{ +using VersionPtr = std::shared_ptr; + +class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity +{ + Q_OBJECT + Q_PROPERTY(QString uid READ uid CONSTANT) + Q_PROPERTY(QString version READ version CONSTANT) + Q_PROPERTY(QString type READ type NOTIFY typeChanged) + Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) + Q_PROPERTY(QVector requires READ requires NOTIFY requiresChanged) +public: + explicit Version(const QString &uid, const QString &version); + + QString descriptor() override; + QString name() override; + QString typeString() const override; + + QString uid() const { return m_uid; } + QString version() const { return m_version; } + QString type() const { return m_type; } + QDateTime time() const; + qint64 rawTime() const { return m_time; } + QVector requires() const { return m_requires; } + VersionFilePtr data() const { return m_data; } + + std::unique_ptr remoteUpdateTask() override; + std::unique_ptr localUpdateTask() override; + void merge(const std::shared_ptr &other) override; + + QString localFilename() const override; + QJsonObject serialized() const override; + +public: // for usage by format parsers only + void setType(const QString &type); + void setTime(const qint64 time); + void setRequires(const QVector &requires); + void setData(const VersionFilePtr &data); + +signals: + void typeChanged(); + void timeChanged(); + void requiresChanged(); + +private: + QString m_uid; + QString m_version; + QString m_type; + qint64 m_time; + QVector m_requires; + VersionFilePtr m_data; +}; +} + +Q_DECLARE_METATYPE(Meta::VersionPtr) -- cgit From 0060b506257b906d40ef53d1e23404dba76afcee Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Fri, 17 Mar 2017 01:48:54 +0100 Subject: NOISSUE simplify. --- api/logic/CMakeLists.txt | 2 - api/logic/Env.cpp | 2 +- api/logic/meta/BaseEntity.cpp | 7 +- api/logic/meta/BaseEntity.h | 5 +- api/logic/meta/Index.cpp | 27 +++-- api/logic/meta/Index.h | 7 +- api/logic/meta/Index_test.cpp | 6 +- api/logic/meta/Util.h | 3 - api/logic/meta/Version.cpp | 13 +-- api/logic/meta/Version.h | 2 +- api/logic/meta/VersionList.cpp | 14 +-- api/logic/meta/VersionList.h | 3 +- api/logic/meta/format/Format.cpp | 101 +++++++++++++----- api/logic/meta/format/Format.h | 23 +--- api/logic/meta/format/FormatV1.cpp | 170 ------------------------------ api/logic/meta/format/FormatV1.h | 33 ------ api/logic/meta/tasks/LocalLoadTask.cpp | 72 +------------ api/logic/meta/tasks/LocalLoadTask.h | 47 +-------- api/logic/meta/tasks/RemoteLoadTask.cpp | 139 ++++++++++-------------- api/logic/meta/tasks/RemoteLoadTask.h | 51 +-------- application/pages/global/PackagesPage.cpp | 2 +- 21 files changed, 192 insertions(+), 537 deletions(-) delete mode 100644 api/logic/meta/format/FormatV1.cpp delete mode 100644 api/logic/meta/format/FormatV1.h (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index b605fbd3..42754157 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -420,8 +420,6 @@ set(META_SOURCES meta/tasks/RemoteLoadTask.h meta/tasks/LocalLoadTask.cpp meta/tasks/LocalLoadTask.h - meta/format/FormatV1.cpp - meta/format/FormatV1.h meta/format/Format.cpp meta/format/Format.h meta/BaseEntity.cpp diff --git a/api/logic/Env.cpp b/api/logic/Env.cpp index 903f1d8a..d7be4a28 100644 --- a/api/logic/Env.cpp +++ b/api/logic/Env.cpp @@ -124,7 +124,7 @@ void Env::initHttpMetaCache() m_metacache->addBase("root", QDir::currentPath()); m_metacache->addBase("translations", QDir("translations").absolutePath()); m_metacache->addBase("icons", QDir("cache/icons").absolutePath()); - m_metacache->addBase("meta", QDir("cache/meta").absolutePath()); + m_metacache->addBase("meta", QDir("meta").absolutePath()); m_metacache->Load(); } diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp index fd44e29c..87cd55c8 100644 --- a/api/logic/meta/BaseEntity.cpp +++ b/api/logic/meta/BaseEntity.cpp @@ -24,19 +24,18 @@ BaseEntity::~BaseEntity() { } -void BaseEntity::store() const +QUrl BaseEntity::url() const { - Json::write(serialized(), Meta::localDir().absoluteFilePath(localFilename())); + return rootUrl().resolved(localFilename()); } void BaseEntity::notifyLocalLoadComplete() { m_localLoaded = true; - store(); } + void BaseEntity::notifyRemoteLoadComplete() { m_remoteLoaded = true; - store(); } } diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h index b7a241c6..7064e9d2 100644 --- a/api/logic/meta/BaseEntity.h +++ b/api/logic/meta/BaseEntity.h @@ -17,6 +17,7 @@ #include #include +#include #include "multimc_logic_export.h" @@ -33,10 +34,10 @@ public: virtual std::unique_ptr remoteUpdateTask() = 0; virtual std::unique_ptr localUpdateTask() = 0; virtual void merge(const std::shared_ptr &other) = 0; + virtual void parse(const QJsonObject &obj) = 0; - void store() const; virtual QString localFilename() const = 0; - virtual QJsonObject serialized() const = 0; + virtual QUrl url() const; bool isComplete() const { return m_localLoaded || m_remoteLoaded; } diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp index 8a6b1355..e0e8bc5d 100644 --- a/api/logic/meta/Index.cpp +++ b/api/logic/meta/Index.cpp @@ -80,29 +80,36 @@ QVariant Index::headerData(int section, Qt::Orientation orientation, int role) c std::unique_ptr Index::remoteUpdateTask() { - return std::unique_ptr(new IndexRemoteLoadTask(this, this)); + return std::unique_ptr(new RemoteLoadTask(this)); } std::unique_ptr Index::localUpdateTask() { - return std::unique_ptr(new IndexLocalLoadTask(this, this)); -} - -QJsonObject Index::serialized() const -{ - return Format::serializeIndex(this); + return std::unique_ptr(new LocalLoadTask(this)); } bool Index::hasUid(const QString &uid) const { return m_uids.contains(uid); } -VersionListPtr Index::getList(const QString &uid) const + +VersionListPtr Index::get(const QString &uid) { return m_uids.value(uid, nullptr); } -VersionListPtr Index::getListGuaranteed(const QString &uid) const + +VersionPtr Index::get(const QString &uid, const QString &version) +{ + auto list = get(uid); + if(list) + { + return list->getVersion(version); + } + return nullptr; +} + +void Index::parse(const QJsonObject& obj) { - return m_uids.value(uid, std::make_shared(uid)); + parseIndex(obj, this); } void Index::merge(const Ptr &other) diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h index 16e95d5a..37341656 100644 --- a/api/logic/meta/Index.h +++ b/api/logic/meta/Index.h @@ -27,6 +27,7 @@ class Task; namespace Meta { using VersionListPtr = std::shared_ptr; +using VersionPtr = std::shared_ptr; class MULTIMC_LOGIC_EXPORT Index : public QAbstractListModel, public BaseEntity { @@ -51,17 +52,21 @@ public: std::unique_ptr localUpdateTask() override; QString localFilename() const override { return "index.json"; } - QJsonObject serialized() const override; // queries + VersionListPtr get(const QString &uid); + VersionPtr get(const QString &uid, const QString &version); bool hasUid(const QString &uid) const; + /* VersionListPtr getList(const QString &uid) const; VersionListPtr getListGuaranteed(const QString &uid) const; + */ QVector lists() const { return m_lists; } public: // for usage by parsers only void merge(const BaseEntity::Ptr &other) override; + void parse(const QJsonObject &obj) override; private: QVector m_lists; diff --git a/api/logic/meta/Index_test.cpp b/api/logic/meta/Index_test.cpp index d26700ca..b4dbd009 100644 --- a/api/logic/meta/Index_test.cpp +++ b/api/logic/meta/Index_test.cpp @@ -27,9 +27,9 @@ slots: Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); QVERIFY(windex.hasUid("list1")); QVERIFY(!windex.hasUid("asdf")); - QVERIFY(windex.getList("list2") != nullptr); - QCOMPARE(windex.getList("list2")->uid(), QString("list2")); - QVERIFY(windex.getList("adsf") == nullptr); + QVERIFY(windex.get("list2") != nullptr); + QCOMPARE(windex.get("list2")->uid(), QString("list2")); + QVERIFY(windex.get("adsf") == nullptr); } void test_merge() diff --git a/api/logic/meta/Util.h b/api/logic/meta/Util.h index 28163fe4..188bcaa3 100644 --- a/api/logic/meta/Util.h +++ b/api/logic/meta/Util.h @@ -24,8 +24,5 @@ class QDir; namespace Meta { MULTIMC_LOGIC_EXPORT QUrl rootUrl(); -MULTIMC_LOGIC_EXPORT QUrl indexUrl(); -MULTIMC_LOGIC_EXPORT QUrl versionListUrl(const QString &uid); -MULTIMC_LOGIC_EXPORT QUrl versionUrl(const QString &uid, const QString &version); MULTIMC_LOGIC_EXPORT QDir localDir(); } diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index 039f4fef..b79c178a 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -48,11 +48,16 @@ QDateTime Version::time() const std::unique_ptr Version::remoteUpdateTask() { - return std::unique_ptr(new VersionRemoteLoadTask(this, this)); + return std::unique_ptr(new RemoteLoadTask(this)); } std::unique_ptr Version::localUpdateTask() { - return std::unique_ptr(new VersionLocalLoadTask(this, this)); + return std::unique_ptr(new LocalLoadTask(this)); +} + +void Version::parse(const QJsonObject& obj) +{ + parseVersion(obj, this); } void Version::merge(const std::shared_ptr &other) @@ -78,10 +83,6 @@ QString Version::localFilename() const { return m_uid + '/' + m_version + ".json"; } -QJsonObject Version::serialized() const -{ - return Format::serializeVersion(this); -} void Version::setType(const QString &type) { diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index 4a791880..635b79f6 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -59,9 +59,9 @@ public: std::unique_ptr remoteUpdateTask() override; std::unique_ptr localUpdateTask() override; void merge(const std::shared_ptr &other) override; + void parse(const QJsonObject &obj) override; QString localFilename() const override; - QJsonObject serialized() const override; public: // for usage by format parsers only void setType(const QString &type); diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index aab3e0f7..7196d4be 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -169,21 +169,17 @@ QHash VersionList::roleNames() const std::unique_ptr VersionList::remoteUpdateTask() { - return std::unique_ptr(new VersionListRemoteLoadTask(this, this)); + return std::unique_ptr(new RemoteLoadTask(this)); } std::unique_ptr VersionList::localUpdateTask() { - return std::unique_ptr(new VersionListLocalLoadTask(this, this)); + return std::unique_ptr(new LocalLoadTask(this)); } QString VersionList::localFilename() const { return m_uid + "/index.json"; } -QJsonObject VersionList::serialized() const -{ - return Format::serializeVersionList(this); -} QString VersionList::humanReadable() const { @@ -224,6 +220,11 @@ void VersionList::setVersions(const QVector &versions) endResetModel(); } +void VersionList::parse(const QJsonObject& obj) +{ + parseVersionList(obj, this); +} + void VersionList::merge(const BaseEntity::Ptr &other) { const VersionListPtr list = std::dynamic_pointer_cast(other); @@ -285,4 +286,5 @@ BaseVersionPtr VersionList::getRecommended() const } + #include "VersionList.moc" diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index 0eb85bf8..934b20e4 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -17,6 +17,7 @@ #include "BaseVersionList.h" #include "BaseEntity.h" +#include #include namespace Meta @@ -57,7 +58,6 @@ public: std::unique_ptr localUpdateTask() override; QString localFilename() const override; - QJsonObject serialized() const override; QString uid() const { return m_uid; } QString name() const { return m_name; } @@ -72,6 +72,7 @@ public: // for usage only by parsers void setName(const QString &name); void setVersions(const QVector &versions); void merge(const BaseEntity::Ptr &other) override; + void parse(const QJsonObject &obj) override; signals: void nameChanged(const QString &name); diff --git a/api/logic/meta/format/Format.cpp b/api/logic/meta/format/Format.cpp index e0fddb0b..39d3f14f 100644 --- a/api/logic/meta/format/Format.cpp +++ b/api/logic/meta/format/Format.cpp @@ -15,15 +15,85 @@ #include "Format.h" -#include "FormatV1.h" +#include "minecraft/onesix/OneSixVersionFormat.h"" #include "meta/Index.h" #include "meta/Version.h" #include "meta/VersionList.h" +#include "Json.h" +using namespace Json; + namespace Meta { +static const int currentFormatVersion = 0; + +// Index +static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) +{ + 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); +} + +// 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; +} + +static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) +{ + 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; +} + +// Version list / package +static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) +{ + 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), [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; +} + + static int formatVersion(const QJsonObject &obj) { if (!obj.contains("formatVersion")) { @@ -35,56 +105,39 @@ static int formatVersion(const QJsonObject &obj) return obj.value("formatVersion").toInt(); } -void Format::parseIndex(const QJsonObject &obj, Index *ptr) +void parseIndex(const QJsonObject &obj, Index *ptr) { const int version = formatVersion(obj); switch (version) { case 0: - ptr->merge(FormatV1().parseIndexInternal(obj)); + ptr->merge(parseIndexInternal(obj)); break; default: throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); } } -void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr) +void parseVersionList(const QJsonObject &obj, VersionList *ptr) { const int version = formatVersion(obj); switch (version) { case 0: - ptr->merge(FormatV1().parseVersionListInternal(obj)); + ptr->merge(parseVersionListInternal(obj)); break; default: throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); } } -void Format::parseVersion(const QJsonObject &obj, Version *ptr) +void parseVersion(const QJsonObject &obj, Version *ptr) { const int version = formatVersion(obj); switch (version) { case 0: - ptr->merge(FormatV1().parseVersionInternal(obj)); + ptr->merge(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::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/Format.h b/api/logic/meta/format/Format.h index 79605a6f..aaed07fc 100644 --- a/api/logic/meta/format/Format.h +++ b/api/logic/meta/format/Format.h @@ -33,25 +33,8 @@ public: using Exception::Exception; }; -class Format -{ -public: - virtual ~Format() {} - - static void parseIndex(const QJsonObject &obj, Index *ptr); - static void parseVersion(const QJsonObject &obj, Version *ptr); - static void parseVersionList(const QJsonObject &obj, VersionList *ptr); +void parseIndex(const QJsonObject &obj, Index *ptr); +void parseVersion(const QJsonObject &obj, Version *ptr); +void parseVersionList(const QJsonObject &obj, VersionList *ptr); - static QJsonObject serializeIndex(const Index *ptr); - static QJsonObject serializeVersion(const Version *ptr); - static QJsonObject serializeVersionList(const VersionList *ptr); - -protected: - virtual BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) const = 0; - virtual BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) const = 0; - virtual BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const = 0; - virtual QJsonObject serializeIndexInternal(const Index *ptr) const = 0; - virtual QJsonObject serializeVersionInternal(const Version *ptr) const = 0; - virtual QJsonObject serializeVersionListInternal(const VersionList *ptr) const = 0; -}; } 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; -} -} diff --git a/api/logic/meta/format/FormatV1.h b/api/logic/meta/format/FormatV1.h deleted file mode 100644 index ab986083..00000000 --- a/api/logic/meta/format/FormatV1.h +++ /dev/null @@ -1,33 +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. - */ - -#pragma once - -#include "Format.h" - -namespace Meta -{ -class FormatV1 : public Format -{ -public: - BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) const override; - BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) const override; - BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const override; - - QJsonObject serializeIndexInternal(const Index *ptr) const override; - QJsonObject serializeVersionInternal(const Version *ptr) const override; - QJsonObject serializeVersionListInternal(const VersionList *ptr) const override; -}; -} diff --git a/api/logic/meta/tasks/LocalLoadTask.cpp b/api/logic/meta/tasks/LocalLoadTask.cpp index 33ea8016..b64fc5d3 100644 --- a/api/logic/meta/tasks/LocalLoadTask.cpp +++ b/api/logic/meta/tasks/LocalLoadTask.cpp @@ -34,19 +34,18 @@ LocalLoadTask::LocalLoadTask(BaseEntity *entity, QObject *parent) void LocalLoadTask::executeTask() { - const QString fname = Meta::localDir().absoluteFilePath(filename()); + const QString fname = Meta::localDir().absoluteFilePath(m_entity->localFilename()); if (!QFile::exists(fname)) { emitFailed(tr("File doesn't exist")); return; } - - setStatus(tr("Reading %1...").arg(name())); + setStatus(tr("Reading %1...").arg(fname)); setProgress(0, 0); try { - parse(Json::requireObject(Json::requireDocument(fname, name()), name())); + m_entity->parse(Json::requireObject(Json::requireDocument(fname, fname), fname)); m_entity->notifyLocalLoadComplete(); emitSucceeded(); } @@ -55,69 +54,4 @@ void LocalLoadTask::executeTask() emitFailed(tr("Unable to parse file %1: %2").arg(fname, e.cause())); } } - - -// INDEX -IndexLocalLoadTask::IndexLocalLoadTask(Index *index, QObject *parent) - : LocalLoadTask(index, parent) -{ -} -QString IndexLocalLoadTask::filename() const -{ - return "index.json"; -} -QString IndexLocalLoadTask::name() const -{ - return tr("Metadata Index"); -} -void IndexLocalLoadTask::parse(const QJsonObject &obj) const -{ - Format::parseIndex(obj, dynamic_cast(entity())); -} - - -// VERSION LIST -VersionListLocalLoadTask::VersionListLocalLoadTask(VersionList *list, QObject *parent) - : LocalLoadTask(list, parent) -{ -} -QString VersionListLocalLoadTask::filename() const -{ - return list()->uid() + ".json"; -} -QString VersionListLocalLoadTask::name() const -{ - return tr("Version List for %1").arg(list()->humanReadable()); -} -void VersionListLocalLoadTask::parse(const QJsonObject &obj) const -{ - Format::parseVersionList(obj, list()); -} -VersionList *VersionListLocalLoadTask::list() const -{ - return dynamic_cast(entity()); -} - - -// VERSION -VersionLocalLoadTask::VersionLocalLoadTask(Version *version, QObject *parent) - : LocalLoadTask(version, parent) -{ -} -QString VersionLocalLoadTask::filename() const -{ - return version()->uid() + "/" + version()->version() + ".json"; -} -QString VersionLocalLoadTask::name() const -{ - return tr(" Version for %1").arg(version()->name()); -} -void VersionLocalLoadTask::parse(const QJsonObject &obj) const -{ - Format::parseVersion(obj, version()); -} -Version *VersionLocalLoadTask::version() const -{ - return dynamic_cast(entity()); -} } diff --git a/api/logic/meta/tasks/LocalLoadTask.h b/api/logic/meta/tasks/LocalLoadTask.h index 36ae1b6f..905660ed 100644 --- a/api/logic/meta/tasks/LocalLoadTask.h +++ b/api/logic/meta/tasks/LocalLoadTask.h @@ -25,60 +25,15 @@ class Index; class VersionList; class Version; +// FIXME: this is now just an odd function, get rid of it class LocalLoadTask : public Task { Q_OBJECT public: explicit LocalLoadTask(BaseEntity *entity, QObject *parent = nullptr); -protected: - virtual QString filename() const = 0; - virtual QString name() const = 0; - virtual void parse(const QJsonObject &obj) const = 0; - - BaseEntity *entity() const { return m_entity; } - private: void executeTask() override; - BaseEntity *m_entity; }; - -class IndexLocalLoadTask : public LocalLoadTask -{ - Q_OBJECT -public: - explicit IndexLocalLoadTask(Index *index, QObject *parent = nullptr); - -private: - QString filename() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; -}; -class VersionListLocalLoadTask : public LocalLoadTask -{ - Q_OBJECT -public: - explicit VersionListLocalLoadTask(VersionList *list, QObject *parent = nullptr); - -private: - QString filename() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - VersionList *list() const; -}; -class VersionLocalLoadTask : public LocalLoadTask -{ - Q_OBJECT -public: - explicit VersionLocalLoadTask(Version *version, QObject *parent = nullptr); - -private: - QString filename() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - Version *version() const; -}; } diff --git a/api/logic/meta/tasks/RemoteLoadTask.cpp b/api/logic/meta/tasks/RemoteLoadTask.cpp index 69a59c07..b73af021 100644 --- a/api/logic/meta/tasks/RemoteLoadTask.cpp +++ b/api/logic/meta/tasks/RemoteLoadTask.cpp @@ -34,99 +34,70 @@ RemoteLoadTask::RemoteLoadTask(BaseEntity *entity, QObject *parent) { } -void RemoteLoadTask::executeTask() -{ - NetJob *job = new NetJob(name()); - - auto entry = ENV.metacache()->resolveEntry("meta", url().toString()); - entry->setStale(true); - m_dl = Net::Download::makeCached(url(), entry); - job->addNetAction(m_dl); - connect(job, &NetJob::failed, this, &RemoteLoadTask::emitFailed); - connect(job, &NetJob::succeeded, this, &RemoteLoadTask::networkFinished); - connect(job, &NetJob::status, this, &RemoteLoadTask::setStatus); - connect(job, &NetJob::progress, this, &RemoteLoadTask::setProgress); - job->start(); -} - -void RemoteLoadTask::networkFinished() +class ParsingValidator : public Net::Validator { - setStatus(tr("Parsing...")); - setProgress(0, 0); +public: /* con/des */ + ParsingValidator(BaseEntity *entity) : m_entity(entity) + { + }; + virtual ~ParsingValidator() + { + }; - try +public: /* methods */ + bool init(QNetworkRequest &) override { - parse(Json::requireObject(Json::requireDocument(m_dl->getTargetFilepath(), name()), name())); - m_entity->notifyRemoteLoadComplete(); - emitSucceeded(); + return true; } - catch (Exception &e) + bool write(QByteArray & data) override { - emitFailed(tr("Unable to parse response: %1").arg(e.cause())); + this->data.append(data); + return true; + } + bool abort() override + { + return true; + } + bool validate(QNetworkReply &) override + { + auto fname = m_entity->localFilename(); + try + { + m_entity->parse(Json::requireObject(Json::requireDocument(data, fname), fname)); + m_entity->notifyRemoteLoadComplete(); + return true; + } + catch (Exception &e) + { + qWarning() << "Unable to parse response:" << e.cause(); + return false; + } } -} - -// INDEX -IndexRemoteLoadTask::IndexRemoteLoadTask(Index *index, QObject *parent) - : RemoteLoadTask(index, parent) -{ -} -QUrl IndexRemoteLoadTask::url() const -{ - return Meta::indexUrl(); -} -QString IndexRemoteLoadTask::name() const -{ - return tr("Metadata Index"); -} -void IndexRemoteLoadTask::parse(const QJsonObject &obj) const -{ - Format::parseIndex(obj, dynamic_cast(entity())); -} +private: /* data */ + QByteArray data; + BaseEntity *m_entity; +}; -// VERSION LIST -VersionListRemoteLoadTask::VersionListRemoteLoadTask(VersionList *list, QObject *parent) - : RemoteLoadTask(list, parent) -{ -} -QUrl VersionListRemoteLoadTask::url() const -{ - return Meta::versionListUrl(list()->uid()); -} -QString VersionListRemoteLoadTask::name() const -{ - return tr("Version List for %1").arg(list()->humanReadable()); -} -void VersionListRemoteLoadTask::parse(const QJsonObject &obj) const -{ - Format::parseVersionList(obj, list()); -} -VersionList* Meta::VersionListRemoteLoadTask::list() const +void RemoteLoadTask::executeTask() { - return dynamic_cast(entity()); -} + // FIXME: leak here!!! + NetJob *job = new NetJob(tr("Download of meta file %1").arg(m_entity->localFilename())); - -// VERSION -VersionRemoteLoadTask::VersionRemoteLoadTask(Version *version, QObject *parent) - : RemoteLoadTask(version, parent) -{ -} -QUrl VersionRemoteLoadTask::url() const -{ - return Meta::versionUrl(version()->uid(), version()->version()); -} -QString VersionRemoteLoadTask::name() const -{ - return tr("Meta Version for %1").arg(version()->name()); -} -void VersionRemoteLoadTask::parse(const QJsonObject &obj) const -{ - Format::parseVersion(obj, version()); -} -Version *VersionRemoteLoadTask::version() const -{ - return dynamic_cast(entity()); + auto url = m_entity->url(); + auto entry = ENV.metacache()->resolveEntry("meta", m_entity->localFilename()); + entry->setStale(true); + m_dl = Net::Download::makeCached(url, entry); + /* + * The validator parses the file and loads it into the object. + * If that fails, the file is not written to storage. + */ + m_dl->addValidator(new ParsingValidator(m_entity)); + job->addNetAction(m_dl); + connect(job, &NetJob::failed, this, &RemoteLoadTask::emitFailed); + connect(job, &NetJob::succeeded, this, &RemoteLoadTask::succeeded); + connect(job, &NetJob::status, this, &RemoteLoadTask::setStatus); + connect(job, &NetJob::progress, this, &RemoteLoadTask::setProgress); + job->start(); } } diff --git a/api/logic/meta/tasks/RemoteLoadTask.h b/api/logic/meta/tasks/RemoteLoadTask.h index 3b09404f..6d81d8ea 100644 --- a/api/logic/meta/tasks/RemoteLoadTask.h +++ b/api/logic/meta/tasks/RemoteLoadTask.h @@ -30,66 +30,17 @@ class Index; class VersionList; class Version; +// FIXME: this is now just an oddly constructed NetJob, get rid of it. class RemoteLoadTask : public Task { Q_OBJECT public: explicit RemoteLoadTask(BaseEntity *entity, QObject *parent = nullptr); -protected: - virtual QUrl url() const = 0; - virtual QString name() const = 0; - virtual void parse(const QJsonObject &obj) const = 0; - - BaseEntity *entity() const { return m_entity; } - -private slots: - void networkFinished(); - private: void executeTask() override; BaseEntity *m_entity; std::shared_ptr m_dl; }; - -class IndexRemoteLoadTask : public RemoteLoadTask -{ - Q_OBJECT -public: - explicit IndexRemoteLoadTask(Index *index, QObject *parent = nullptr); - -private: - QUrl url() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; -}; - -class VersionListRemoteLoadTask : public RemoteLoadTask -{ - Q_OBJECT -public: - explicit VersionListRemoteLoadTask(VersionList *list, QObject *parent = nullptr); - -private: - QUrl url() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - VersionList *list() const; -}; - -class VersionRemoteLoadTask : public RemoteLoadTask -{ - Q_OBJECT -public: - explicit VersionRemoteLoadTask(Version *version, QObject *parent = nullptr); - -private: - QUrl url() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - Version *version() const; -}; } diff --git a/application/pages/global/PackagesPage.cpp b/application/pages/global/PackagesPage.cpp index 52efaf9a..81ad4da1 100644 --- a/application/pages/global/PackagesPage.cpp +++ b/application/pages/global/PackagesPage.cpp @@ -36,7 +36,7 @@ static QString formatRequires(const VersionPtr &version) QStringList lines; for (const Reference &ref : version->requires()) { - const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->getList(ref.uid())->humanReadable() : ref.uid(); + const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->get(ref.uid())->humanReadable() : ref.uid(); if (ref.version().isEmpty()) { lines.append(readable); -- cgit From e46aba9da584338db8d8a1a8a487bdcc6cf84343 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 18 Mar 2017 02:22:36 +0100 Subject: NOISSUE sanitize loading and downloading of metadata files --- api/logic/CMakeLists.txt | 10 +-- api/logic/meta/BaseEntity.cpp | 119 +++++++++++++++++++++--- api/logic/meta/BaseEntity.h | 45 +++++++--- api/logic/meta/Index.cpp | 13 +-- api/logic/meta/Index.h | 7 -- api/logic/meta/Index_test.cpp | 6 -- api/logic/meta/JsonFormat.cpp | 144 ++++++++++++++++++++++++++++++ api/logic/meta/JsonFormat.h | 40 +++++++++ api/logic/meta/Util.cpp | 50 ----------- api/logic/meta/Util.h | 28 ------ api/logic/meta/Version.cpp | 13 +-- api/logic/meta/Version.h | 2 - api/logic/meta/VersionList.cpp | 70 ++------------- api/logic/meta/VersionList.h | 3 - api/logic/meta/format/Format.cpp | 143 ----------------------------- api/logic/meta/format/Format.h | 40 --------- api/logic/meta/tasks/LocalLoadTask.cpp | 57 ------------ api/logic/meta/tasks/LocalLoadTask.h | 39 -------- api/logic/meta/tasks/RemoteLoadTask.cpp | 103 --------------------- api/logic/meta/tasks/RemoteLoadTask.h | 46 ---------- application/MainWindow.cpp | 15 +--- application/pages/global/PackagesPage.cpp | 33 ++----- 22 files changed, 340 insertions(+), 686 deletions(-) create mode 100644 api/logic/meta/JsonFormat.cpp create mode 100644 api/logic/meta/JsonFormat.h delete mode 100644 api/logic/meta/Util.cpp delete mode 100644 api/logic/meta/Util.h delete mode 100644 api/logic/meta/format/Format.cpp delete mode 100644 api/logic/meta/format/Format.h delete mode 100644 api/logic/meta/tasks/LocalLoadTask.cpp delete mode 100644 api/logic/meta/tasks/LocalLoadTask.h delete mode 100644 api/logic/meta/tasks/RemoteLoadTask.cpp delete mode 100644 api/logic/meta/tasks/RemoteLoadTask.h (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 42754157..544ace80 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -416,12 +416,8 @@ set(TOOLS_SOURCES set(META_SOURCES # Metadata sources - meta/tasks/RemoteLoadTask.cpp - meta/tasks/RemoteLoadTask.h - meta/tasks/LocalLoadTask.cpp - meta/tasks/LocalLoadTask.h - meta/format/Format.cpp - meta/format/Format.h + meta/JsonFormat.cpp + meta/JsonFormat.h meta/BaseEntity.cpp meta/BaseEntity.h meta/VersionList.cpp @@ -430,8 +426,6 @@ set(META_SOURCES meta/Version.h meta/Index.cpp meta/Index.h - meta/Util.cpp - meta/Util.h meta/Reference.cpp meta/Reference.h ) diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp index 87cd55c8..18b7f92f 100644 --- a/api/logic/meta/BaseEntity.cpp +++ b/api/logic/meta/BaseEntity.cpp @@ -16,26 +16,125 @@ #include "BaseEntity.h" #include "Json.h" -#include "Util.h" -namespace Meta +#include "net/Download.h" +#include "net/HttpMetaCache.h" +#include "net/NetJob.h" + +#include "Env.h" +#include "Json.h" + +class ParsingValidator : public Net::Validator { -BaseEntity::~BaseEntity() +public: /* con/des */ + ParsingValidator(Meta::BaseEntity *entity) : m_entity(entity) + { + }; + virtual ~ParsingValidator() + { + }; + +public: /* methods */ + bool init(QNetworkRequest &) override + { + return true; + } + bool write(QByteArray & data) override + { + this->data.append(data); + return true; + } + bool abort() override + { + return true; + } + bool validate(QNetworkReply &) override + { + auto fname = m_entity->localFilename(); + try + { + m_entity->parse(Json::requireObject(Json::requireDocument(data, fname), fname)); + return true; + } + catch (Exception &e) + { + qWarning() << "Unable to parse response:" << e.cause(); + return false; + } + } + +private: /* data */ + QByteArray data; + Meta::BaseEntity *m_entity; +}; + +Meta::BaseEntity::~BaseEntity() { } -QUrl BaseEntity::url() const +QUrl Meta::BaseEntity::url() const { - return rootUrl().resolved(localFilename()); + return QUrl("https://meta.multimc.org").resolved(localFilename()); } -void BaseEntity::notifyLocalLoadComplete() +bool Meta::BaseEntity::loadLocalFile() { - m_localLoaded = true; + const QString fname = QDir("meta").absoluteFilePath(localFilename()); + if (!QFile::exists(fname)) + { + return false; + } + // TODO: check if the file has the expected checksum + try + { + parse(Json::requireObject(Json::requireDocument(fname, fname), fname)); + return true; + } + catch (Exception &e) + { + qDebug() << QString("Unable to parse file %1: %2").arg(fname, e.cause()); + // just make sure it's gone and we never consider it again. + QFile::remove(fname); + return false; + } } -void BaseEntity::notifyRemoteLoadComplete() +void Meta::BaseEntity::load() { - m_remoteLoaded = true; -} + if(!isLoaded()) + { + loadLocalFile(); + } + if(!shouldStartRemoteUpdate()) + { + return; + } + NetJob *job = new NetJob(QObject::tr("Download of meta file %1").arg(localFilename())); + + auto url = this->url(); + auto entry = ENV.metacache()->resolveEntry("meta", localFilename()); + entry->setStale(true); + auto dl = Net::Download::makeCached(url, entry); + /* + * The validator parses the file and loads it into the object. + * If that fails, the file is not written to storage. + */ + dl->addValidator(new ParsingValidator(this)); + job->addNetAction(dl); + m_updateStatus = UpdateStatus::InProgress; + m_updateTask.reset(job); + QObject::connect(job, &NetJob::succeeded, [&]() + { + m_loadStatus = LoadStatus::Remote; + m_updateStatus = UpdateStatus::Succeeded; + m_updateTask.reset(); + }); + QObject::connect(job, &NetJob::failed, [&]() + { + m_updateStatus = UpdateStatus::Failed; + m_updateTask.reset(); + }); + m_updateTask->start(); } + +#include "BaseEntity.moc" diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h index 7064e9d2..92a39272 100644 --- a/api/logic/meta/BaseEntity.h +++ b/api/logic/meta/BaseEntity.h @@ -15,9 +15,9 @@ #pragma once -#include -#include #include +#include +#include "QObjectPtr.h" #include "multimc_logic_export.h" @@ -26,29 +26,48 @@ namespace Meta { class MULTIMC_LOGIC_EXPORT BaseEntity { +public: /* types */ + using Ptr = std::shared_ptr; + enum class LoadStatus + { + NotLoaded, + Local, + Remote + }; + enum class UpdateStatus + { + NotDone, + InProgress, + Failed, + Succeeded + }; + public: virtual ~BaseEntity(); - using Ptr = std::shared_ptr; - - virtual std::unique_ptr remoteUpdateTask() = 0; - virtual std::unique_ptr localUpdateTask() = 0; virtual void merge(const std::shared_ptr &other) = 0; virtual void parse(const QJsonObject &obj) = 0; virtual QString localFilename() const = 0; virtual QUrl url() const; - bool isComplete() const { return m_localLoaded || m_remoteLoaded; } + bool isLoaded() const + { + return m_loadStatus > LoadStatus::NotLoaded; + } + bool shouldStartRemoteUpdate() const + { + return m_updateStatus == UpdateStatus::NotDone; + } - bool isLocalLoaded() const { return m_localLoaded; } - bool isRemoteLoaded() const { return m_remoteLoaded; } + void load(); - void notifyLocalLoadComplete(); - void notifyRemoteLoadComplete(); +protected: /* methods */ + bool loadLocalFile(); private: - bool m_localLoaded = false; - bool m_remoteLoaded = false; + LoadStatus m_loadStatus = LoadStatus::NotLoaded; + UpdateStatus m_updateStatus = UpdateStatus::NotDone; + shared_qobject_ptr m_updateTask; }; } diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp index e0e8bc5d..35b9fb6f 100644 --- a/api/logic/meta/Index.cpp +++ b/api/logic/meta/Index.cpp @@ -16,9 +16,7 @@ #include "Index.h" #include "VersionList.h" -#include "tasks/LocalLoadTask.h" -#include "tasks/RemoteLoadTask.h" -#include "format/Format.h" +#include "JsonFormat.h" namespace Meta { @@ -78,15 +76,6 @@ QVariant Index::headerData(int section, Qt::Orientation orientation, int role) c } } -std::unique_ptr Index::remoteUpdateTask() -{ - return std::unique_ptr(new RemoteLoadTask(this)); -} -std::unique_ptr Index::localUpdateTask() -{ - return std::unique_ptr(new LocalLoadTask(this)); -} - bool Index::hasUid(const QString &uid) const { return m_uids.contains(uid); diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h index 37341656..544a8b96 100644 --- a/api/logic/meta/Index.h +++ b/api/logic/meta/Index.h @@ -48,19 +48,12 @@ public: int columnCount(const QModelIndex &parent) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - std::unique_ptr remoteUpdateTask() override; - std::unique_ptr localUpdateTask() override; - QString localFilename() const override { return "index.json"; } // queries VersionListPtr get(const QString &uid); VersionPtr get(const QString &uid, const QString &version); bool hasUid(const QString &uid) const; - /* - VersionListPtr getList(const QString &uid) const; - VersionListPtr getListGuaranteed(const QString &uid) const; - */ QVector lists() const { return m_lists; } diff --git a/api/logic/meta/Index_test.cpp b/api/logic/meta/Index_test.cpp index b4dbd009..d4343c37 100644 --- a/api/logic/meta/Index_test.cpp +++ b/api/logic/meta/Index_test.cpp @@ -16,12 +16,6 @@ slots: QCOMPARE(ENV.metadataIndex(), ENV.metadataIndex()); } - void test_providesTasks() - { - QVERIFY(ENV.metadataIndex()->localUpdateTask() != nullptr); - QVERIFY(ENV.metadataIndex()->remoteUpdateTask() != nullptr); - } - void test_hasUid_and_getList() { Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp new file mode 100644 index 00000000..4e43b715 --- /dev/null +++ b/api/logic/meta/JsonFormat.cpp @@ -0,0 +1,144 @@ +/* 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 "JsonFormat.h" + +// FIXME: remove this from here... somehow +#include "minecraft/onesix/OneSixVersionFormat.h" +#include "Json.h" + +#include "Index.h" +#include "Version.h" +#include "VersionList.h" + +using namespace Json; + +namespace Meta +{ + +static const int currentFormatVersion = 0; + +// Index +static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) +{ + 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); +} + +// 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; +} + +static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) +{ + 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; +} + +// Version list / package +static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) +{ + 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), [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; +} + + +static int formatVersion(const QJsonObject &obj) +{ + if (!obj.contains("formatVersion")) { + throw ParseException(QObject::tr("Missing required field: 'formatVersion'")); + } + if (!obj.value("formatVersion").isDouble()) { + throw ParseException(QObject::tr("Required field has invalid type: 'formatVersion'")); + } + return obj.value("formatVersion").toInt(); +} + +void parseIndex(const QJsonObject &obj, Index *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 0: + ptr->merge(parseIndexInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} + +void parseVersionList(const QJsonObject &obj, VersionList *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 0: + ptr->merge(parseVersionListInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} + +void parseVersion(const QJsonObject &obj, Version *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 0: + ptr->merge(parseVersionInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} +} diff --git a/api/logic/meta/JsonFormat.h b/api/logic/meta/JsonFormat.h new file mode 100644 index 00000000..aaed07fc --- /dev/null +++ b/api/logic/meta/JsonFormat.h @@ -0,0 +1,40 @@ +/* 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. + */ + +#pragma once + +#include +#include + +#include "Exception.h" +#include "meta/BaseEntity.h" + +namespace Meta +{ +class Index; +class Version; +class VersionList; + +class ParseException : public Exception +{ +public: + using Exception::Exception; +}; + +void parseIndex(const QJsonObject &obj, Index *ptr); +void parseVersion(const QJsonObject &obj, Version *ptr); +void parseVersionList(const QJsonObject &obj, VersionList *ptr); + +} diff --git a/api/logic/meta/Util.cpp b/api/logic/meta/Util.cpp deleted file mode 100644 index 76941f83..00000000 --- a/api/logic/meta/Util.cpp +++ /dev/null @@ -1,50 +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 "Util.h" - -#include -#include - -#include "Env.h" - -namespace Meta -{ -QUrl rootUrl() -{ - return QUrl("https://meta.multimc.org"); -} - -QUrl indexUrl() -{ - return rootUrl().resolved(QStringLiteral("index.json")); -} - -QUrl versionListUrl(const QString &uid) -{ - return rootUrl().resolved(uid + "/index.json"); -} - -QUrl versionUrl(const QString &uid, const QString &version) -{ - return rootUrl().resolved(uid + "/" + version + ".json"); -} - -QDir localDir() -{ - return QDir("meta"); -} - -} diff --git a/api/logic/meta/Util.h b/api/logic/meta/Util.h deleted file mode 100644 index 188bcaa3..00000000 --- a/api/logic/meta/Util.h +++ /dev/null @@ -1,28 +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. - */ - -#pragma once - -#include "multimc_logic_export.h" - -class QUrl; -class QString; -class QDir; - -namespace Meta -{ -MULTIMC_LOGIC_EXPORT QUrl rootUrl(); -MULTIMC_LOGIC_EXPORT QDir localDir(); -} diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index b79c178a..f8c865e7 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -17,9 +17,7 @@ #include -#include "tasks/LocalLoadTask.h" -#include "tasks/RemoteLoadTask.h" -#include "format/Format.h" +#include "JsonFormat.h" namespace Meta { @@ -46,15 +44,6 @@ QDateTime Version::time() const return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC); } -std::unique_ptr Version::remoteUpdateTask() -{ - return std::unique_ptr(new RemoteLoadTask(this)); -} -std::unique_ptr Version::localUpdateTask() -{ - return std::unique_ptr(new LocalLoadTask(this)); -} - void Version::parse(const QJsonObject& obj) { parseVersion(obj, this); diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index 635b79f6..0be2d94a 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -56,8 +56,6 @@ public: QVector requires() const { return m_requires; } VersionFilePtr data() const { return m_data; } - std::unique_ptr remoteUpdateTask() override; - std::unique_ptr localUpdateTask() override; void merge(const std::shared_ptr &other) override; void parse(const QJsonObject &obj) override; diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 7196d4be..a12f5418 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -18,64 +18,11 @@ #include #include "Version.h" -#include "tasks/RemoteLoadTask.h" -#include "tasks/LocalLoadTask.h" -#include "format/Format.h" +#include "JsonFormat.h" #include "Reference.h" namespace Meta { - -class WVLLoadTask : public Task -{ - Q_OBJECT -public: - explicit WVLLoadTask(VersionList *list, QObject *parent = nullptr) - : Task(parent), m_list(list) - { - } - - bool canAbort() const override - { - return !m_currentTask || m_currentTask->canAbort(); - } - bool abort() override - { - return m_currentTask->abort(); - } - -private: - void executeTask() override - { - if (!m_list->isLocalLoaded()) - { - m_currentTask = m_list->localUpdateTask(); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::next); - } - else - { - m_currentTask = m_list->remoteUpdateTask(); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::emitSucceeded); - } - connect(m_currentTask.get(), &Task::status, this, &WVLLoadTask::setStatus); - connect(m_currentTask.get(), &Task::progress, this, &WVLLoadTask::setProgress); - connect(m_currentTask.get(), &Task::failed, this, &WVLLoadTask::emitFailed); - m_currentTask->start(); - } - - void next() - { - m_currentTask = m_list->remoteUpdateTask(); - connect(m_currentTask.get(), &Task::status, this, &WVLLoadTask::setStatus); - connect(m_currentTask.get(), &Task::progress, this, &WVLLoadTask::setProgress); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::emitSucceeded); - m_currentTask->start(); - } - - VersionList *m_list; - std::unique_ptr m_currentTask; -}; - VersionList::VersionList(const QString &uid, QObject *parent) : BaseVersionList(parent), m_uid(uid) { @@ -84,12 +31,13 @@ VersionList::VersionList(const QString &uid, QObject *parent) Task *VersionList::getLoadTask() { - return new WVLLoadTask(this); + // TODO: create a wrapper task that will chain from root to here. + return nullptr; } bool VersionList::isLoaded() { - return isLocalLoaded() && isRemoteLoaded(); + return isLoaded(); } const BaseVersionPtr VersionList::at(int i) const @@ -167,15 +115,6 @@ QHash VersionList::roleNames() const return roles; } -std::unique_ptr VersionList::remoteUpdateTask() -{ - return std::unique_ptr(new RemoteLoadTask(this)); -} -std::unique_ptr VersionList::localUpdateTask() -{ - return std::unique_ptr(new LocalLoadTask(this)); -} - QString VersionList::localFilename() const { return m_uid + "/index.json"; @@ -200,6 +139,7 @@ void VersionList::setName(const QString &name) m_name = name; emit nameChanged(name); } + void VersionList::setVersions(const QVector &versions) { beginResetModel(); diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index 934b20e4..e958475e 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -54,9 +54,6 @@ public: RoleList providesRoles() const override; QHash roleNames() const override; - std::unique_ptr remoteUpdateTask() override; - std::unique_ptr localUpdateTask() override; - QString localFilename() const override; QString uid() const { return m_uid; } diff --git a/api/logic/meta/format/Format.cpp b/api/logic/meta/format/Format.cpp deleted file mode 100644 index 39d3f14f..00000000 --- a/api/logic/meta/format/Format.cpp +++ /dev/null @@ -1,143 +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 "Format.h" - -#include "minecraft/onesix/OneSixVersionFormat.h"" - -#include "meta/Index.h" -#include "meta/Version.h" -#include "meta/VersionList.h" - -#include "Json.h" -using namespace Json; - -namespace Meta -{ - -static const int currentFormatVersion = 0; - -// Index -static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) -{ - 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); -} - -// 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; -} - -static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) -{ - 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; -} - -// Version list / package -static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) -{ - 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), [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; -} - - -static int formatVersion(const QJsonObject &obj) -{ - if (!obj.contains("formatVersion")) { - throw ParseException(QObject::tr("Missing required field: 'formatVersion'")); - } - if (!obj.value("formatVersion").isDouble()) { - throw ParseException(QObject::tr("Required field has invalid type: 'formatVersion'")); - } - return obj.value("formatVersion").toInt(); -} - -void parseIndex(const QJsonObject &obj, Index *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 0: - ptr->merge(parseIndexInternal(obj)); - break; - default: - throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} - -void parseVersionList(const QJsonObject &obj, VersionList *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 0: - ptr->merge(parseVersionListInternal(obj)); - break; - default: - throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} - -void parseVersion(const QJsonObject &obj, Version *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 0: - ptr->merge(parseVersionInternal(obj)); - break; - default: - throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} -} diff --git a/api/logic/meta/format/Format.h b/api/logic/meta/format/Format.h deleted file mode 100644 index aaed07fc..00000000 --- a/api/logic/meta/format/Format.h +++ /dev/null @@ -1,40 +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. - */ - -#pragma once - -#include -#include - -#include "Exception.h" -#include "meta/BaseEntity.h" - -namespace Meta -{ -class Index; -class Version; -class VersionList; - -class ParseException : public Exception -{ -public: - using Exception::Exception; -}; - -void parseIndex(const QJsonObject &obj, Index *ptr); -void parseVersion(const QJsonObject &obj, Version *ptr); -void parseVersionList(const QJsonObject &obj, VersionList *ptr); - -} diff --git a/api/logic/meta/tasks/LocalLoadTask.cpp b/api/logic/meta/tasks/LocalLoadTask.cpp deleted file mode 100644 index b64fc5d3..00000000 --- a/api/logic/meta/tasks/LocalLoadTask.cpp +++ /dev/null @@ -1,57 +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 "LocalLoadTask.h" - -#include - -#include "meta/format/Format.h" -#include "meta/Util.h" -#include "meta/Index.h" -#include "meta/Version.h" -#include "meta/VersionList.h" -#include "Env.h" -#include "Json.h" - -namespace Meta -{ -LocalLoadTask::LocalLoadTask(BaseEntity *entity, QObject *parent) - : Task(parent), m_entity(entity) -{ -} - -void LocalLoadTask::executeTask() -{ - const QString fname = Meta::localDir().absoluteFilePath(m_entity->localFilename()); - if (!QFile::exists(fname)) - { - emitFailed(tr("File doesn't exist")); - return; - } - setStatus(tr("Reading %1...").arg(fname)); - setProgress(0, 0); - - try - { - m_entity->parse(Json::requireObject(Json::requireDocument(fname, fname), fname)); - m_entity->notifyLocalLoadComplete(); - emitSucceeded(); - } - catch (Exception &e) - { - emitFailed(tr("Unable to parse file %1: %2").arg(fname, e.cause())); - } -} -} diff --git a/api/logic/meta/tasks/LocalLoadTask.h b/api/logic/meta/tasks/LocalLoadTask.h deleted file mode 100644 index 905660ed..00000000 --- a/api/logic/meta/tasks/LocalLoadTask.h +++ /dev/null @@ -1,39 +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. - */ - -#pragma once - -#include "tasks/Task.h" -#include - -namespace Meta -{ -class BaseEntity; -class Index; -class VersionList; -class Version; - -// FIXME: this is now just an odd function, get rid of it -class LocalLoadTask : public Task -{ - Q_OBJECT -public: - explicit LocalLoadTask(BaseEntity *entity, QObject *parent = nullptr); - -private: - void executeTask() override; - BaseEntity *m_entity; -}; -} diff --git a/api/logic/meta/tasks/RemoteLoadTask.cpp b/api/logic/meta/tasks/RemoteLoadTask.cpp deleted file mode 100644 index b73af021..00000000 --- a/api/logic/meta/tasks/RemoteLoadTask.cpp +++ /dev/null @@ -1,103 +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 "RemoteLoadTask.h" - -#include "net/Download.h" -#include "net/HttpMetaCache.h" -#include "net/NetJob.h" -#include "meta/format/Format.h" -#include "meta/Util.h" -#include "meta/Index.h" -#include "meta/Version.h" -#include "meta/VersionList.h" -#include "Env.h" -#include "Json.h" - -namespace Meta -{ - -RemoteLoadTask::RemoteLoadTask(BaseEntity *entity, QObject *parent) - : Task(parent), m_entity(entity) -{ -} - -class ParsingValidator : public Net::Validator -{ -public: /* con/des */ - ParsingValidator(BaseEntity *entity) : m_entity(entity) - { - }; - virtual ~ParsingValidator() - { - }; - -public: /* methods */ - bool init(QNetworkRequest &) override - { - return true; - } - bool write(QByteArray & data) override - { - this->data.append(data); - return true; - } - bool abort() override - { - return true; - } - bool validate(QNetworkReply &) override - { - auto fname = m_entity->localFilename(); - try - { - m_entity->parse(Json::requireObject(Json::requireDocument(data, fname), fname)); - m_entity->notifyRemoteLoadComplete(); - return true; - } - catch (Exception &e) - { - qWarning() << "Unable to parse response:" << e.cause(); - return false; - } - } - -private: /* data */ - QByteArray data; - BaseEntity *m_entity; -}; - -void RemoteLoadTask::executeTask() -{ - // FIXME: leak here!!! - NetJob *job = new NetJob(tr("Download of meta file %1").arg(m_entity->localFilename())); - - auto url = m_entity->url(); - auto entry = ENV.metacache()->resolveEntry("meta", m_entity->localFilename()); - entry->setStale(true); - m_dl = Net::Download::makeCached(url, entry); - /* - * The validator parses the file and loads it into the object. - * If that fails, the file is not written to storage. - */ - m_dl->addValidator(new ParsingValidator(m_entity)); - job->addNetAction(m_dl); - connect(job, &NetJob::failed, this, &RemoteLoadTask::emitFailed); - connect(job, &NetJob::succeeded, this, &RemoteLoadTask::succeeded); - connect(job, &NetJob::status, this, &RemoteLoadTask::setStatus); - connect(job, &NetJob::progress, this, &RemoteLoadTask::setProgress); - job->start(); -} -} diff --git a/api/logic/meta/tasks/RemoteLoadTask.h b/api/logic/meta/tasks/RemoteLoadTask.h deleted file mode 100644 index 6d81d8ea..00000000 --- a/api/logic/meta/tasks/RemoteLoadTask.h +++ /dev/null @@ -1,46 +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. - */ - -#pragma once - -#include "tasks/Task.h" -#include - -namespace Net -{ -class Download; -} - -namespace Meta -{ -class BaseEntity; -class Index; -class VersionList; -class Version; - -// FIXME: this is now just an oddly constructed NetJob, get rid of it. -class RemoteLoadTask : public Task -{ - Q_OBJECT -public: - explicit RemoteLoadTask(BaseEntity *entity, QObject *parent = nullptr); - -private: - void executeTask() override; - - BaseEntity *m_entity; - std::shared_ptr m_dl; -}; -} diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 9073c006..e0870d06 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -554,21 +554,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow job->start(); } - // run the things that load and download other things... FIXME: this is NOT the place - // FIXME: invisible actions in the background = NOPE. + // load the news { - /* - if (!MMC->minecraftlist()->isLoaded()) - { - m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); - startTask(m_versionLoadTask); - } - if (!MMC->lwjgllist()->isLoaded()) - { - MMC->lwjgllist()->loadList(); - } - */ - m_newsChecker->reloadNews(); updateNewsLabel(); } diff --git a/application/pages/global/PackagesPage.cpp b/application/pages/global/PackagesPage.cpp index 81ad4da1..e4967532 100644 --- a/application/pages/global/PackagesPage.cpp +++ b/application/pages/global/PackagesPage.cpp @@ -97,7 +97,7 @@ QIcon PackagesPage::icon() const void PackagesPage::on_refreshIndexBtn_clicked() { - ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); + ENV.metadataIndex()->load(); } void PackagesPage::on_refreshFileBtn_clicked() { @@ -106,7 +106,7 @@ void PackagesPage::on_refreshFileBtn_clicked() { return; } - ProgressDialog(this).execWithTask(list->remoteUpdateTask()); + list->load(); } void PackagesPage::on_refreshVersionBtn_clicked() { @@ -115,7 +115,7 @@ void PackagesPage::on_refreshVersionBtn_clicked() { return; } - ProgressDialog(this).execWithTask(version->remoteUpdateTask()); + version->load(); } void PackagesPage::on_fileSearchEdit_textChanged(const QString &search) @@ -158,19 +158,7 @@ void PackagesPage::updateCurrentVersionList(const QModelIndex &index) ui->fileName->setText(list->name()); m_versionProxy->setSourceModel(list.get()); ui->refreshFileBtn->setText(tr("Refresh %1").arg(list->humanReadable())); - - if (!list->isLocalLoaded()) - { - std::unique_ptr task = list->localUpdateTask(); - connect(task.get(), &Task::finished, this, [this, list]() - { - if (list->count() == 0 && !list->isRemoteLoaded()) - { - ProgressDialog(this).execWithTask(list->remoteUpdateTask()); - } - }); - ProgressDialog(this).execWithTask(task); - } + list->load(); } else { @@ -227,16 +215,5 @@ void PackagesPage::updateVersion() void PackagesPage::opened() { - if (!ENV.metadataIndex()->isLocalLoaded()) - { - std::unique_ptr task = ENV.metadataIndex()->localUpdateTask(); - connect(task.get(), &Task::finished, this, [this]() - { - if (!ENV.metadataIndex()->isRemoteLoaded()) - { - ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); - } - }); - ProgressDialog(this).execWithTask(task); - } + ENV.metadataIndex()->load(); } -- cgit From 2660418d58efb33cd3a0ab8ed9d48c359c076905 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 19 Mar 2017 02:13:49 +0100 Subject: NOISSUE hack it together enough to get launching back Meta index will now always return valid objects. They just might never load if they don't exist on the server. --- api/logic/meta/BaseEntity.cpp | 9 +++ api/logic/meta/BaseEntity.h | 1 + api/logic/meta/Index.cpp | 14 ++-- api/logic/meta/Index.h | 1 + api/logic/meta/Version.cpp | 35 +++++---- api/logic/meta/Version.h | 84 +++++++++++++++++++++- api/logic/meta/VersionList.cpp | 14 ++-- api/logic/meta/VersionList.h | 3 +- api/logic/minecraft/ProfilePatch.h | 4 -- .../minecraft/onesix/OneSixProfileStrategy.cpp | 6 +- api/logic/minecraft/onesix/OneSixUpdate.cpp | 48 +++++++------ application/pages/VersionPage.cpp | 1 + 12 files changed, 162 insertions(+), 58 deletions(-) (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp index 18b7f92f..809f88cb 100644 --- a/api/logic/meta/BaseEntity.cpp +++ b/api/logic/meta/BaseEntity.cpp @@ -137,4 +137,13 @@ void Meta::BaseEntity::load() m_updateTask->start(); } +shared_qobject_ptr Meta::BaseEntity::getCurrentTask() +{ + if(m_updateStatus == UpdateStatus::InProgress) + { + return m_updateTask; + } + return nullptr; +} + #include "BaseEntity.moc" diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h index 92a39272..85051d97 100644 --- a/api/logic/meta/BaseEntity.h +++ b/api/logic/meta/BaseEntity.h @@ -61,6 +61,7 @@ public: } void load(); + shared_qobject_ptr getCurrentTask(); protected: /* methods */ bool loadLocalFile(); diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp index 35b9fb6f..0749651a 100644 --- a/api/logic/meta/Index.cpp +++ b/api/logic/meta/Index.cpp @@ -83,17 +83,19 @@ bool Index::hasUid(const QString &uid) const VersionListPtr Index::get(const QString &uid) { - return m_uids.value(uid, nullptr); + VersionListPtr out = m_uids.value(uid, nullptr); + if(!out) + { + out = std::make_shared(uid); + m_uids[uid] = out; + } + return out; } VersionPtr Index::get(const QString &uid, const QString &version) { auto list = get(uid); - if(list) - { - return list->getVersion(version); - } - return nullptr; + return list->getVersion(version); } void Index::parse(const QJsonObject& obj) diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h index 544a8b96..9811e152 100644 --- a/api/logic/meta/Index.h +++ b/api/logic/meta/Index.h @@ -68,3 +68,4 @@ private: void connectVersionList(const int row, const VersionListPtr &list); }; } + diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index f8c865e7..2790b2f3 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -18,38 +18,45 @@ #include #include "JsonFormat.h" +#include "minecraft/MinecraftProfile.h" -namespace Meta +void Meta::Version::applyTo(MinecraftProfile* profile) { -Version::Version(const QString &uid, const QString &version) + if(m_data) + { + m_data->applyTo(profile); + } +} + +Meta::Version::Version(const QString &uid, const QString &version) : BaseVersion(), m_uid(uid), m_version(version) { } -QString Version::descriptor() +QString Meta::Version::descriptor() { return m_version; } -QString Version::name() +QString Meta::Version::name() { return m_version; } -QString Version::typeString() const +QString Meta::Version::typeString() const { return m_type; } -QDateTime Version::time() const +QDateTime Meta::Version::time() const { return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC); } -void Version::parse(const QJsonObject& obj) +void Meta::Version::parse(const QJsonObject& obj) { parseVersion(obj, this); } -void Version::merge(const std::shared_ptr &other) +void Meta::Version::merge(const std::shared_ptr &other) { VersionPtr version = std::dynamic_pointer_cast(other); if (m_type != version->m_type) @@ -68,28 +75,28 @@ void Version::merge(const std::shared_ptr &other) setData(version->m_data); } -QString Version::localFilename() const +QString Meta::Version::localFilename() const { return m_uid + '/' + m_version + ".json"; } -void Version::setType(const QString &type) +void Meta::Version::setType(const QString &type) { m_type = type; emit typeChanged(); } -void Version::setTime(const qint64 time) +void Meta::Version::setTime(const qint64 time) { m_time = time; emit timeChanged(); } -void Version::setRequires(const QVector &requires) +void Meta::Version::setRequires(const QVector &requires) { m_requires = requires; emit requiresChanged(); } -void Version::setData(const VersionFilePtr &data) +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 0be2d94a..b8ea7e44 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -33,7 +33,7 @@ namespace Meta { using VersionPtr = std::shared_ptr; -class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity +class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity, public ProfilePatch { Q_OBJECT Q_PROPERTY(QString uid READ uid CONSTANT) @@ -41,9 +41,89 @@ class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public Q_PROPERTY(QString type READ type NOTIFY typeChanged) Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) Q_PROPERTY(QVector requires READ requires NOTIFY requiresChanged) -public: + +public: /* con/des */ explicit Version(const QString &uid, const QString &version); +// FIXME: none of this belongs here... +public: /* ProfilePatch overrides */ + QString getFilename() override + { + return QString(); + } + QString getID() override + { + return m_uid; + } + QList getJarMods() override + { + return {}; + } + QString getName() override + { + return name(); + } + QDateTime getReleaseDateTime() override + { + return time(); + } + QString getVersion() override + { + return m_version; + } + std::shared_ptr getVersionFile() override + { + return m_data; + } + int getOrder() override + { + return 0; + } + VersionSource getVersionSource() override + { + return VersionSource::Local; + } + bool isVersionChangeable() override + { + return true; + } + bool isRevertible() override + { + return false; + } + bool isRemovable() override + { + return true; + } + bool isCustom() override + { + return false; + } + bool isCustomizable() override + { + return true; + } + bool isMoveable() override + { + return true; + } + bool isEditable() override + { + return false; + } + void setOrder(int) override + { + } + bool hasJarMods() override + { + return false; + } + bool isMinecraftVersion() override + { + return m_uid == "net.minecraft"; + } + void applyTo(MinecraftProfile * profile) override; + QString descriptor() override; QString name() override; QString typeString() const override; diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index a12f5418..d6bbf70f 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -125,13 +125,15 @@ QString VersionList::humanReadable() const return m_name.isEmpty() ? m_uid : m_name; } -bool VersionList::hasVersion(const QString &version) const +VersionPtr VersionList::getVersion(const QString &version) { - return m_lookup.contains(version); -} -VersionPtr VersionList::getVersion(const QString &version) const -{ - return m_lookup.value(version); + VersionPtr out = m_lookup.value(version, nullptr); + if(!out) + { + out = std::make_shared(m_uid, version); + m_lookup[version] = out; + } + return out; } void VersionList::setName(const QString &name) diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index e958475e..26fa6c5a 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -60,8 +60,7 @@ public: QString name() const { return m_name; } QString humanReadable() const; - bool hasVersion(const QString &version) const; - VersionPtr getVersion(const QString &version) const; + VersionPtr getVersion(const QString &version); QVector versions() const { return m_versions; } diff --git a/api/logic/minecraft/ProfilePatch.h b/api/logic/minecraft/ProfilePatch.h index 26230092..b61fb8b3 100644 --- a/api/logic/minecraft/ProfilePatch.h +++ b/api/logic/minecraft/ProfilePatch.h @@ -92,10 +92,6 @@ public: { return m_problemSeverity; } - virtual bool hasFailed() - { - return getProblemSeverity() == PROBLEM_ERROR; - } protected: QList m_problems; diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index e3d3f674..b19a2dea 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include OneSixProfileStrategy::OneSixProfileStrategy(OneSixInstance* instance) { @@ -98,7 +100,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() } else { - auto mcversion = ENV.getVersion("net.minecraft", m_instance->intendedVersionId()); + auto mcversion = ENV.metadataIndex()->get("net.minecraft", m_instance->intendedVersionId()); minecraftPatch = std::dynamic_pointer_cast(mcversion); } if (!minecraftPatch) @@ -121,7 +123,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() } else { - auto lwjglversion = ENV.getVersion("org.lwjgl", "2.9.1" /*m_instance->intendedVersionId()*/); + auto lwjglversion = ENV.metadataIndex()->get("org.lwjgl", "2.9.1"); lwjglPatch = std::dynamic_pointer_cast(lwjglversion); } if (!lwjglPatch) diff --git a/api/logic/minecraft/onesix/OneSixUpdate.cpp b/api/logic/minecraft/onesix/OneSixUpdate.cpp index ec40e086..5bc76b01 100644 --- a/api/logic/minecraft/onesix/OneSixUpdate.cpp +++ b/api/logic/minecraft/onesix/OneSixUpdate.cpp @@ -34,6 +34,9 @@ #include "update/FMLLibrariesTask.h" #include "update/AssetUpdateTask.h" +#include +#include + OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent), m_inst(inst) { // create folders @@ -44,30 +47,22 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent) // add a version update task, if necessary { /* - auto list = std::dynamic_pointer_cast(ENV.getVersionList("net.minecraft")); - auto version = std::dynamic_pointer_cast(list->findVersion(m_inst->intendedVersionId())); - if (version == nullptr) - { - // don't do anything if it was invalid - m_preFailure = tr("The specified Minecraft version is invalid. Choose a different one."); - } - else if (m_inst->providesVersionFile() || !version->needsUpdate()) + * FIXME: there are some corner cases here that remain unhandled: + * what if local load succeeds but remote fails? The version is still usable... + */ + // FIXME: derive this from the actual list of version patches... + auto loadVersion = [&](const QString & uid, const QString & version) { - qDebug() << "Instance either provides a version file or doesn't need an update."; - } - else - { - auto versionUpdateTask = list->createUpdateTask(m_inst->intendedVersionId()); - if (!versionUpdateTask) - { - qDebug() << "Didn't spawn an update task."; - } - else + auto obj = ENV.metadataIndex()->get(uid, version); + obj->load(); + auto task = obj->getCurrentTask(); + if(task) { - m_tasks.append(versionUpdateTask); + m_tasks.append(task.unwrap()); } - } - */ + }; + loadVersion("org.lwjgl", "2.9.1"); + loadVersion("net.minecraft", m_inst->intendedVersionId()); } // libraries download @@ -118,11 +113,20 @@ void OneSixUpdate::next() return; } auto task = m_tasks[m_currentTask]; + // if the task is already finished by the time we look at it, skip it + if(task->isFinished()) + { + next(); + } connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded); connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed); connect(task.get(), &Task::progress, this, &OneSixUpdate::progress); connect(task.get(), &Task::status, this, &OneSixUpdate::setStatus); - task->start(); + // if the task is already running, do not start it again + if(!task->isRunning()) + { + task->start(); + } } void OneSixUpdate::subtaskSucceeded() diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index 42eb31de..78e2a888 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -320,6 +320,7 @@ void VersionPage::on_moveDownBtn_clicked() void VersionPage::on_changeVersionBtn_clicked() { + // FIXME: this is hilariously broken because it assumes m_inst->versionList() is a sensible thing... VersionSelectDialog vselect(m_inst->versionList().get(), tr("Change Minecraft version"), this); if (!vselect.exec() || !vselect.selectedVersion()) -- cgit From f557c1367994a61935fa0e8d0b1b67688d2692d0 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 19 Mar 2017 23:58:54 +0100 Subject: NOISSUE stuff and things happened. Maybe. --- api/logic/BaseVersionList.h | 13 ++- api/logic/java/JavaInstallList.cpp | 2 +- api/logic/java/JavaInstallList.h | 18 +-- api/logic/meta/BaseEntity.cpp | 8 +- api/logic/meta/Index_test.cpp | 2 +- api/logic/meta/Version.cpp | 12 +- api/logic/meta/Version.h | 82 +------------ api/logic/meta/VersionList.cpp | 8 +- api/logic/meta/VersionList.h | 2 +- api/logic/minecraft/MinecraftInstance.cpp | 4 +- api/logic/minecraft/MojangVersionFormat.cpp | 2 +- api/logic/minecraft/ProfilePatch.h | 2 - api/logic/minecraft/ProfileUtils.cpp | 2 +- api/logic/minecraft/VersionFile.cpp | 9 +- api/logic/minecraft/VersionFile.h | 17 +-- api/logic/minecraft/ftb/FTBProfileStrategy.cpp | 4 +- api/logic/minecraft/legacy/LwjglVersionList.cpp | 5 +- api/logic/minecraft/legacy/LwjglVersionList.h | 4 +- .../minecraft/onesix/OneSixProfileStrategy.cpp | 130 ++++++++++++++++++--- api/logic/minecraft/onesix/OneSixVersionFormat.cpp | 20 +++- application/pages/VersionPage.cpp | 25 +--- application/widgets/VersionSelectWidget.cpp | 44 +++---- application/widgets/VersionSelectWidget.h | 5 +- 23 files changed, 209 insertions(+), 211 deletions(-) (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/BaseVersionList.h b/api/logic/BaseVersionList.h index eadc6933..8afcae1d 100644 --- a/api/logic/BaseVersionList.h +++ b/api/logic/BaseVersionList.h @@ -22,6 +22,7 @@ #include "BaseVersion.h" #include "tasks/Task.h" #include "multimc_logic_export.h" +#include "QObjectPtr.h" /*! * \brief Class that each instance type's version list derives from. @@ -63,7 +64,7 @@ public: * The task returned by this function should reset the model when it's done. * \return A pointer to a task that reloads the version list. */ - virtual Task *getLoadTask() = 0; + virtual shared_qobject_ptr getLoadTask() = 0; //! Checks whether or not the list is loaded. If this returns false, the list should be //loaded. @@ -76,17 +77,17 @@ public: virtual int count() const = 0; //////// List Model Functions //////// - virtual QVariant data(const QModelIndex &index, int role) const; - virtual int rowCount(const QModelIndex &parent) const; - virtual int columnCount(const QModelIndex &parent) const; - virtual QHash roleNames() const override; + QVariant data(const QModelIndex &index, int role) const override; + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + virtual QHash roleNames() const; //! which roles are provided by this version list? virtual RoleList providesRoles() const; /*! * \brief Finds a version by its descriptor. - * \param The descriptor of the version to find. + * \param descriptor The descriptor of the version to find. * \return A const pointer to the version with the given descriptor. NULL if * one doesn't exist. */ diff --git a/api/logic/java/JavaInstallList.cpp b/api/logic/java/JavaInstallList.cpp index c98ef279..dbf66f5f 100644 --- a/api/logic/java/JavaInstallList.cpp +++ b/api/logic/java/JavaInstallList.cpp @@ -29,7 +29,7 @@ JavaInstallList::JavaInstallList(QObject *parent) : BaseVersionList(parent) { } -Task *JavaInstallList::getLoadTask() +shared_qobject_ptr JavaInstallList::getLoadTask() { return new JavaListLoadTask(this); } diff --git a/api/logic/java/JavaInstallList.h b/api/logic/java/JavaInstallList.h index 2055d154..afc5ef43 100644 --- a/api/logic/java/JavaInstallList.h +++ b/api/logic/java/JavaInstallList.h @@ -34,17 +34,17 @@ class MULTIMC_LOGIC_EXPORT JavaInstallList : public BaseVersionList public: explicit JavaInstallList(QObject *parent = 0); - virtual Task *getLoadTask() override; - virtual bool isLoaded() override; - virtual const BaseVersionPtr at(int i) const override; - virtual int count() const override; - virtual void sortVersions() override; + shared_qobject_ptr getLoadTask() override; + bool isLoaded() override; + const BaseVersionPtr at(int i) const override; + int count() const override; + void sortVersions() override; - virtual QVariant data(const QModelIndex &index, int role) const override; - virtual RoleList providesRoles() const override; + QVariant data(const QModelIndex &index, int role) const override; + RoleList providesRoles() const override; public slots: - virtual void updateListData(QList versions) override; + void updateListData(QList versions) override; protected: QList m_vlist; @@ -60,7 +60,7 @@ public: explicit JavaListLoadTask(JavaInstallList *vlist); ~JavaListLoadTask(); - virtual void executeTask(); + void executeTask() override; public slots: void javaCheckerFinished(QList results); diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp index 809f88cb..633afab2 100644 --- a/api/logic/meta/BaseEntity.cpp +++ b/api/logic/meta/BaseEntity.cpp @@ -101,16 +101,20 @@ bool Meta::BaseEntity::loadLocalFile() void Meta::BaseEntity::load() { + // load local file if nothing is loaded yet if(!isLoaded()) { - loadLocalFile(); + if(loadLocalFile()) + { + m_loadStatus = LoadStatus::Local; + } } + // if we need remote update, run the update task if(!shouldStartRemoteUpdate()) { return; } NetJob *job = new NetJob(QObject::tr("Download of meta file %1").arg(localFilename())); - auto url = this->url(); auto entry = ENV.metacache()->resolveEntry("meta", localFilename()); entry->setStale(true); diff --git a/api/logic/meta/Index_test.cpp b/api/logic/meta/Index_test.cpp index d4343c37..1c5face2 100644 --- a/api/logic/meta/Index_test.cpp +++ b/api/logic/meta/Index_test.cpp @@ -23,7 +23,7 @@ slots: QVERIFY(!windex.hasUid("asdf")); QVERIFY(windex.get("list2") != nullptr); QCOMPARE(windex.get("list2")->uid(), QString("list2")); - QVERIFY(windex.get("adsf") == nullptr); + QVERIFY(windex.get("adsf") != nullptr); } void test_merge() diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index 2790b2f3..fee7d049 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -20,14 +20,6 @@ #include "JsonFormat.h" #include "minecraft/MinecraftProfile.h" -void Meta::Version::applyTo(MinecraftProfile* profile) -{ - if(m_data) - { - m_data->applyTo(profile); - } -} - Meta::Version::Version(const QString &uid, const QString &version) : BaseVersion(), m_uid(uid), m_version(version) { @@ -39,7 +31,9 @@ QString Meta::Version::descriptor() } QString Meta::Version::name() { - return m_version; + if(m_data) + return m_data->getName(); + return m_uid; } QString Meta::Version::typeString() const { diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index b8ea7e44..b3943f47 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -33,7 +33,7 @@ namespace Meta { using VersionPtr = std::shared_ptr; -class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity, public ProfilePatch +class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity { Q_OBJECT Q_PROPERTY(QString uid READ uid CONSTANT) @@ -45,85 +45,6 @@ class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public public: /* con/des */ explicit Version(const QString &uid, const QString &version); -// FIXME: none of this belongs here... -public: /* ProfilePatch overrides */ - QString getFilename() override - { - return QString(); - } - QString getID() override - { - return m_uid; - } - QList getJarMods() override - { - return {}; - } - QString getName() override - { - return name(); - } - QDateTime getReleaseDateTime() override - { - return time(); - } - QString getVersion() override - { - return m_version; - } - std::shared_ptr getVersionFile() override - { - return m_data; - } - int getOrder() override - { - return 0; - } - VersionSource getVersionSource() override - { - return VersionSource::Local; - } - bool isVersionChangeable() override - { - return true; - } - bool isRevertible() override - { - return false; - } - bool isRemovable() override - { - return true; - } - bool isCustom() override - { - return false; - } - bool isCustomizable() override - { - return true; - } - bool isMoveable() override - { - return true; - } - bool isEditable() override - { - return false; - } - void setOrder(int) override - { - } - bool hasJarMods() override - { - return false; - } - bool isMinecraftVersion() override - { - return m_uid == "net.minecraft"; - } - void applyTo(MinecraftProfile * profile) override; - QString descriptor() override; QString name() override; QString typeString() const override; @@ -153,6 +74,7 @@ signals: void requiresChanged(); private: + QString m_name; QString m_uid; QString m_version; QString m_type; diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index d6bbf70f..28d9dd26 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -29,15 +29,15 @@ VersionList::VersionList(const QString &uid, QObject *parent) setObjectName("Version list: " + uid); } -Task *VersionList::getLoadTask() +shared_qobject_ptr VersionList::getLoadTask() { - // TODO: create a wrapper task that will chain from root to here. - return nullptr; + load(); + return getCurrentTask(); } bool VersionList::isLoaded() { - return isLoaded(); + return BaseEntity::isLoaded(); } const BaseVersionPtr VersionList::at(int i) const diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index 26fa6c5a..08d71230 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -41,7 +41,7 @@ public: VersionPtrRole }; - Task *getLoadTask() override; + shared_qobject_ptr getLoadTask() override; bool isLoaded() override; const BaseVersionPtr at(int i) const override; int count() const override; diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index b88d0c2a..cb080bfe 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -20,6 +20,8 @@ #include "minecraft/launch/ModMinecraftJar.h" #include "minecraft/launch/ClaimAccount.h" #include "java/launch/CheckJava.h" +#include +#include #include @@ -105,7 +107,7 @@ QString MinecraftInstance::binRoot() const std::shared_ptr< BaseVersionList > MinecraftInstance::versionList() const { - return ENV.getVersionList("net.minecraft"); + return ENV.metadataIndex()->get("net.minecraft"); } QStringList MinecraftInstance::javaArguments() const diff --git a/api/logic/minecraft/MojangVersionFormat.cpp b/api/logic/minecraft/MojangVersionFormat.cpp index 1312421f..651e2fbc 100644 --- a/api/logic/minecraft/MojangVersionFormat.cpp +++ b/api/logic/minecraft/MojangVersionFormat.cpp @@ -210,7 +210,7 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc readVersionProperties(root, out.get()); out->name = "Minecraft"; - out->fileId = "net.minecraft"; + out->uid = "net.minecraft"; out->version = out->minecraftVersion; out->filename = filename; diff --git a/api/logic/minecraft/ProfilePatch.h b/api/logic/minecraft/ProfilePatch.h index b61fb8b3..6f63f3c4 100644 --- a/api/logic/minecraft/ProfilePatch.h +++ b/api/logic/minecraft/ProfilePatch.h @@ -51,8 +51,6 @@ public: virtual void applyTo(MinecraftProfile *profile) = 0; virtual bool isMinecraftVersion() = 0; - virtual bool hasJarMods() = 0; - virtual QList getJarMods() = 0; virtual bool isMoveable() = 0; virtual bool isCustomizable() = 0; diff --git a/api/logic/minecraft/ProfileUtils.cpp b/api/logic/minecraft/ProfileUtils.cpp index ef9b3b28..c7c56dd6 100644 --- a/api/logic/minecraft/ProfileUtils.cpp +++ b/api/logic/minecraft/ProfileUtils.cpp @@ -102,7 +102,7 @@ bool readOverrideOrders(QString path, PatchOrder &order) static VersionFilePtr createErrorVersionFile(QString fileId, QString filepath, QString error) { auto outError = std::make_shared(); - outError->fileId = outError->name = fileId; + outError->uid = outError->name = fileId; outError->filename = filepath; outError->addProblem(PROBLEM_ERROR, error); return outError; diff --git a/api/logic/minecraft/VersionFile.cpp b/api/logic/minecraft/VersionFile.cpp index 573c4cb4..17dc6a49 100644 --- a/api/logic/minecraft/VersionFile.cpp +++ b/api/logic/minecraft/VersionFile.cpp @@ -14,12 +14,7 @@ bool VersionFile::isMinecraftVersion() { - return fileId == "net.minecraft"; -} - -bool VersionFile::hasJarMods() -{ - return !jarMods.isEmpty(); + return uid == "net.minecraft"; } void VersionFile::applyTo(MinecraftProfile *profile) @@ -29,7 +24,7 @@ void VersionFile::applyTo(MinecraftProfile *profile) { if (QRegExp(dependsOnMinecraftVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(theirVersion) == -1) { - throw MinecraftVersionMismatch(fileId, dependsOnMinecraftVersion, theirVersion); + throw MinecraftVersionMismatch(uid, dependsOnMinecraftVersion, theirVersion); } } profile->applyMinecraftVersion(minecraftVersion); diff --git a/api/logic/minecraft/VersionFile.h b/api/logic/minecraft/VersionFile.h index 249d0965..6a922d74 100644 --- a/api/logic/minecraft/VersionFile.h +++ b/api/logic/minecraft/VersionFile.h @@ -25,7 +25,6 @@ class VersionFile : public ProfilePatch public: /* methods */ virtual void applyTo(MinecraftProfile *profile) override; virtual bool isMinecraftVersion() override; - virtual bool hasJarMods() override; virtual int getOrder() override { return order; @@ -34,13 +33,9 @@ public: /* methods */ { this->order = order; } - virtual QList getJarMods() override - { - return jarMods; - } virtual QString getID() override { - return fileId; + return uid; } virtual QString getName() override { @@ -120,9 +115,6 @@ public: /* methods */ public: /* data */ - /// MultiMC: order hint for this version file if no explicit order is set - int order = 0; - // Flags for UI and version file manipulation in general bool m_isVanilla = false; bool m_isRemovable = false; @@ -130,6 +122,9 @@ public: /* data */ bool m_isCustomizable = false; bool m_isMovable = false; + /// MultiMC: order hint for this version file if no explicit order is set + int order = 0; + /// MultiMC: filename of the file this was loaded from QString filename; @@ -137,7 +132,7 @@ public: /* data */ QString name; /// MultiMC: package ID of this package - QString fileId; + QString uid; /// MultiMC: version of this package QString version; @@ -191,5 +186,3 @@ public: // Mojang: extended asset index download information std::shared_ptr mojangAssetIndex; }; - - diff --git a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp index 92a1555a..45765cd4 100644 --- a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp +++ b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp @@ -27,7 +27,7 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() if(QFile::exists(mcJson)) { auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false); - file->fileId = "net.minecraft"; + file->uid = "net.minecraft"; file->name = QObject::tr("Minecraft (tracked)"); file->setVanilla(true); if(file->version.isEmpty()) @@ -64,7 +64,7 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() addLib->setHint("local"); addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath()); } - file->fileId = "org.multimc.ftb.pack"; + file->uid = "org.multimc.ftb.pack"; file->setVanilla(true); file->name = QObject::tr("%1 (FTB pack)").arg(m_instance->name()); if(file->version.isEmpty()) diff --git a/api/logic/minecraft/legacy/LwjglVersionList.cpp b/api/logic/minecraft/legacy/LwjglVersionList.cpp index 7f4e7b38..3d7ad2d4 100644 --- a/api/logic/minecraft/legacy/LwjglVersionList.cpp +++ b/api/logic/minecraft/legacy/LwjglVersionList.cpp @@ -99,6 +99,7 @@ inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname) void LWJGLVersionList::rssFailed(const QString& reason) { + m_rssDLJob.reset(); m_loading = false; qWarning() << "Failed to load LWJGL list. Network error: " + reason; } @@ -116,8 +117,9 @@ void LWJGLVersionList::rssSucceeded() if (!doc.setContent(m_rssData, false, &xmlErrorMsg, &errorLine)) { qWarning() << "Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + QString::number(errorLine); - m_loading = false; + m_rssDLJob.reset(); m_rssData.clear(); + m_loading = false; return; } m_rssData.clear(); @@ -162,5 +164,6 @@ void LWJGLVersionList::rssSucceeded() endResetModel(); qDebug() << "Loaded LWJGL list."; + m_rssDLJob.reset(); m_loading = false; } diff --git a/api/logic/minecraft/legacy/LwjglVersionList.h b/api/logic/minecraft/legacy/LwjglVersionList.h index 652a3fda..f5312e2c 100644 --- a/api/logic/minecraft/legacy/LwjglVersionList.h +++ b/api/logic/minecraft/legacy/LwjglVersionList.h @@ -78,9 +78,9 @@ public: return m_vlist[i]; } - virtual Task* getLoadTask() override + virtual shared_qobject_ptr getLoadTask() override { - return nullptr; + return m_rssDLJob; } virtual void sortVersions() override {}; diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index b19a2dea..3a9b10e6 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -56,7 +56,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles() } auto file = ProfileUtils::parseJsonFile(QFileInfo(sourceFile), false); ProfileUtils::removeLwjglFromPatch(file); - file->fileId = "net.minecraft"; + file->uid = "net.minecraft"; file->version = file->minecraftVersion; file->name = "Minecraft"; auto data = OneSixVersionFormat::versionFileToJson(file, false).toJson(); @@ -81,6 +81,107 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles() } } +class MetaPatchProvider : public ProfilePatch +{ +public: /* con/des */ + MetaPatchProvider(std::shared_ptr data) + :m_version(data) + { + } +public: + QString getFilename() override + { + return QString(); + } + QString getID() override + { + return m_version->uid(); + } + QString getName() override + { + auto vfile = getFile(); + if(vfile) + { + return vfile->getName(); + } + return m_version->name(); + } + QDateTime getReleaseDateTime() override + { + return m_version->time(); + } + QString getVersion() override + { + return m_version->version(); + } + std::shared_ptr getVersionFile() override + { + return m_version->data(); + } + void setOrder(int) override + { + } + int getOrder() override + { + return 0; + } + VersionSource getVersionSource() override + { + return VersionSource::Local; + } + bool isVersionChangeable() override + { + return true; + } + bool isRevertible() override + { + return false; + } + bool isRemovable() override + { + return true; + } + bool isCustom() override + { + return false; + } + bool isCustomizable() override + { + return true; + } + bool isMoveable() override + { + return true; + } + bool isEditable() override + { + return false; + } + bool isMinecraftVersion() override + { + return getID() == "net.minecraft"; + } + void applyTo(MinecraftProfile * profile) override + { + auto vfile = getFile(); + if(vfile) + { + vfile->applyTo(profile); + } + } +private: + VersionFilePtr getFile() + { + if(!m_version->isLoaded()) + { + m_version->load(); + } + return m_version->data(); + } +private: + std::shared_ptr m_version; +}; + void OneSixProfileStrategy::loadDefaultBuiltinPatches() { { @@ -101,7 +202,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() else { auto mcversion = ENV.metadataIndex()->get("net.minecraft", m_instance->intendedVersionId()); - minecraftPatch = std::dynamic_pointer_cast(mcversion); + minecraftPatch = std::make_shared(mcversion); } if (!minecraftPatch) { @@ -124,7 +225,7 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() else { auto lwjglversion = ENV.metadataIndex()->get("org.lwjgl", "2.9.1"); - lwjglPatch = std::dynamic_pointer_cast(lwjglversion); + lwjglPatch = std::make_shared(lwjglversion); } if (!lwjglPatch) { @@ -162,10 +263,10 @@ void OneSixProfileStrategy::loadUserPatches() qDebug() << "Reading" << filename << "by user order"; VersionFilePtr file = ProfileUtils::parseJsonFile(finfo, false); // sanity check. prevent tampering with files. - if (file->fileId != id) + if (file->uid != id) { - file->addProblem(PROBLEM_WARNING, QObject::tr("load id %1 does not match internal id %2").arg(id, file->fileId)); - seen_extra.insert(file->fileId); + file->addProblem(PROBLEM_WARNING, QObject::tr("load id %1 does not match internal id %2").arg(id, file->uid)); + seen_extra.insert(file->uid); } file->setRemovable(true); file->setMovable(true); @@ -185,15 +286,15 @@ void OneSixProfileStrategy::loadUserPatches() qDebug() << "Reading" << info.fileName(); auto file = ProfileUtils::parseJsonFile(info, true); // ignore builtins - if (file->fileId == "net.minecraft") + if (file->uid == "net.minecraft") continue; - if (file->fileId == "org.lwjgl") + if (file->uid == "org.lwjgl") continue; // do not load versions with broken IDs twice - if(seen_extra.contains(file->fileId)) + if(seen_extra.contains(file->uid)) continue; // do not load what we already loaded in the first pass - if (userOrder.contains(file->fileId)) + if (userOrder.contains(file->uid)) continue; file->setRemovable(true); file->setMovable(true); @@ -203,7 +304,7 @@ void OneSixProfileStrategy::loadUserPatches() file->assets = QString(); file->mojangAssetIndex.reset(); // HACK - files.insert(file->order, file); + files.insert(file->getOrder(), file); } QSet seen; for (auto order : files.keys()) @@ -284,7 +385,8 @@ bool OneSixProfileStrategy::removePatch(ProfilePatchPtr patch) return true; }; - for(auto &jarmod: patch->getJarMods()) + auto &jarMods = patch->getVersionFile()->jarMods; + for(auto &jarmod: jarMods) { ok &= preRemoveJarMod(jarmod); } @@ -404,8 +506,8 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) jarMod->originalName = sourceInfo.completeBaseName(); f->jarMods.append(jarMod); f->name = target_name; - f->fileId = target_id; - f->order = profile->getFreeOrderNumber(); + f->uid = target_id; + f->setOrder(profile->getFreeOrderNumber()); QString patchFileName = FS::PathCombine(patchDir, target_id + ".json"); f->filename = patchFileName; f->setMovable(true); diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp index 403eb112..944e68a4 100644 --- a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp +++ b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp @@ -51,7 +51,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc { if (root.contains("order")) { - out->order = requireInteger(root.value("order")); + out->setOrder(requireInteger(root.value("order"))); } else { @@ -61,7 +61,16 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc } out->name = root.value("name").toString(); - out->fileId = root.value("fileId").toString(); + + if(root.contains("uid")) + { + out->uid = root.value("uid").toString(); + } + else + { + out->uid = root.value("fileId").toString(); + } + out->version = root.value("version").toString(); out->dependsOnMinecraftVersion = root.value("mcVersion").toString(); out->filename = filename; @@ -161,10 +170,13 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch QJsonObject root; if (saveOrder) { - root.insert("order", patch->order); + root.insert("order", patch->getOrder()); } writeString(root, "name", patch->name); - writeString(root, "fileId", patch->fileId); + + writeString(root, "uid", patch->uid); + writeString(root, "fileId", patch->uid); + writeString(root, "version", patch->version); writeString(root, "mcVersion", patch->dependsOnMinecraftVersion); diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index 78e2a888..732a33eb 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -487,22 +487,16 @@ int VersionPage::currentRow() void VersionPage::on_customizeBtn_clicked() { - // TODO: implement - /* auto version = currentRow(); if(version == -1) { return; } - //HACK HACK remove, this is dumb auto patch = m_profile->versionPatch(version); - auto mc = std::dynamic_pointer_cast(patch); - if(mc && mc->needsUpdate()) + if(!patch->getVersionFile()) { - if(!doUpdate()) - { - return; - } + // TODO: wait for the update task to finish here... + return; } if(!m_profile->customize(version)) { @@ -510,7 +504,6 @@ void VersionPage::on_customizeBtn_clicked() } updateButtons(); preselect(currentIdx); - */ } void VersionPage::on_editBtn_clicked() @@ -531,22 +524,11 @@ void VersionPage::on_editBtn_clicked() void VersionPage::on_revertBtn_clicked() { - // TODO: implement - /* auto version = currentRow(); if(version == -1) { return; } - auto mcraw = MMC->minecraftlist()->findVersion(m_inst->intendedVersionId()); - auto mc = std::dynamic_pointer_cast(mcraw); - if(mc && mc->needsUpdate()) - { - if(!doUpdate()) - { - return; - } - } if(!m_profile->revertToBase(version)) { // TODO: some error box here @@ -554,7 +536,6 @@ void VersionPage::on_revertBtn_clicked() updateButtons(); preselect(currentIdx); m_container->refreshContainer(); - */ } #include "VersionPage.moc" diff --git a/application/widgets/VersionSelectWidget.cpp b/application/widgets/VersionSelectWidget.cpp index 18284a91..a4eb428b 100644 --- a/application/widgets/VersionSelectWidget.cpp +++ b/application/widgets/VersionSelectWidget.cpp @@ -80,52 +80,42 @@ void VersionSelectWidget::initialize() void VersionSelectWidget::closeEvent(QCloseEvent * event) { - if(loadTask) - { - loadTask->abort(); - loadTask->deleteLater(); - loadTask = nullptr; - } QWidget::closeEvent(event); } void VersionSelectWidget::loadList() { - if(loadTask) + auto newTask = m_vlist->getLoadTask(); + if (!newTask) { return; } - loadTask = m_vlist->getLoadTask(); - if (!loadTask) + loadTask = newTask.get(); + connect(loadTask, &Task::succeeded, this, &VersionSelectWidget::onTaskSucceeded); + connect(loadTask, &Task::failed, this, &VersionSelectWidget::onTaskFailed); + connect(loadTask, &Task::progress, this, &VersionSelectWidget::changeProgress); + if(!loadTask->isRunning()) { - return; + loadTask->start(); } - connect(loadTask, &Task::finished, this, &VersionSelectWidget::onTaskFinished); - connect(loadTask, &Task::progress, this, &VersionSelectWidget::changeProgress); - loadTask->start(); sneakyProgressBar->setHidden(false); } -void VersionSelectWidget::onTaskFinished() +void VersionSelectWidget::onTaskSucceeded() { - if (!loadTask->successful()) - { - CustomMessageBox::selectable(this, tr("Error"), - tr("List update failed:\n%1").arg(loadTask->failReason()), - QMessageBox::Warning)->show(); - if (m_proxyModel->rowCount() == 0) - { - listView->setEmptyMode(VersionListView::ErrorString); - } - } - else if (m_proxyModel->rowCount() == 0) + if (m_proxyModel->rowCount() == 0) { listView->setEmptyMode(VersionListView::String); } sneakyProgressBar->setHidden(true); - loadTask->deleteLater(); - loadTask = nullptr; preselect(); + loadTask = nullptr; +} + +void VersionSelectWidget::onTaskFailed(const QString& reason) +{ + CustomMessageBox::selectable(this, tr("Error"), tr("List update failed:\n%1").arg(reason), QMessageBox::Warning)->show(); + onTaskSucceeded(); } void VersionSelectWidget::changeProgress(qint64 current, qint64 total) diff --git a/application/widgets/VersionSelectWidget.h b/application/widgets/VersionSelectWidget.h index 0fc9f2e6..66e512ac 100644 --- a/application/widgets/VersionSelectWidget.h +++ b/application/widgets/VersionSelectWidget.h @@ -55,7 +55,8 @@ protected: virtual void closeEvent ( QCloseEvent* ); private slots: - void onTaskFinished(); + void onTaskSucceeded(); + void onTaskFailed(const QString &reason); void changeProgress(qint64 current, qint64 total); void currentRowChanged(const QModelIndex ¤t, const QModelIndex &); @@ -66,7 +67,7 @@ private: BaseVersionList *m_vlist = nullptr; VersionProxyModel *m_proxyModel = nullptr; int resizeOnColumn = 0; - Task * loadTask = nullptr; + Task * loadTask; bool preselectedAlready = false; private: -- cgit From da4ae1bc1ec74cdb4e75f4ebac30886ba4a1909c Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Fri, 24 Mar 2017 02:26:06 +0100 Subject: NOISSUE reimplement package dependencies It is now stored as a hashmap There is also a parentUid to limit depsolving by encapsulating by version --- api/logic/CMakeLists.txt | 2 -- api/logic/meta/JsonFormat.cpp | 25 +++++++++------- api/logic/meta/Reference.cpp | 48 ------------------------------- api/logic/meta/Reference.h | 44 ---------------------------- api/logic/meta/Version.cpp | 15 +++++++++- api/logic/meta/Version.h | 48 +++++++++++++++++++++++-------- api/logic/meta/VersionList.cpp | 26 ++++++++++++----- api/logic/meta/VersionList.h | 28 ++++++++++++++---- application/pages/VersionPage.cpp | 7 +++-- application/pages/global/PackagesPage.cpp | 18 ++++++------ 10 files changed, 118 insertions(+), 143 deletions(-) delete mode 100644 api/logic/meta/Reference.cpp delete mode 100644 api/logic/meta/Reference.h (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 544ace80..7f04a41e 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -426,8 +426,6 @@ set(META_SOURCES meta/Version.h meta/Index.cpp meta/Index.h - meta/Reference.cpp - meta/Reference.h ) add_unit_test(Index diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp index 4e43b715..8a063f48 100644 --- a/api/logic/meta/JsonFormat.cpp +++ b/api/logic/meta/JsonFormat.cpp @@ -48,20 +48,22 @@ static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) // 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); + version->setParentUid(ensureString(obj, "parentUid", QString())); + if(obj.contains("requires")) + { + QHash requires; + auto reqobj = requireObject(obj, "requires"); + auto iter = reqobj.begin(); + while(iter != reqobj.end()) + { + requires[iter.key()] = requireString(iter.value()); + iter++; + } + version->setRequires(requires); + } return version; } @@ -90,6 +92,7 @@ static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) VersionListPtr list = std::make_shared(uid); list->setName(ensureString(obj, "name", QString())); + list->setParentUid(ensureString(obj, "parentUid", QString())); list->setVersions(versions); return list; } diff --git a/api/logic/meta/Reference.cpp b/api/logic/meta/Reference.cpp deleted file mode 100644 index c5cef172..00000000 --- a/api/logic/meta/Reference.cpp +++ /dev/null @@ -1,48 +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 "Reference.h" - -namespace Meta -{ -Reference::Reference(const QString &uid) - : m_uid(uid) -{ -} - -QString Reference::uid() const -{ - return m_uid; -} - -QString Reference::version() const -{ - return m_version; -} -void Reference::setVersion(const QString &version) -{ - m_version = version; -} - -bool Reference::operator==(const Reference &other) const -{ - return m_uid == other.m_uid && m_version == other.m_version; -} - -bool Reference::operator!=(const Reference &other) const -{ - return m_uid != other.m_uid || m_version != other.m_version; -} -} diff --git a/api/logic/meta/Reference.h b/api/logic/meta/Reference.h deleted file mode 100644 index 027076cc..00000000 --- a/api/logic/meta/Reference.h +++ /dev/null @@ -1,44 +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. - */ - -#pragma once - -#include -#include - -#include "multimc_logic_export.h" - -namespace Meta -{ -class MULTIMC_LOGIC_EXPORT Reference -{ -public: - Reference() {} - explicit Reference(const QString &uid); - - QString uid() const; - - QString version() const; - void setVersion(const QString &version); - - bool operator==(const Reference &other) const; - bool operator!=(const Reference &other) const; - -private: - QString m_uid; - QString m_version; -}; -} -Q_DECLARE_METATYPE(Meta::Reference) diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index fee7d049..af9d4f10 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -65,6 +65,10 @@ void Meta::Version::merge(const std::shared_ptr &other) { setRequires(version->m_requires); } + if (m_parentUid != version->m_parentUid) + { + setParentUid(version->m_parentUid); + } setData(version->m_data); } @@ -74,21 +78,30 @@ 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; emit typeChanged(); } + void Meta::Version::setTime(const qint64 time) { m_time = time; emit timeChanged(); } -void Meta::Version::setRequires(const QVector &requires) + +void Meta::Version::setRequires(const QHash &requires) { m_requires = requires; emit requiresChanged(); } + 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 b3943f47..1d921035 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -17,15 +17,14 @@ #include "BaseVersion.h" -#include -#include #include +#include +#include #include #include "minecraft/VersionFile.h" #include "BaseEntity.h" -#include "Reference.h" #include "multimc_logic_export.h" @@ -37,10 +36,11 @@ class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public { Q_OBJECT Q_PROPERTY(QString uid READ uid CONSTANT) + Q_PROPERTY(QString parentUid READ parentUid) Q_PROPERTY(QString version READ version CONSTANT) Q_PROPERTY(QString type READ type NOTIFY typeChanged) Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) - Q_PROPERTY(QVector requires READ requires NOTIFY requiresChanged) + Q_PROPERTY(QHash requires READ requires NOTIFY requiresChanged) public: /* con/des */ explicit Version(const QString &uid, const QString &version); @@ -49,13 +49,35 @@ public: /* con/des */ QString name() override; QString typeString() const override; - QString uid() const { return m_uid; } - QString version() const { return m_version; } - QString type() const { return m_type; } + QString uid() const + { + return m_uid; + } + QString parentUid() const + { + return m_parentUid; + } + QString version() const + { + return m_version; + } + QString type() const + { + return m_type; + } QDateTime time() const; - qint64 rawTime() const { return m_time; } - QVector requires() const { return m_requires; } - VersionFilePtr data() const { return m_data; } + qint64 rawTime() const + { + return m_time; + } + const QHash &requires() const + { + return m_requires; + } + VersionFilePtr data() const + { + return m_data; + } void merge(const std::shared_ptr &other) override; void parse(const QJsonObject &obj) override; @@ -63,9 +85,10 @@ 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 QVector &requires); + void setRequires(const QHash &requires); void setData(const VersionFilePtr &data); signals: @@ -76,10 +99,11 @@ signals: private: QString m_name; QString m_uid; + QString m_parentUid; QString m_version; QString m_type; qint64 m_time; - QVector m_requires; + QHash m_requires; VersionFilePtr m_data; }; } diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 28d9dd26..c2712155 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -19,7 +19,6 @@ #include "Version.h" #include "JsonFormat.h" -#include "Reference.h" namespace Meta { @@ -76,14 +75,17 @@ QVariant VersionList::data(const QModelIndex &index, int role) const return version->version(); case ParentGameVersionRole: { - const auto end = version->requires().end(); - const auto it = std::find_if(version->requires().begin(), end, - [](const Reference &ref) { return ref.uid() == "net.minecraft"; }); - if (it != end) + auto parentUid = this->parentUid(); + if(parentUid.isEmpty()) { - return (*it).version(); + return QVariant(); + } + auto & reqs = version->requires(); + auto iter = reqs.find(parentUid); + if (iter != reqs.end()) + { + return iter.value(); } - return QVariant(); } case TypeRole: return version->type(); @@ -175,6 +177,11 @@ void VersionList::merge(const BaseEntity::Ptr &other) setName(list->m_name); } + if(m_parentUid != list->m_parentUid) + { + setParentUid(list->m_parentUid); + } + if (m_versions.isEmpty()) { setVersions(list->m_versions); @@ -228,5 +235,10 @@ 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 08d71230..faacdbf8 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -15,8 +15,8 @@ #pragma once -#include "BaseVersionList.h" #include "BaseEntity.h" +#include "BaseVersionList.h" #include #include @@ -56,16 +56,30 @@ public: QString localFilename() const override; - QString uid() const { return m_uid; } - QString name() const { return m_name; } + QString parentUid() const + { + return m_parentUid; + } + QString uid() const + { + return m_uid; + } + QString name() const + { + return m_name; + } QString humanReadable() const; VersionPtr getVersion(const QString &version); - QVector versions() const { return m_versions; } + QVector versions() const + { + return m_versions; + } public: // for usage only by parsers void setName(const QString &name); + void setParentUid(const QString &parentUid); void setVersions(const QVector &versions); void merge(const BaseEntity::Ptr &other) override; void parse(const QJsonObject &obj) override; @@ -74,12 +88,15 @@ signals: void nameChanged(const QString &name); protected slots: - void updateListData(QList) override {} + void updateListData(QList) override + { + } private: QVector m_versions; QHash m_lookup; QString m_uid; + QString m_parentUid; QString m_name; VersionPtr m_recommended; @@ -87,6 +104,5 @@ private: void setupAddedVersion(const int row, const VersionPtr &version); }; - } Q_DECLARE_METATYPE(Meta::VersionListPtr) diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index 732a33eb..0608b2bf 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -43,6 +43,9 @@ #include "MultiMC.h" +#include +#include + class IconProxy : public QIdentityProxyModel { Q_OBJECT @@ -372,7 +375,7 @@ int VersionPage::doUpdate() void VersionPage::on_forgeBtn_clicked() { - auto vlist = ENV.getVersionList("net.minecraftforge"); + auto vlist = ENV.metadataIndex()->get("net.minecraftforge"); if(!vlist) { return; @@ -391,7 +394,7 @@ void VersionPage::on_forgeBtn_clicked() void VersionPage::on_liteloaderBtn_clicked() { - auto vlist = ENV.getVersionList("com.liteloader"); + auto vlist = ENV.metadataIndex()->get("com.liteloader"); if(!vlist) { return; diff --git a/application/pages/global/PackagesPage.cpp b/application/pages/global/PackagesPage.cpp index e4967532..e15ddbab 100644 --- a/application/pages/global/PackagesPage.cpp +++ b/application/pages/global/PackagesPage.cpp @@ -34,17 +34,15 @@ using namespace Meta; static QString formatRequires(const VersionPtr &version) { QStringList lines; - for (const Reference &ref : version->requires()) + auto & reqs = version->requires(); + auto iter = reqs.begin(); + while (iter != reqs.end()) { - const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->get(ref.uid())->humanReadable() : ref.uid(); - if (ref.version().isEmpty()) - { - lines.append(readable); - } - else - { - lines.append(QString("%1 (%2)").arg(readable, ref.version())); - } + auto &uid = iter.key(); + auto &version = iter.value(); + const QString readable = ENV.metadataIndex()->hasUid(uid) ? ENV.metadataIndex()->get(uid)->humanReadable() : uid; + lines.append(QString("%1 (%2)").arg(readable, version)); + iter++; } return lines.join('\n'); } -- cgit From 6f2a87167a13101d80d2fbc096bbb6a5eb5ab0c9 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 26 Mar 2017 20:50:31 +0200 Subject: NOISSUE remove some dead code from version related classes --- api/logic/meta/Version.h | 6 ------ api/logic/minecraft/ProfilePatch.h | 10 ---------- api/logic/minecraft/VersionFile.h | 4 ---- api/logic/minecraft/onesix/OneSixProfileStrategy.cpp | 4 ---- 4 files changed, 24 deletions(-) (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index 1d921035..8aac8ea1 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -35,12 +35,6 @@ using VersionPtr = std::shared_ptr; class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity { Q_OBJECT - Q_PROPERTY(QString uid READ uid CONSTANT) - Q_PROPERTY(QString parentUid READ parentUid) - Q_PROPERTY(QString version READ version CONSTANT) - Q_PROPERTY(QString type READ type NOTIFY typeChanged) - Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) - Q_PROPERTY(QHash requires READ requires NOTIFY requiresChanged) public: /* con/des */ explicit Version(const QString &uid, const QString &version); diff --git a/api/logic/minecraft/ProfilePatch.h b/api/logic/minecraft/ProfilePatch.h index 6f63f3c4..699a38ae 100644 --- a/api/logic/minecraft/ProfilePatch.h +++ b/api/logic/minecraft/ProfilePatch.h @@ -15,14 +15,6 @@ enum ProblemSeverity PROBLEM_ERROR }; -/// where is a version from? -enum class VersionSource -{ - Builtin, //!< version loaded from the internal resources. - Local, //!< version loaded from a file in the cache. - Remote, //!< incomplete version on a remote server. -}; - class PatchProblem { public: @@ -70,8 +62,6 @@ public: virtual QString getFilename() = 0; - virtual VersionSource getVersionSource() = 0; - virtual std::shared_ptr getVersionFile() = 0; virtual const QList& getProblems() diff --git a/api/logic/minecraft/VersionFile.h b/api/logic/minecraft/VersionFile.h index 6a922d74..dad9a057 100644 --- a/api/logic/minecraft/VersionFile.h +++ b/api/logic/minecraft/VersionFile.h @@ -53,10 +53,6 @@ public: /* methods */ { return m_releaseTime; } - VersionSource getVersionSource() override - { - return VersionSource::Local; - } std::shared_ptr getVersionFile() override { diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index 3a9b10e6..3f33dd7f 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -125,10 +125,6 @@ public: { return 0; } - VersionSource getVersionSource() override - { - return VersionSource::Local; - } bool isVersionChangeable() override { return true; -- cgit From 643d74f66c2b22660264a393d5c3fa38f68a5d59 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Thu, 6 Apr 2017 23:30:18 +0200 Subject: NOISSUE implement recommended versions using the new JSON format --- api/logic/BaseVersionList.cpp | 7 +------ api/logic/BaseVersionList.h | 5 ----- api/logic/meta/JsonFormat.cpp | 5 ++++- api/logic/meta/Version.cpp | 16 ++++++++++++++++ api/logic/meta/Version.h | 8 ++++++++ api/logic/meta/VersionList.cpp | 15 +++------------ api/logic/meta/VersionList.h | 2 -- 7 files changed, 32 insertions(+), 26 deletions(-) (limited to 'api/logic/meta/Version.h') diff --git a/api/logic/BaseVersionList.cpp b/api/logic/BaseVersionList.cpp index dae604a2..8b424c11 100644 --- a/api/logic/BaseVersionList.cpp +++ b/api/logic/BaseVersionList.cpp @@ -30,7 +30,7 @@ BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor) return BaseVersionPtr(); } -BaseVersionPtr BaseVersionList::getLatestStable() const +BaseVersionPtr BaseVersionList::getRecommended() const { if (count() <= 0) return BaseVersionPtr(); @@ -38,11 +38,6 @@ BaseVersionPtr BaseVersionList::getLatestStable() const return at(0); } -BaseVersionPtr BaseVersionList::getRecommended() const -{ - return getLatestStable(); -} - QVariant BaseVersionList::data(const QModelIndex &index, int role) const { if (!index.isValid()) diff --git a/api/logic/BaseVersionList.h b/api/logic/BaseVersionList.h index eb3b622a..655bbd43 100644 --- a/api/logic/BaseVersionList.h +++ b/api/logic/BaseVersionList.h @@ -93,11 +93,6 @@ public: */ virtual BaseVersionPtr findVersion(const QString &descriptor); - /*! - * \brief Gets the latest stable version from this list - */ - virtual BaseVersionPtr getLatestStable() const; - /*! * \brief Gets the recommended version from this list * If the list doesn't support recommended versions, this works exactly as getLatestStable diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp index 8a063f48..1638105a 100644 --- a/api/logic/meta/JsonFormat.cpp +++ b/api/logic/meta/JsonFormat.cpp @@ -52,6 +52,7 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) 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, "recommended", false)); if(obj.contains("requires")) { QHash requires; @@ -87,7 +88,9 @@ static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) versions.reserve(versionsRaw.size()); std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [uid](const QJsonObject &vObj) { - return parseCommonVersion(uid, vObj); + auto version = parseCommonVersion(uid, vObj); + version->setProvidesRecommendations(); + return version; }); VersionListPtr list = std::make_shared(uid); diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index 2a8e1780..338e180b 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -53,6 +53,13 @@ void Meta::Version::parse(const QJsonObject& obj) void Meta::Version::merge(const std::shared_ptr &other) { VersionPtr version = std::dynamic_pointer_cast(other); + if(version->m_providesRecommendations) + { + if(m_recommended != version->m_recommended) + { + setRecommended(version->m_recommended); + } + } if (m_type != version->m_type) { setType(version->m_type); @@ -107,3 +114,12 @@ void Meta::Version::setData(const VersionFilePtr &data) m_data = data; } +void Meta::Version::setProvidesRecommendations() +{ + m_providesRecommendations = true; +} + +void Meta::Version::setRecommended(bool recommended) +{ + m_recommended = recommended; +} diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index 8aac8ea1..f132b861 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -72,6 +72,10 @@ public: /* con/des */ { return m_data; } + bool isRecommended() const + { + return m_recommended; + } void merge(const std::shared_ptr &other) override; void parse(const QJsonObject &obj) override; @@ -83,6 +87,8 @@ public: // for usage by format parsers only void setType(const QString &type); void setTime(const qint64 time); void setRequires(const QHash &requires); + void setRecommended(bool recommended); + void setProvidesRecommendations(); void setData(const VersionFilePtr &data); signals: @@ -91,6 +97,8 @@ signals: void requiresChanged(); private: + bool m_providesRecommendations = false; + bool m_recommended = false; QString m_name; QString m_uid; QString m_parentUid; diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 41ed1352..0f1404ba 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -94,8 +94,9 @@ QVariant VersionList::data(const QModelIndex &index, int role) const case RequiresRole: return QVariant::fromValue(version->requires()); case SortRole: return version->rawTime(); case VersionPtrRole: return QVariant::fromValue(version); - case RecommendedRole: return version == getRecommended(); - case LatestRole: return version == getLatestStable(); + case RecommendedRole: return version->isRecommended(); + // FIXME: this should be determined in whatever view/proxy is used... + // case LatestRole: return version == getLatestStable(); default: return QVariant(); } } @@ -158,7 +159,6 @@ void VersionList::setVersions(const QVector &versions) setupAddedVersion(i, m_versions.at(i)); } - m_latest = m_versions.isEmpty() ? nullptr : m_versions.first(); 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(); @@ -202,11 +202,6 @@ void VersionList::merge(const BaseEntity::Ptr &other) m_lookup.insert(version->uid(), version); endInsertRows(); - if (!m_latest || version->rawTime() > m_latest->rawTime()) - { - m_latest = version; - emit dataChanged(index(0), index(m_versions.size() - 1), QVector() << LatestRole); - } if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime())) { m_recommended = version; @@ -224,10 +219,6 @@ void VersionList::setupAddedVersion(const int row, const VersionPtr &version) connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TypeRole); }); } -BaseVersionPtr VersionList::getLatestStable() const -{ - return m_latest; -} BaseVersionPtr VersionList::getRecommended() const { return m_recommended; diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index faacdbf8..e8016314 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -47,7 +47,6 @@ public: int count() const override; void sortVersions() override; - BaseVersionPtr getLatestStable() const override; BaseVersionPtr getRecommended() const override; QVariant data(const QModelIndex &index, int role) const override; @@ -100,7 +99,6 @@ private: QString m_name; VersionPtr m_recommended; - VersionPtr m_latest; void setupAddedVersion(const int row, const VersionPtr &version); }; -- cgit