diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 544ace80d..7f04a41e3 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 4e43b7152..8a063f48e 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 c5cef1722..000000000 --- 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 027076ccf..000000000 --- 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 fee7d049b..af9d4f100 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 b3943f471..1d9210356 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 28d9dd26d..c27121557 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 08d712304..faacdbf87 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 732a33eb2..0608b2bfb 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 e4967532a..e15ddbabb 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'); }