summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-12-14 02:22:20 +0100
committerPetr Mrázek <peterix@gmail.com>2017-12-14 02:22:20 +0100
commitdaf9d0eaa7e762ad8571f91a266098631b1843e6 (patch)
treed0a707e4742f787f9769c0bbc2c0e0213bd22b48 /api
parentf18afd3d1e73cc0020bfa1189e0b8fefc0f14e61 (diff)
downloadMultiMC-daf9d0eaa7e762ad8571f91a266098631b1843e6.tar
MultiMC-daf9d0eaa7e762ad8571f91a266098631b1843e6.tar.gz
MultiMC-daf9d0eaa7e762ad8571f91a266098631b1843e6.tar.lz
MultiMC-daf9d0eaa7e762ad8571f91a266098631b1843e6.tar.xz
MultiMC-daf9d0eaa7e762ad8571f91a266098631b1843e6.zip
NOISSUE do not override already loaded metadata entities with partial data
Diffstat (limited to 'api')
-rw-r--r--api/logic/meta/BaseEntity.h1
-rw-r--r--api/logic/meta/Index.cpp4
-rw-r--r--api/logic/meta/Index.h2
-rw-r--r--api/logic/meta/JsonFormat.cpp6
-rw-r--r--api/logic/meta/Version.cpp42
-rw-r--r--api/logic/meta/Version.h3
-rw-r--r--api/logic/meta/VersionList.cpp31
-rw-r--r--api/logic/meta/VersionList.h3
8 files changed, 55 insertions, 37 deletions
diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h
index 4c74b1a7..9120b844 100644
--- a/api/logic/meta/BaseEntity.h
+++ b/api/logic/meta/BaseEntity.h
@@ -46,7 +46,6 @@ public: /* types */
public:
virtual ~BaseEntity();
- virtual void merge(const std::shared_ptr<BaseEntity> &other) = 0;
virtual void parse(const QJsonObject &obj) = 0;
virtual QString localFilename() const = 0;
diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp
index 0749651a..c67ab48c 100644
--- a/api/logic/meta/Index.cpp
+++ b/api/logic/meta/Index.cpp
@@ -103,7 +103,7 @@ void Index::parse(const QJsonObject& obj)
parseIndex(obj, this);
}
-void Index::merge(const Ptr &other)
+void Index::merge(const std::shared_ptr<Index> &other)
{
const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
// initial load, no need to merge
@@ -124,7 +124,7 @@ void Index::merge(const Ptr &other)
{
if (m_uids.contains(list->uid()))
{
- m_uids[list->uid()]->merge(list);
+ m_uids[list->uid()]->mergeFromIndex(list);
}
else
{
diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h
index 9811e152..d820f825 100644
--- a/api/logic/meta/Index.h
+++ b/api/logic/meta/Index.h
@@ -58,7 +58,7 @@ public:
QVector<VersionListPtr> lists() const { return m_lists; }
public: // for usage by parsers only
- void merge(const BaseEntity::Ptr &other) override;
+ void merge(const std::shared_ptr<Index> &other);
void parse(const QJsonObject &obj) override;
private:
diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp
index 2c313478..832743ed 100644
--- a/api/logic/meta/JsonFormat.cpp
+++ b/api/logic/meta/JsonFormat.cpp
@@ -29,7 +29,7 @@ namespace Meta
{
// Index
-static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj)
+static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
{
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages");
QVector<VersionListPtr> lists;
@@ -59,7 +59,7 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
return version;
}
-static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj)
+static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj)
{
VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj);
@@ -70,7 +70,7 @@ static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj)
}
// Version list / package
-static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj)
+static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &obj)
{
const QString uid = requireString(obj, "uid");
diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp
index d82878a1..55b92966 100644
--- a/api/logic/meta/Version.cpp
+++ b/api/logic/meta/Version.cpp
@@ -54,43 +54,47 @@ void Meta::Version::parse(const QJsonObject& obj)
parseVersion(obj, this);
}
-void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
+void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
{
- VersionPtr version = std::dynamic_pointer_cast<Version>(other);
- if(version->m_providesRecommendations)
+ if(other->m_providesRecommendations)
{
- if(m_recommended != version->m_recommended)
+ if(m_recommended != other->m_recommended)
{
- setRecommended(version->m_recommended);
+ setRecommended(other->m_recommended);
}
}
- if (m_type != version->m_type)
+ if (m_type != other->m_type)
{
- setType(version->m_type);
+ setType(other->m_type);
}
- if (m_time != version->m_time)
+ if (m_time != other->m_time)
{
- setTime(version->m_time);
+ setTime(other->m_time);
}
- if (m_requires != version->m_requires)
+ if (m_requires != other->m_requires)
{
- m_requires = version->m_requires;
+ m_requires = other->m_requires;
}
- if (m_conflicts != version->m_conflicts)
+ if (m_conflicts != other->m_conflicts)
{
- m_conflicts = version->m_conflicts;
+ m_conflicts = other->m_conflicts;
}
- if (m_parentUid != version->m_parentUid)
+ if (m_parentUid != other->m_parentUid)
{
- setParentUid(version->m_parentUid);
+ setParentUid(other->m_parentUid);
}
- if(m_volatile != version->m_volatile)
+ if(m_volatile != other->m_volatile)
{
- setVolatile(version->m_volatile);
+ setVolatile(other->m_volatile);
}
- if(version->m_data)
+}
+
+void Meta::Version::merge(const VersionPtr &other)
+{
+ mergeFromList(other);
+ if(other->m_data)
{
- setData(version->m_data);
+ setData(other->m_data);
}
}
diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h
index 61f253c6..debdf20a 100644
--- a/api/logic/meta/Version.h
+++ b/api/logic/meta/Version.h
@@ -84,7 +84,8 @@ public: /* con/des */
return m_data != nullptr;
}
- void merge(const std::shared_ptr<BaseEntity> &other) override;
+ void merge(const VersionPtr &other);
+ void mergeFromList(const VersionPtr &other);
void parse(const QJsonObject &obj) override;
QString localFilename() const override;
diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp
index 1387f282..4963f235 100644
--- a/api/logic/meta/VersionList.cpp
+++ b/api/logic/meta/VersionList.cpp
@@ -19,6 +19,7 @@
#include "Version.h"
#include "JsonFormat.h"
+#include "Version.h"
namespace Meta
{
@@ -189,32 +190,44 @@ static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const
return (a->type() == "release" ? a : b);
}
-void VersionList::merge(const BaseEntity::Ptr &other)
+void VersionList::mergeFromIndex(const VersionListPtr &other)
+{
+ if (m_name != other->m_name)
+ {
+ setName(other->m_name);
+ }
+
+ if(m_parentUid != other->m_parentUid)
+ {
+ setParentUid(other->m_parentUid);
+ }
+}
+
+void VersionList::merge(const VersionListPtr &other)
{
- const VersionListPtr list = std::dynamic_pointer_cast<VersionList>(other);
- if (m_name != list->m_name)
+ if (m_name != other->m_name)
{
- setName(list->m_name);
+ setName(other->m_name);
}
- if(m_parentUid != list->m_parentUid)
+ if(m_parentUid != other->m_parentUid)
{
- setParentUid(list->m_parentUid);
+ setParentUid(other->m_parentUid);
}
// TODO: do not reset the whole model. maybe?
beginResetModel();
m_versions.clear();
- if(list->m_versions.isEmpty())
+ if(other->m_versions.isEmpty())
{
qWarning() << "Empty list loaded ...";
}
- for (const VersionPtr &version : list->m_versions)
+ for (const VersionPtr &version : other->m_versions)
{
// we already have the version. merge the contents
if (m_lookup.contains(version->version()))
{
- m_lookup.value(version->version())->merge(version);
+ m_lookup.value(version->version())->mergeFromList(version);
}
else
{
diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h
index e8016314..c4a2b757 100644
--- a/api/logic/meta/VersionList.h
+++ b/api/logic/meta/VersionList.h
@@ -80,7 +80,8 @@ 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 merge(const VersionListPtr &other);
+ void mergeFromIndex(const VersionListPtr &other);
void parse(const QJsonObject &obj) override;
signals: