NOISSUE reimplement package dependencies

It is now stored as a hashmap
There is also a parentUid to limit depsolving by encapsulating by version
This commit is contained in:
Petr Mrázek 2017-03-24 02:26:06 +01:00
parent 77f27a628f
commit da4ae1bc1e
10 changed files with 118 additions and 143 deletions

View File

@ -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

View File

@ -48,20 +48,22 @@ static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj)
// Version
static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
{
const QVector<QJsonObject> requiresRaw = obj.contains("requires") ? requireIsArrayOf<QJsonObject>(obj, "requires") : QVector<QJsonObject>();
QVector<Reference> 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<Version>(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<QString, QString> 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<VersionList>(uid);
list->setName(ensureString(obj, "name", QString()));
list->setParentUid(ensureString(obj, "parentUid", QString()));
list->setVersions(versions);
return list;
}

View File

@ -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;
}
}

View File

@ -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 <QString>
#include <QMetaType>
#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)

View File

@ -65,6 +65,10 @@ void Meta::Version::merge(const std::shared_ptr<BaseEntity> &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<Reference> &requires)
void Meta::Version::setRequires(const QHash<QString, QString> &requires)
{
m_requires = requires;
emit requiresChanged();
}
void Meta::Version::setData(const VersionFilePtr &data)
{
m_data = data;

View File

@ -17,15 +17,14 @@
#include "BaseVersion.h"
#include <QVector>
#include <QStringList>
#include <QJsonObject>
#include <QStringList>
#include <QVector>
#include <memory>
#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<Reference> requires READ requires NOTIFY requiresChanged)
Q_PROPERTY(QHash<QString, QString> 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<Reference> requires() const { return m_requires; }
VersionFilePtr data() const { return m_data; }
qint64 rawTime() const
{
return m_time;
}
const QHash<QString, QString> &requires() const
{
return m_requires;
}
VersionFilePtr data() const
{
return m_data;
}
void merge(const std::shared_ptr<BaseEntity> &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<Reference> &requires);
void setRequires(const QHash<QString, QString> &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<Reference> m_requires;
QHash<QString, QString> m_requires;
VersionFilePtr m_data;
};
}

View File

@ -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"

View File

@ -15,8 +15,8 @@
#pragma once
#include "BaseVersionList.h"
#include "BaseEntity.h"
#include "BaseVersionList.h"
#include <QJsonObject>
#include <memory>
@ -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<VersionPtr> versions() const { return m_versions; }
QVector<VersionPtr> 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<VersionPtr> &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<BaseVersionPtr>) override {}
void updateListData(QList<BaseVersionPtr>) override
{
}
private:
QVector<VersionPtr> m_versions;
QHash<QString, VersionPtr> 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)

View File

@ -43,6 +43,9 @@
#include "MultiMC.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
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;

View File

@ -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');
}