diff options
Diffstat (limited to 'api/logic/meta')
-rw-r--r-- | api/logic/meta/BaseEntity.cpp | 9 | ||||
-rw-r--r-- | api/logic/meta/BaseEntity.h | 1 | ||||
-rw-r--r-- | api/logic/meta/Index.cpp | 14 | ||||
-rw-r--r-- | api/logic/meta/Index.h | 1 | ||||
-rw-r--r-- | api/logic/meta/Version.cpp | 35 | ||||
-rw-r--r-- | api/logic/meta/Version.h | 84 | ||||
-rw-r--r-- | api/logic/meta/VersionList.cpp | 14 | ||||
-rw-r--r-- | api/logic/meta/VersionList.h | 3 |
8 files changed, 131 insertions, 30 deletions
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<Task> 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<Task> 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<VersionList>(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 <QDateTime> #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<BaseEntity> &other) +void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other) { VersionPtr version = std::dynamic_pointer_cast<Version>(other); if (m_type != version->m_type) @@ -68,28 +75,28 @@ void Version::merge(const std::shared_ptr<BaseEntity> &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<Reference> &requires) +void Meta::Version::setRequires(const QVector<Reference> &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 Version>; -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<Reference> 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<JarmodPtr> getJarMods() override + { + return {}; + } + QString getName() override + { + return name(); + } + QDateTime getReleaseDateTime() override + { + return time(); + } + QString getVersion() override + { + return m_version; + } + std::shared_ptr<class VersionFile> 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<Version>(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<VersionPtr> versions() const { return m_versions; } |