NOISSUE Wonko is the new Meta

And then Wonko was the Meta.
This commit is contained in:
Petr Mrázek 2017-03-11 01:39:45 +01:00
parent 1fbe03f982
commit ab868df50e
37 changed files with 820 additions and 872 deletions

View File

@ -430,32 +430,32 @@ set(TOOLS_SOURCES
tools/MCEditTool.h
)
set(WONKO_SOURCES
# Wonko
wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp
wonko/tasks/BaseWonkoEntityRemoteLoadTask.h
wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp
wonko/tasks/BaseWonkoEntityLocalLoadTask.h
wonko/format/WonkoFormatV1.cpp
wonko/format/WonkoFormatV1.h
wonko/format/WonkoFormat.cpp
wonko/format/WonkoFormat.h
wonko/BaseWonkoEntity.cpp
wonko/BaseWonkoEntity.h
wonko/WonkoVersionList.cpp
wonko/WonkoVersionList.h
wonko/WonkoVersion.cpp
wonko/WonkoVersion.h
wonko/WonkoIndex.cpp
wonko/WonkoIndex.h
wonko/WonkoUtil.cpp
wonko/WonkoUtil.h
wonko/WonkoReference.cpp
wonko/WonkoReference.h
set(META_SOURCES
# Metadata sources
meta/tasks/RemoteLoadTask.cpp
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
meta/BaseEntity.h
meta/VersionList.cpp
meta/VersionList.h
meta/Version.cpp
meta/Version.h
meta/Index.cpp
meta/Index.h
meta/Util.cpp
meta/Util.h
meta/Reference.cpp
meta/Reference.h
)
add_unit_test(WonkoIndex
SOURCES wonko/WonkoIndex_test.cpp
add_unit_test(Index
SOURCES meta/Index_test.cpp
LIBS MultiMC_logic
)
@ -480,7 +480,7 @@ set(LOGIC_SOURCES
${JAVA_SOURCES}
${TRANSLATIONS_SOURCES}
${TOOLS_SOURCES}
${WONKO_SOURCES}
${META_SOURCES}
${ICONS_SOURCES}
)

View File

@ -7,7 +7,7 @@
#include <QNetworkAccessManager>
#include <QDebug>
#include "tasks/Task.h"
#include "wonko/WonkoIndex.h"
#include "meta/Index.h"
#include <QDebug>
@ -18,8 +18,7 @@ public:
shared_qobject_ptr<HttpMetaCache> m_metacache;
std::shared_ptr<IIconList> m_iconlist;
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
shared_qobject_ptr<WonkoIndex> m_wonkoIndex;
QString m_wonkoRootUrl;
shared_qobject_ptr<Meta::Index> m_metadataIndex;
};
static Env * instance;
@ -99,13 +98,13 @@ void Env::registerVersionList(QString name, std::shared_ptr< BaseVersionList > v
d->m_versionLists[name] = vlist;
}
shared_qobject_ptr<WonkoIndex> Env::wonkoIndex()
shared_qobject_ptr<Meta::Index> Env::metadataIndex()
{
if (!d->m_wonkoIndex)
if (!d->m_metadataIndex)
{
d->m_wonkoIndex.reset(new WonkoIndex());
d->m_metadataIndex.reset(new Meta::Index());
}
return d->m_wonkoIndex;
return d->m_metadataIndex;
}
@ -125,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("wonko", QDir("cache/wonko").absolutePath());
m_metacache->addBase("meta", QDir("cache/meta").absolutePath());
m_metacache->Load();
}
@ -191,14 +190,4 @@ void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QStr
qDebug() << proxyDesc;
}
QString Env::wonkoRootUrl() const
{
return d->m_wonkoRootUrl;
}
void Env::setWonkoRootUrl(const QString& url)
{
d->m_wonkoRootUrl = url;
}
#include "Env.moc"
#include "Env.moc"

View File

@ -13,7 +13,11 @@ class QNetworkAccessManager;
class HttpMetaCache;
class BaseVersionList;
class BaseVersion;
class WonkoIndex;
namespace Meta
{
class Index;
}
#if defined(ENV)
#undef ENV
@ -53,10 +57,7 @@ public:
void registerIconList(std::shared_ptr<IIconList> iconlist);
shared_qobject_ptr<WonkoIndex> wonkoIndex();
QString wonkoRootUrl() const;
void setWonkoRootUrl(const QString &url);
shared_qobject_ptr<Meta::Index> metadataIndex();
protected:
Private * d;

View File

@ -13,27 +13,30 @@
* limitations under the License.
*/
#include "BaseWonkoEntity.h"
#include "BaseEntity.h"
#include "Json.h"
#include "WonkoUtil.h"
#include "Util.h"
BaseWonkoEntity::~BaseWonkoEntity()
namespace Meta
{
BaseEntity::~BaseEntity()
{
}
void BaseWonkoEntity::store() const
void BaseEntity::store() const
{
Json::write(serialized(), Wonko::localWonkoDir().absoluteFilePath(localFilename()));
Json::write(serialized(), Meta::localDir().absoluteFilePath(localFilename()));
}
void BaseWonkoEntity::notifyLocalLoadComplete()
void BaseEntity::notifyLocalLoadComplete()
{
m_localLoaded = true;
store();
}
void BaseWonkoEntity::notifyRemoteLoadComplete()
void BaseEntity::notifyRemoteLoadComplete()
{
m_remoteLoaded = true;
store();
}
}

View File

@ -21,17 +21,18 @@
#include "multimc_logic_export.h"
class Task;
class MULTIMC_LOGIC_EXPORT BaseWonkoEntity
namespace Meta
{
class MULTIMC_LOGIC_EXPORT BaseEntity
{
public:
virtual ~BaseWonkoEntity();
virtual ~BaseEntity();
using Ptr = std::shared_ptr<BaseWonkoEntity>;
using Ptr = std::shared_ptr<BaseEntity>;
virtual std::unique_ptr<Task> remoteUpdateTask() = 0;
virtual std::unique_ptr<Task> localUpdateTask() = 0;
virtual void merge(const std::shared_ptr<BaseWonkoEntity> &other) = 0;
virtual void merge(const std::shared_ptr<BaseEntity> &other) = 0;
void store() const;
virtual QString localFilename() const = 0;
@ -49,3 +50,4 @@ private:
bool m_localLoaded = false;
bool m_remoteLoaded = false;
};
}

View File

@ -13,18 +13,20 @@
* limitations under the License.
*/
#include "WonkoIndex.h"
#include "Index.h"
#include "WonkoVersionList.h"
#include "tasks/BaseWonkoEntityLocalLoadTask.h"
#include "tasks/BaseWonkoEntityRemoteLoadTask.h"
#include "format/WonkoFormat.h"
#include "VersionList.h"
#include "tasks/LocalLoadTask.h"
#include "tasks/RemoteLoadTask.h"
#include "format/Format.h"
WonkoIndex::WonkoIndex(QObject *parent)
namespace Meta
{
Index::Index(QObject *parent)
: QAbstractListModel(parent)
{
}
WonkoIndex::WonkoIndex(const QVector<WonkoVersionListPtr> &lists, QObject *parent)
Index::Index(const QVector<VersionListPtr> &lists, QObject *parent)
: QAbstractListModel(parent), m_lists(lists)
{
for (int i = 0; i < m_lists.size(); ++i)
@ -34,14 +36,14 @@ WonkoIndex::WonkoIndex(const QVector<WonkoVersionListPtr> &lists, QObject *paren
}
}
QVariant WonkoIndex::data(const QModelIndex &index, int role) const
QVariant Index::data(const QModelIndex &index, int role) const
{
if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size())
{
return QVariant();
}
WonkoVersionListPtr list = m_lists.at(index.row());
VersionListPtr list = m_lists.at(index.row());
switch (role)
{
case Qt::DisplayRole:
@ -56,15 +58,15 @@ QVariant WonkoIndex::data(const QModelIndex &index, int role) const
}
return QVariant();
}
int WonkoIndex::rowCount(const QModelIndex &parent) const
int Index::rowCount(const QModelIndex &parent) const
{
return m_lists.size();
}
int WonkoIndex::columnCount(const QModelIndex &parent) const
int Index::columnCount(const QModelIndex &parent) const
{
return 1;
}
QVariant WonkoIndex::headerData(int section, Qt::Orientation orientation, int role) const
QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0)
{
@ -76,36 +78,36 @@ QVariant WonkoIndex::headerData(int section, Qt::Orientation orientation, int ro
}
}
std::unique_ptr<Task> WonkoIndex::remoteUpdateTask()
std::unique_ptr<Task> Index::remoteUpdateTask()
{
return std::unique_ptr<WonkoIndexRemoteLoadTask>(new WonkoIndexRemoteLoadTask(this, this));
return std::unique_ptr<IndexRemoteLoadTask>(new IndexRemoteLoadTask(this, this));
}
std::unique_ptr<Task> WonkoIndex::localUpdateTask()
std::unique_ptr<Task> Index::localUpdateTask()
{
return std::unique_ptr<WonkoIndexLocalLoadTask>(new WonkoIndexLocalLoadTask(this, this));
return std::unique_ptr<IndexLocalLoadTask>(new IndexLocalLoadTask(this, this));
}
QJsonObject WonkoIndex::serialized() const
QJsonObject Index::serialized() const
{
return WonkoFormat::serializeIndex(this);
return Format::serializeIndex(this);
}
bool WonkoIndex::hasUid(const QString &uid) const
bool Index::hasUid(const QString &uid) const
{
return m_uids.contains(uid);
}
WonkoVersionListPtr WonkoIndex::getList(const QString &uid) const
VersionListPtr Index::getList(const QString &uid) const
{
return m_uids.value(uid, nullptr);
}
WonkoVersionListPtr WonkoIndex::getListGuaranteed(const QString &uid) const
VersionListPtr Index::getListGuaranteed(const QString &uid) const
{
return m_uids.value(uid, std::make_shared<WonkoVersionList>(uid));
return m_uids.value(uid, std::make_shared<VersionList>(uid));
}
void WonkoIndex::merge(const Ptr &other)
void Index::merge(const Ptr &other)
{
const QVector<WonkoVersionListPtr> lists = std::dynamic_pointer_cast<WonkoIndex>(other)->m_lists;
const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
// initial load, no need to merge
if (m_lists.isEmpty())
{
@ -120,7 +122,7 @@ void WonkoIndex::merge(const Ptr &other)
}
else
{
for (const WonkoVersionListPtr &list : lists)
for (const VersionListPtr &list : lists)
{
if (m_uids.contains(list->uid()))
{
@ -138,10 +140,11 @@ void WonkoIndex::merge(const Ptr &other)
}
}
void WonkoIndex::connectVersionList(const int row, const WonkoVersionListPtr &list)
void Index::connectVersionList(const int row, const VersionListPtr &list)
{
connect(list.get(), &WonkoVersionList::nameChanged, this, [this, row]()
connect(list.get(), &VersionList::nameChanged, this, [this, row]()
{
emit dataChanged(index(row), index(row), QVector<int>() << Qt::DisplayRole);
});
}
}

View File

@ -18,19 +18,22 @@
#include <QAbstractListModel>
#include <memory>
#include "BaseWonkoEntity.h"
#include "BaseEntity.h"
#include "multimc_logic_export.h"
class Task;
using WonkoVersionListPtr = std::shared_ptr<class WonkoVersionList>;
class MULTIMC_LOGIC_EXPORT WonkoIndex : public QAbstractListModel, public BaseWonkoEntity
namespace Meta
{
using VersionListPtr = std::shared_ptr<class VersionList>;
class MULTIMC_LOGIC_EXPORT Index : public QAbstractListModel, public BaseEntity
{
Q_OBJECT
public:
explicit WonkoIndex(QObject *parent = nullptr);
explicit WonkoIndex(const QVector<WonkoVersionListPtr> &lists, QObject *parent = nullptr);
explicit Index(QObject *parent = nullptr);
explicit Index(const QVector<VersionListPtr> &lists, QObject *parent = nullptr);
enum
{
@ -52,17 +55,18 @@ public:
// queries
bool hasUid(const QString &uid) const;
WonkoVersionListPtr getList(const QString &uid) const;
WonkoVersionListPtr getListGuaranteed(const QString &uid) const;
VersionListPtr getList(const QString &uid) const;
VersionListPtr getListGuaranteed(const QString &uid) const;
QVector<WonkoVersionListPtr> lists() const { return m_lists; }
QVector<VersionListPtr> lists() const { return m_lists; }
public: // for usage by parsers only
void merge(const BaseWonkoEntity::Ptr &other);
void merge(const BaseEntity::Ptr &other) override;
private:
QVector<WonkoVersionListPtr> m_lists;
QHash<QString, WonkoVersionListPtr> m_uids;
QVector<VersionListPtr> m_lists;
QHash<QString, VersionListPtr> m_uids;
void connectVersionList(const int row, const WonkoVersionListPtr &list);
void connectVersionList(const int row, const VersionListPtr &list);
};
}

View File

@ -0,0 +1,50 @@
#include <QTest>
#include "TestUtil.h"
#include "meta/Index.h"
#include "meta/VersionList.h"
#include "Env.h"
class IndexTest : public QObject
{
Q_OBJECT
private
slots:
void test_isProvidedByEnv()
{
QVERIFY(ENV.metadataIndex());
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<Meta::VersionList>("list1"), std::make_shared<Meta::VersionList>("list2"), std::make_shared<Meta::VersionList>("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);
}
void test_merge()
{
Meta::Index windex({std::make_shared<Meta::VersionList>("list1"), std::make_shared<Meta::VersionList>("list2"), std::make_shared<Meta::VersionList>("list3")});
QCOMPARE(windex.lists().size(), 3);
windex.merge(std::shared_ptr<Meta::Index>(new Meta::Index({std::make_shared<Meta::VersionList>("list1"), std::make_shared<Meta::VersionList>("list2"), std::make_shared<Meta::VersionList>("list3")})));
QCOMPARE(windex.lists().size(), 3);
windex.merge(std::shared_ptr<Meta::Index>(new Meta::Index({std::make_shared<Meta::VersionList>("list4"), std::make_shared<Meta::VersionList>("list2"), std::make_shared<Meta::VersionList>("list5")})));
QCOMPARE(windex.lists().size(), 5);
windex.merge(std::shared_ptr<Meta::Index>(new Meta::Index({std::make_shared<Meta::VersionList>("list6")})));
QCOMPARE(windex.lists().size(), 6);
}
};
QTEST_GUILESS_MAIN(IndexTest)
#include "Index_test.moc"

View File

@ -13,32 +13,36 @@
* limitations under the License.
*/
#include "WonkoReference.h"
#include "Reference.h"
WonkoReference::WonkoReference(const QString &uid)
namespace Meta
{
Reference::Reference(const QString &uid)
: m_uid(uid)
{
}
QString WonkoReference::uid() const
QString Reference::uid() const
{
return m_uid;
}
QString WonkoReference::version() const
QString Reference::version() const
{
return m_version;
}
void WonkoReference::setVersion(const QString &version)
void Reference::setVersion(const QString &version)
{
m_version = version;
}
bool WonkoReference::operator==(const WonkoReference &other) const
bool Reference::operator==(const Reference &other) const
{
return m_uid == other.m_uid && m_version == other.m_version;
}
bool WonkoReference::operator!=(const WonkoReference &other) const
bool Reference::operator!=(const Reference &other) const
{
return m_uid != other.m_uid || m_version != other.m_version;
}
}

View File

@ -20,22 +20,25 @@
#include "multimc_logic_export.h"
class MULTIMC_LOGIC_EXPORT WonkoReference
namespace Meta
{
class MULTIMC_LOGIC_EXPORT Reference
{
public:
WonkoReference() {}
explicit WonkoReference(const QString &uid);
Reference() {}
explicit Reference(const QString &uid);
QString uid() const;
QString version() const;
void setVersion(const QString &version);
bool operator==(const WonkoReference &other) const;
bool operator!=(const WonkoReference &other) const;
bool operator==(const Reference &other) const;
bool operator!=(const Reference &other) const;
private:
QString m_uid;
QString m_version;
};
Q_DECLARE_METATYPE(WonkoReference)
}
Q_DECLARE_METATYPE(Meta::Reference)

View File

@ -13,35 +13,38 @@
* limitations under the License.
*/
#include "WonkoUtil.h"
#include "Util.h"
#include <QUrl>
#include <QDir>
#include "Env.h"
namespace Wonko
namespace Meta
{
QUrl rootUrl()
{
return ENV.wonkoRootUrl();
return QUrl("https://meta.multimc.org");
}
QUrl indexUrl()
{
return rootUrl().resolved(QStringLiteral("index.json"));
}
QUrl versionListUrl(const QString &uid)
{
return rootUrl().resolved(uid + ".json");
}
QUrl versionUrl(const QString &uid, const QString &version)
{
return rootUrl().resolved(uid + "/" + version + ".json");
}
QDir localWonkoDir()
QDir localDir()
{
return QDir("wonko");
return QDir("meta");
}
}

View File

@ -21,11 +21,11 @@ class QUrl;
class QString;
class QDir;
namespace Wonko
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 localWonkoDir();
MULTIMC_LOGIC_EXPORT QDir localDir();
}

View File

@ -13,49 +13,51 @@
* limitations under the License.
*/
#include "WonkoVersion.h"
#include "Version.h"
#include <QDateTime>
#include "tasks/BaseWonkoEntityLocalLoadTask.h"
#include "tasks/BaseWonkoEntityRemoteLoadTask.h"
#include "format/WonkoFormat.h"
#include "tasks/LocalLoadTask.h"
#include "tasks/RemoteLoadTask.h"
#include "format/Format.h"
WonkoVersion::WonkoVersion(const QString &uid, const QString &version)
namespace Meta
{
Version::Version(const QString &uid, const QString &version)
: BaseVersion(), m_uid(uid), m_version(version)
{
}
QString WonkoVersion::descriptor()
QString Version::descriptor()
{
return m_version;
}
QString WonkoVersion::name()
QString Version::name()
{
return m_version;
}
QString WonkoVersion::typeString() const
QString Version::typeString() const
{
return m_type;
}
QDateTime WonkoVersion::time() const
QDateTime Version::time() const
{
return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC);
}
std::unique_ptr<Task> WonkoVersion::remoteUpdateTask()
std::unique_ptr<Task> Version::remoteUpdateTask()
{
return std::unique_ptr<WonkoVersionRemoteLoadTask>(new WonkoVersionRemoteLoadTask(this, this));
return std::unique_ptr<VersionRemoteLoadTask>(new VersionRemoteLoadTask(this, this));
}
std::unique_ptr<Task> WonkoVersion::localUpdateTask()
std::unique_ptr<Task> Version::localUpdateTask()
{
return std::unique_ptr<WonkoVersionLocalLoadTask>(new WonkoVersionLocalLoadTask(this, this));
return std::unique_ptr<VersionLocalLoadTask>(new VersionLocalLoadTask(this, this));
}
void WonkoVersion::merge(const std::shared_ptr<BaseWonkoEntity> &other)
void Version::merge(const std::shared_ptr<BaseEntity> &other)
{
WonkoVersionPtr version = std::dynamic_pointer_cast<WonkoVersion>(other);
VersionPtr version = std::dynamic_pointer_cast<Version>(other);
if (m_type != version->m_type)
{
setType(version->m_type);
@ -72,31 +74,32 @@ void WonkoVersion::merge(const std::shared_ptr<BaseWonkoEntity> &other)
setData(version->m_data);
}
QString WonkoVersion::localFilename() const
QString Version::localFilename() const
{
return m_uid + '/' + m_version + ".json";
}
QJsonObject WonkoVersion::serialized() const
QJsonObject Version::serialized() const
{
return WonkoFormat::serializeVersion(this);
return Format::serializeVersion(this);
}
void WonkoVersion::setType(const QString &type)
void Version::setType(const QString &type)
{
m_type = type;
emit typeChanged();
}
void WonkoVersion::setTime(const qint64 time)
void Version::setTime(const qint64 time)
{
m_time = time;
emit timeChanged();
}
void WonkoVersion::setRequires(const QVector<WonkoReference> &requires)
void Version::setRequires(const QVector<Reference> &requires)
{
m_requires = requires;
emit requiresChanged();
}
void WonkoVersion::setData(const VersionFilePtr &data)
void Version::setData(const VersionFilePtr &data)
{
m_data = data;
}
}

View File

@ -16,7 +16,6 @@
#pragma once
#include "BaseVersion.h"
#include "BaseWonkoEntity.h"
#include <QVector>
#include <QStringList>
@ -24,22 +23,26 @@
#include <memory>
#include "minecraft/VersionFile.h"
#include "WonkoReference.h"
#include "BaseEntity.h"
#include "Reference.h"
#include "multimc_logic_export.h"
using WonkoVersionPtr = std::shared_ptr<class WonkoVersion>;
namespace Meta
{
using VersionPtr = std::shared_ptr<class Version>;
class MULTIMC_LOGIC_EXPORT WonkoVersion : public QObject, public BaseVersion, public BaseWonkoEntity
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<WonkoReference> requires READ requires NOTIFY requiresChanged)
Q_PROPERTY(QVector<Reference> requires READ requires NOTIFY requiresChanged)
public:
explicit WonkoVersion(const QString &uid, const QString &version);
explicit Version(const QString &uid, const QString &version);
QString descriptor() override;
QString name() override;
@ -50,12 +53,12 @@ public:
QString type() const { return m_type; }
QDateTime time() const;
qint64 rawTime() const { return m_time; }
QVector<WonkoReference> requires() const { return m_requires; }
QVector<Reference> requires() const { return m_requires; }
VersionFilePtr data() const { return m_data; }
std::unique_ptr<Task> remoteUpdateTask() override;
std::unique_ptr<Task> localUpdateTask() override;
void merge(const std::shared_ptr<BaseWonkoEntity> &other) override;
void merge(const std::shared_ptr<BaseEntity> &other) override;
QString localFilename() const override;
QJsonObject serialized() const override;
@ -63,7 +66,7 @@ public:
public: // for usage by format parsers only
void setType(const QString &type);
void setTime(const qint64 time);
void setRequires(const QVector<WonkoReference> &requires);
void setRequires(const QVector<Reference> &requires);
void setData(const VersionFilePtr &data);
signals:
@ -76,8 +79,9 @@ private:
QString m_version;
QString m_type;
qint64 m_time;
QVector<WonkoReference> m_requires;
QVector<Reference> m_requires;
VersionFilePtr m_data;
};
}
Q_DECLARE_METATYPE(WonkoVersionPtr)
Q_DECLARE_METATYPE(Meta::VersionPtr)

View File

@ -13,21 +13,24 @@
* limitations under the License.
*/
#include "WonkoVersionList.h"
#include "VersionList.h"
#include <QDateTime>
#include "WonkoVersion.h"
#include "tasks/BaseWonkoEntityRemoteLoadTask.h"
#include "tasks/BaseWonkoEntityLocalLoadTask.h"
#include "format/WonkoFormat.h"
#include "WonkoReference.h"
#include "Version.h"
#include "tasks/RemoteLoadTask.h"
#include "tasks/LocalLoadTask.h"
#include "format/Format.h"
#include "Reference.h"
namespace Meta
{
class WVLLoadTask : public Task
{
Q_OBJECT
public:
explicit WVLLoadTask(WonkoVersionList *list, QObject *parent = nullptr)
explicit WVLLoadTask(VersionList *list, QObject *parent = nullptr)
: Task(parent), m_list(list)
{
}
@ -69,53 +72,53 @@ private:
m_currentTask->start();
}
WonkoVersionList *m_list;
VersionList *m_list;
std::unique_ptr<Task> m_currentTask;
};
WonkoVersionList::WonkoVersionList(const QString &uid, QObject *parent)
VersionList::VersionList(const QString &uid, QObject *parent)
: BaseVersionList(parent), m_uid(uid)
{
setObjectName("Wonko version list: " + uid);
setObjectName("Version list: " + uid);
}
Task *WonkoVersionList::getLoadTask()
Task *VersionList::getLoadTask()
{
return new WVLLoadTask(this);
}
bool WonkoVersionList::isLoaded()
bool VersionList::isLoaded()
{
return isLocalLoaded() && isRemoteLoaded();
}
const BaseVersionPtr WonkoVersionList::at(int i) const
const BaseVersionPtr VersionList::at(int i) const
{
return m_versions.at(i);
}
int WonkoVersionList::count() const
int VersionList::count() const
{
return m_versions.size();
}
void WonkoVersionList::sortVersions()
void VersionList::sortVersions()
{
beginResetModel();
std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b)
std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b)
{
return *a.get() < *b.get();
});
endResetModel();
}
QVariant WonkoVersionList::data(const QModelIndex &index, int role) const
QVariant VersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_versions.size() || index.parent().isValid())
{
return QVariant();
}
WonkoVersionPtr version = m_versions.at(index.row());
VersionPtr version = m_versions.at(index.row());
switch (role)
{
@ -127,7 +130,7 @@ QVariant WonkoVersionList::data(const QModelIndex &index, int role) const
{
const auto end = version->requires().end();
const auto it = std::find_if(version->requires().begin(), end,
[](const WonkoReference &ref) { return ref.uid() == "net.minecraft"; });
[](const Reference &ref) { return ref.uid() == "net.minecraft"; });
if (it != end)
{
return (*it).version();
@ -140,21 +143,21 @@ QVariant WonkoVersionList::data(const QModelIndex &index, int role) const
case TimeRole: return version->time();
case RequiresRole: return QVariant::fromValue(version->requires());
case SortRole: return version->rawTime();
case WonkoVersionPtrRole: return QVariant::fromValue(version);
case VersionPtrRole: return QVariant::fromValue(version);
case RecommendedRole: return version == getRecommended();
case LatestRole: return version == getLatestStable();
default: return QVariant();
}
}
BaseVersionList::RoleList WonkoVersionList::providesRoles() const
BaseVersionList::RoleList VersionList::providesRoles() const
{
return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole,
TypeRole, UidRole, TimeRole, RequiresRole, SortRole,
RecommendedRole, LatestRole, WonkoVersionPtrRole};
RecommendedRole, LatestRole, VersionPtrRole};
}
QHash<int, QByteArray> WonkoVersionList::roleNames() const
QHash<int, QByteArray> VersionList::roleNames() const
{
QHash<int, QByteArray> roles = BaseVersionList::roleNames();
roles.insert(UidRole, "uid");
@ -164,48 +167,48 @@ QHash<int, QByteArray> WonkoVersionList::roleNames() const
return roles;
}
std::unique_ptr<Task> WonkoVersionList::remoteUpdateTask()
std::unique_ptr<Task> VersionList::remoteUpdateTask()
{
return std::unique_ptr<WonkoVersionListRemoteLoadTask>(new WonkoVersionListRemoteLoadTask(this, this));
return std::unique_ptr<VersionListRemoteLoadTask>(new VersionListRemoteLoadTask(this, this));
}
std::unique_ptr<Task> WonkoVersionList::localUpdateTask()
std::unique_ptr<Task> VersionList::localUpdateTask()
{
return std::unique_ptr<WonkoVersionListLocalLoadTask>(new WonkoVersionListLocalLoadTask(this, this));
return std::unique_ptr<VersionListLocalLoadTask>(new VersionListLocalLoadTask(this, this));
}
QString WonkoVersionList::localFilename() const
QString VersionList::localFilename() const
{
return m_uid + ".json";
}
QJsonObject WonkoVersionList::serialized() const
QJsonObject VersionList::serialized() const
{
return WonkoFormat::serializeVersionList(this);
return Format::serializeVersionList(this);
}
QString WonkoVersionList::humanReadable() const
QString VersionList::humanReadable() const
{
return m_name.isEmpty() ? m_uid : m_name;
}
bool WonkoVersionList::hasVersion(const QString &version) const
bool VersionList::hasVersion(const QString &version) const
{
return m_lookup.contains(version);
}
WonkoVersionPtr WonkoVersionList::getVersion(const QString &version) const
VersionPtr VersionList::getVersion(const QString &version) const
{
return m_lookup.value(version);
}
void WonkoVersionList::setName(const QString &name)
void VersionList::setName(const QString &name)
{
m_name = name;
emit nameChanged(name);
}
void WonkoVersionList::setVersions(const QVector<WonkoVersionPtr> &versions)
void VersionList::setVersions(const QVector<VersionPtr> &versions)
{
beginResetModel();
m_versions = versions;
std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b)
std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b)
{
return a->rawTime() > b->rawTime();
});
@ -216,14 +219,14 @@ void WonkoVersionList::setVersions(const QVector<WonkoVersionPtr> &versions)
}
m_latest = m_versions.isEmpty() ? nullptr : m_versions.first();
auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const WonkoVersionPtr &ptr) { return ptr->type() == "release"; });
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();
}
void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other)
void VersionList::merge(const BaseEntity::Ptr &other)
{
const WonkoVersionListPtr list = std::dynamic_pointer_cast<WonkoVersionList>(other);
const VersionListPtr list = std::dynamic_pointer_cast<VersionList>(other);
if (m_name != list->m_name)
{
setName(list->m_name);
@ -235,7 +238,7 @@ void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other)
}
else
{
for (const WonkoVersionPtr &version : list->m_versions)
for (const VersionPtr &version : list->m_versions)
{
if (m_lookup.contains(version->version()))
{
@ -264,20 +267,22 @@ void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other)
}
}
void WonkoVersionList::setupAddedVersion(const int row, const WonkoVersionPtr &version)
void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
{
connect(version.get(), &WonkoVersion::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
connect(version.get(), &WonkoVersion::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TimeRole << SortRole); });
connect(version.get(), &WonkoVersion::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
connect(version.get(), &Version::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
connect(version.get(), &Version::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TimeRole << SortRole); });
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
}
BaseVersionPtr WonkoVersionList::getLatestStable() const
BaseVersionPtr VersionList::getLatestStable() const
{
return m_latest;
}
BaseVersionPtr WonkoVersionList::getRecommended() const
BaseVersionPtr VersionList::getRecommended() const
{
return m_recommended;
}
#include "WonkoVersionList.moc"
}
#include "VersionList.moc"

View File

@ -16,26 +16,28 @@
#pragma once
#include "BaseVersionList.h"
#include "BaseWonkoEntity.h"
#include "BaseEntity.h"
#include <memory>
using WonkoVersionPtr = std::shared_ptr<class WonkoVersion>;
using WonkoVersionListPtr = std::shared_ptr<class WonkoVersionList>;
namespace Meta
{
using VersionPtr = std::shared_ptr<class Version>;
using VersionListPtr = std::shared_ptr<class VersionList>;
class MULTIMC_LOGIC_EXPORT WonkoVersionList : public BaseVersionList, public BaseWonkoEntity
class MULTIMC_LOGIC_EXPORT VersionList : public BaseVersionList, public BaseEntity
{
Q_OBJECT
Q_PROPERTY(QString uid READ uid CONSTANT)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
public:
explicit WonkoVersionList(const QString &uid, QObject *parent = nullptr);
explicit VersionList(const QString &uid, QObject *parent = nullptr);
enum Roles
{
UidRole = Qt::UserRole + 100,
TimeRole,
RequiresRole,
WonkoVersionPtrRole
VersionPtrRole
};
Task *getLoadTask() override;
@ -62,31 +64,32 @@ public:
QString humanReadable() const;
bool hasVersion(const QString &version) const;
WonkoVersionPtr getVersion(const QString &version) const;
VersionPtr getVersion(const QString &version) const;
QVector<WonkoVersionPtr> versions() const { return m_versions; }
QVector<VersionPtr> versions() const { return m_versions; }
public: // for usage only by parsers
void setName(const QString &name);
void setVersions(const QVector<WonkoVersionPtr> &versions);
void merge(const BaseWonkoEntity::Ptr &other);
void setVersions(const QVector<VersionPtr> &versions);
void merge(const BaseEntity::Ptr &other) override;
signals:
void nameChanged(const QString &name);
protected slots:
void updateListData(QList<BaseVersionPtr> versions) override {}
void updateListData(QList<BaseVersionPtr>) override {}
private:
QVector<WonkoVersionPtr> m_versions;
QHash<QString, WonkoVersionPtr> m_lookup;
QVector<VersionPtr> m_versions;
QHash<QString, VersionPtr> m_lookup;
QString m_uid;
QString m_name;
WonkoVersionPtr m_recommended;
WonkoVersionPtr m_latest;
VersionPtr m_recommended;
VersionPtr m_latest;
void setupAddedVersion(const int row, const WonkoVersionPtr &version);
void setupAddedVersion(const int row, const VersionPtr &version);
};
Q_DECLARE_METATYPE(WonkoVersionListPtr)
}
Q_DECLARE_METATYPE(Meta::VersionListPtr)

View File

@ -0,0 +1,84 @@
/* 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 "FormatV1.h"
#include "meta/Index.h"
#include "meta/Version.h"
#include "meta/VersionList.h"
namespace Meta
{
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 Format::parseIndex(const QJsonObject &obj, Index *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 1:
ptr->merge(FormatV1().parseIndexInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
void Format::parseVersion(const QJsonObject &obj, Version *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 1:
ptr->merge(FormatV1().parseVersionInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 10:
ptr->merge(FormatV1().parseVersionListInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
QJsonObject Format::serializeIndex(const Index *ptr)
{
return FormatV1().serializeIndexInternal(ptr);
}
QJsonObject Format::serializeVersion(const Version *ptr)
{
return FormatV1().serializeVersionInternal(ptr);
}
QJsonObject Format::serializeVersionList(const VersionList *ptr)
{
return FormatV1().serializeVersionListInternal(ptr);
}
}

View File

@ -0,0 +1,57 @@
/* 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 <QJsonObject>
#include <memory>
#include "Exception.h"
#include "meta/BaseEntity.h"
namespace Meta
{
class Index;
class Version;
class VersionList;
class ParseException : public Exception
{
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);
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;
};
}

View File

@ -13,31 +13,33 @@
* limitations under the License.
*/
#include "WonkoFormatV1.h"
#include "FormatV1.h"
#include <minecraft/onesix/OneSixVersionFormat.h>
#include "Json.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersion.h"
#include "wonko/WonkoVersionList.h"
#include "meta/Index.h"
#include "meta/Version.h"
#include "meta/VersionList.h"
#include "Env.h"
using namespace Json;
static WonkoVersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
namespace Meta
{
static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
{
const QVector<QJsonObject> requiresRaw = obj.contains("requires") ? requireIsArrayOf<QJsonObject>(obj, "requires") : QVector<QJsonObject>();
QVector<WonkoReference> requires;
QVector<Reference> requires;
requires.reserve(requiresRaw.size());
std::transform(requiresRaw.begin(), requiresRaw.end(), std::back_inserter(requires), [](const QJsonObject &rObj)
{
WonkoReference ref(requireString(rObj, "uid"));
Reference ref(requireString(rObj, "uid"));
ref.setVersion(ensureString(rObj, "version", QString()));
return ref;
});
WonkoVersionPtr version = std::make_shared<WonkoVersion>(uid, requireString(obj, "version"));
VersionPtr version = std::make_shared<Version>(uid, requireString(obj, "version"));
if (obj.value("time").isString())
{
version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
@ -50,10 +52,10 @@ static WonkoVersionPtr parseCommonVersion(const QString &uid, const QJsonObject
version->setRequires(requires);
return version;
}
static void serializeCommonVersion(const WonkoVersion *version, QJsonObject &obj)
static void serializeCommonVersion(const Version *version, QJsonObject &obj)
{
QJsonArray requires;
for (const WonkoReference &ref : version->requires())
for (const Reference &ref : version->requires())
{
if (ref.version().isEmpty())
{
@ -76,48 +78,48 @@ static void serializeCommonVersion(const WonkoVersion *version, QJsonObject &obj
obj.insert("requires", requires);
}
BaseWonkoEntity::Ptr WonkoFormatV1::parseIndexInternal(const QJsonObject &obj) const
BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const
{
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "index");
QVector<WonkoVersionListPtr> lists;
QVector<VersionListPtr> lists;
lists.reserve(objects.size());
std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj)
{
WonkoVersionListPtr list = std::make_shared<WonkoVersionList>(requireString(obj, "uid"));
VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid"));
list->setName(ensureString(obj, "name", QString()));
return list;
});
return std::make_shared<WonkoIndex>(lists);
return std::make_shared<Index>(lists);
}
BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionInternal(const QJsonObject &obj) const
BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const
{
WonkoVersionPtr version = parseCommonVersion(requireString(obj, "uid"), 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;
}
BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionListInternal(const QJsonObject &obj) const
BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const
{
const QString uid = requireString(obj, "uid");
const QVector<QJsonObject> versionsRaw = requireIsArrayOf<QJsonObject>(obj, "versions");
QVector<WonkoVersionPtr> versions;
QVector<VersionPtr> versions;
versions.reserve(versionsRaw.size());
std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [this, uid](const QJsonObject &vObj)
{ return parseCommonVersion(uid, vObj); });
WonkoVersionListPtr list = std::make_shared<WonkoVersionList>(uid);
VersionListPtr list = std::make_shared<VersionList>(uid);
list->setName(ensureString(obj, "name", QString()));
list->setVersions(versions);
return list;
}
QJsonObject WonkoFormatV1::serializeIndexInternal(const WonkoIndex *ptr) const
QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const
{
QJsonArray index;
for (const WonkoVersionListPtr &list : ptr->lists())
for (const VersionListPtr &list : ptr->lists())
{
QJsonObject out;
out["uid"] = list->uid();
@ -129,21 +131,21 @@ QJsonObject WonkoFormatV1::serializeIndexInternal(const WonkoIndex *ptr) const
out["index"] = index;
return out;
}
QJsonObject WonkoFormatV1::serializeVersionInternal(const WonkoVersion *ptr) const
QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const
{
QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object();
serializeCommonVersion(ptr, obj);
obj.insert("formatVersion", 1);
obj.insert("uid", ptr->uid());
// TODO: the name should be looked up in the UI based on the uid
obj.insert("name", ENV.wonkoIndex()->getListGuaranteed(ptr->uid())->name());
obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name());
return obj;
}
QJsonObject WonkoFormatV1::serializeVersionListInternal(const WonkoVersionList *ptr) const
QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const
{
QJsonArray versions;
for (const WonkoVersionPtr &version : ptr->versions())
for (const VersionPtr &version : ptr->versions())
{
QJsonObject obj;
serializeCommonVersion(version.get(), obj);
@ -156,3 +158,4 @@ QJsonObject WonkoFormatV1::serializeVersionListInternal(const WonkoVersionList *
out["versions"] = versions;
return out;
}
}

View File

@ -15,16 +15,19 @@
#pragma once
#include "WonkoFormat.h"
#include "Format.h"
class WonkoFormatV1 : public WonkoFormat
namespace Meta
{
class FormatV1 : public Format
{
public:
BaseWonkoEntity::Ptr parseIndexInternal(const QJsonObject &obj) const override;
BaseWonkoEntity::Ptr parseVersionInternal(const QJsonObject &obj) const override;
BaseWonkoEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const override;
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 WonkoIndex *ptr) const override;
QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const override;
QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const override;
QJsonObject serializeIndexInternal(const Index *ptr) const override;
QJsonObject serializeVersionInternal(const Version *ptr) const override;
QJsonObject serializeVersionListInternal(const VersionList *ptr) const override;
};
}

View File

@ -0,0 +1,123 @@
/* 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 <QFile>
#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(filename());
if (!QFile::exists(fname))
{
emitFailed(tr("File doesn't exist"));
return;
}
setStatus(tr("Reading %1...").arg(name()));
setProgress(0, 0);
try
{
parse(Json::requireObject(Json::requireDocument(fname, name()), name()));
m_entity->notifyLocalLoadComplete();
emitSucceeded();
}
catch (Exception &e)
{
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<Index *>(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<VersionList *>(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<Version *>(entity());
}
}

View File

@ -18,64 +18,67 @@
#include "tasks/Task.h"
#include <memory>
class BaseWonkoEntity;
class WonkoIndex;
class WonkoVersionList;
class WonkoVersion;
namespace Meta
{
class BaseEntity;
class Index;
class VersionList;
class Version;
class BaseWonkoEntityLocalLoadTask : public Task
class LocalLoadTask : public Task
{
Q_OBJECT
public:
explicit BaseWonkoEntityLocalLoadTask(BaseWonkoEntity *entity, QObject *parent = nullptr);
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;
BaseWonkoEntity *entity() const { return m_entity; }
BaseEntity *entity() const { return m_entity; }
private:
void executeTask() override;
BaseWonkoEntity *m_entity;
BaseEntity *m_entity;
};
class WonkoIndexLocalLoadTask : public BaseWonkoEntityLocalLoadTask
class IndexLocalLoadTask : public LocalLoadTask
{
Q_OBJECT
public:
explicit WonkoIndexLocalLoadTask(WonkoIndex *index, QObject *parent = nullptr);
explicit IndexLocalLoadTask(Index *index, QObject *parent = nullptr);
private:
QString filename() const override;
QString name() const override;
void parse(const QJsonObject &obj) const override;
};
class WonkoVersionListLocalLoadTask : public BaseWonkoEntityLocalLoadTask
class VersionListLocalLoadTask : public LocalLoadTask
{
Q_OBJECT
public:
explicit WonkoVersionListLocalLoadTask(WonkoVersionList *list, QObject *parent = nullptr);
explicit VersionListLocalLoadTask(VersionList *list, QObject *parent = nullptr);
private:
QString filename() const override;
QString name() const override;
void parse(const QJsonObject &obj) const override;
WonkoVersionList *list() const;
VersionList *list() const;
};
class WonkoVersionLocalLoadTask : public BaseWonkoEntityLocalLoadTask
class VersionLocalLoadTask : public LocalLoadTask
{
Q_OBJECT
public:
explicit WonkoVersionLocalLoadTask(WonkoVersion *version, QObject *parent = nullptr);
explicit VersionLocalLoadTask(Version *version, QObject *parent = nullptr);
private:
QString filename() const override;
QString name() const override;
void parse(const QJsonObject &obj) const override;
WonkoVersion *version() const;
Version *version() const;
};
}

View File

@ -0,0 +1,132 @@
/* 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)
{
}
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()
{
setStatus(tr("Parsing..."));
setProgress(0, 0);
try
{
parse(Json::requireObject(Json::requireDocument(m_dl->getTargetFilepath(), name()), name()));
m_entity->notifyRemoteLoadComplete();
emitSucceeded();
}
catch (Exception &e)
{
emitFailed(tr("Unable to parse response: %1").arg(e.cause()));
}
}
// 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<Index *>(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
{
return dynamic_cast<VersionList *>(entity());
}
// 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<Version *>(entity());
}
}

View File

@ -20,26 +20,28 @@
namespace Net
{
class Download;
class Download;
}
class BaseWonkoEntity;
class WonkoIndex;
class WonkoVersionList;
class WonkoVersion;
namespace Meta
{
class BaseEntity;
class Index;
class VersionList;
class Version;
class BaseWonkoEntityRemoteLoadTask : public Task
class RemoteLoadTask : public Task
{
Q_OBJECT
public:
explicit BaseWonkoEntityRemoteLoadTask(BaseWonkoEntity *entity, QObject *parent = nullptr);
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;
BaseWonkoEntity *entity() const { return m_entity; }
BaseEntity *entity() const { return m_entity; }
private slots:
void networkFinished();
@ -47,44 +49,47 @@ private slots:
private:
void executeTask() override;
BaseWonkoEntity *m_entity;
BaseEntity *m_entity;
std::shared_ptr<Net::Download> m_dl;
};
class WonkoIndexRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask
class IndexRemoteLoadTask : public RemoteLoadTask
{
Q_OBJECT
public:
explicit WonkoIndexRemoteLoadTask(WonkoIndex *index, QObject *parent = nullptr);
explicit IndexRemoteLoadTask(Index *index, QObject *parent = nullptr);
private:
QUrl url() const override;
QString name() const override;
void parse(const QJsonObject &obj) const override;
};
class WonkoVersionListRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask
class VersionListRemoteLoadTask : public RemoteLoadTask
{
Q_OBJECT
public:
explicit WonkoVersionListRemoteLoadTask(WonkoVersionList *list, QObject *parent = nullptr);
explicit VersionListRemoteLoadTask(VersionList *list, QObject *parent = nullptr);
private:
QUrl url() const override;
QString name() const override;
void parse(const QJsonObject &obj) const override;
WonkoVersionList *list() const;
VersionList *list() const;
};
class WonkoVersionRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask
class VersionRemoteLoadTask : public RemoteLoadTask
{
Q_OBJECT
public:
explicit WonkoVersionRemoteLoadTask(WonkoVersion *version, QObject *parent = nullptr);
explicit VersionRemoteLoadTask(Version *version, QObject *parent = nullptr);
private:
QUrl url() const override;
QString name() const override;
void parse(const QJsonObject &obj) const override;
WonkoVersion *version() const;
Version *version() const;
};
}

View File

@ -1,50 +0,0 @@
#include <QTest>
#include "TestUtil.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersionList.h"
#include "Env.h"
class WonkoIndexTest : public QObject
{
Q_OBJECT
private
slots:
void test_isProvidedByEnv()
{
QVERIFY(ENV.wonkoIndex());
QCOMPARE(ENV.wonkoIndex(), ENV.wonkoIndex());
}
void test_providesTasks()
{
QVERIFY(ENV.wonkoIndex()->localUpdateTask() != nullptr);
QVERIFY(ENV.wonkoIndex()->remoteUpdateTask() != nullptr);
}
void test_hasUid_and_getList()
{
WonkoIndex windex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("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);
}
void test_merge()
{
WonkoIndex windex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")});
QCOMPARE(windex.lists().size(), 3);
windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")})));
QCOMPARE(windex.lists().size(), 3);
windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list4"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list5")})));
QCOMPARE(windex.lists().size(), 5);
windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list6")})));
QCOMPARE(windex.lists().size(), 6);
}
};
QTEST_GUILESS_MAIN(WonkoIndexTest)
#include "WonkoIndex_test.moc"

View File

@ -1,80 +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 "WonkoFormat.h"
#include "WonkoFormatV1.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersion.h"
#include "wonko/WonkoVersionList.h"
static int formatVersion(const QJsonObject &obj)
{
if (!obj.contains("formatVersion")) {
throw WonkoParseException(QObject::tr("Missing required field: 'formatVersion'"));
}
if (!obj.value("formatVersion").isDouble()) {
throw WonkoParseException(QObject::tr("Required field has invalid type: 'formatVersion'"));
}
return obj.value("formatVersion").toInt();
}
void WonkoFormat::parseIndex(const QJsonObject &obj, WonkoIndex *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 1:
ptr->merge(WonkoFormatV1().parseIndexInternal(obj));
break;
default:
throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
void WonkoFormat::parseVersion(const QJsonObject &obj, WonkoVersion *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 1:
ptr->merge(WonkoFormatV1().parseVersionInternal(obj));
break;
default:
throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
void WonkoFormat::parseVersionList(const QJsonObject &obj, WonkoVersionList *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 10:
ptr->merge(WonkoFormatV1().parseVersionListInternal(obj));
break;
default:
throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
QJsonObject WonkoFormat::serializeIndex(const WonkoIndex *ptr)
{
return WonkoFormatV1().serializeIndexInternal(ptr);
}
QJsonObject WonkoFormat::serializeVersion(const WonkoVersion *ptr)
{
return WonkoFormatV1().serializeVersionInternal(ptr);
}
QJsonObject WonkoFormat::serializeVersionList(const WonkoVersionList *ptr)
{
return WonkoFormatV1().serializeVersionListInternal(ptr);
}

View File

@ -1,54 +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 <QJsonObject>
#include <memory>
#include "Exception.h"
#include "wonko/BaseWonkoEntity.h"
class WonkoIndex;
class WonkoVersion;
class WonkoVersionList;
class WonkoParseException : public Exception
{
public:
using Exception::Exception;
};
class WonkoFormat
{
public:
virtual ~WonkoFormat() {}
static void parseIndex(const QJsonObject &obj, WonkoIndex *ptr);
static void parseVersion(const QJsonObject &obj, WonkoVersion *ptr);
static void parseVersionList(const QJsonObject &obj, WonkoVersionList *ptr);
static QJsonObject serializeIndex(const WonkoIndex *ptr);
static QJsonObject serializeVersion(const WonkoVersion *ptr);
static QJsonObject serializeVersionList(const WonkoVersionList *ptr);
protected:
virtual BaseWonkoEntity::Ptr parseIndexInternal(const QJsonObject &obj) const = 0;
virtual BaseWonkoEntity::Ptr parseVersionInternal(const QJsonObject &obj) const = 0;
virtual BaseWonkoEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const = 0;
virtual QJsonObject serializeIndexInternal(const WonkoIndex *ptr) const = 0;
virtual QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const = 0;
virtual QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const = 0;
};

View File

@ -1,117 +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 "BaseWonkoEntityLocalLoadTask.h"
#include <QFile>
#include "wonko/format/WonkoFormat.h"
#include "wonko/WonkoUtil.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersion.h"
#include "wonko/WonkoVersionList.h"
#include "Env.h"
#include "Json.h"
BaseWonkoEntityLocalLoadTask::BaseWonkoEntityLocalLoadTask(BaseWonkoEntity *entity, QObject *parent)
: Task(parent), m_entity(entity)
{
}
void BaseWonkoEntityLocalLoadTask::executeTask()
{
const QString fname = Wonko::localWonkoDir().absoluteFilePath(filename());
if (!QFile::exists(fname))
{
emitFailed(tr("File doesn't exist"));
return;
}
setStatus(tr("Reading %1...").arg(name()));
setProgress(0, 0);
try
{
parse(Json::requireObject(Json::requireDocument(fname, name()), name()));
m_entity->notifyLocalLoadComplete();
emitSucceeded();
}
catch (Exception &e)
{
emitFailed(tr("Unable to parse file %1: %2").arg(fname, e.cause()));
}
}
// WONKO INDEX //
WonkoIndexLocalLoadTask::WonkoIndexLocalLoadTask(WonkoIndex *index, QObject *parent)
: BaseWonkoEntityLocalLoadTask(index, parent)
{
}
QString WonkoIndexLocalLoadTask::filename() const
{
return "index.json";
}
QString WonkoIndexLocalLoadTask::name() const
{
return tr("Wonko Index");
}
void WonkoIndexLocalLoadTask::parse(const QJsonObject &obj) const
{
WonkoFormat::parseIndex(obj, dynamic_cast<WonkoIndex *>(entity()));
}
// WONKO VERSION LIST //
WonkoVersionListLocalLoadTask::WonkoVersionListLocalLoadTask(WonkoVersionList *list, QObject *parent)
: BaseWonkoEntityLocalLoadTask(list, parent)
{
}
QString WonkoVersionListLocalLoadTask::filename() const
{
return list()->uid() + ".json";
}
QString WonkoVersionListLocalLoadTask::name() const
{
return tr("Wonko Version List for %1").arg(list()->humanReadable());
}
void WonkoVersionListLocalLoadTask::parse(const QJsonObject &obj) const
{
WonkoFormat::parseVersionList(obj, list());
}
WonkoVersionList *WonkoVersionListLocalLoadTask::list() const
{
return dynamic_cast<WonkoVersionList *>(entity());
}
// WONKO VERSION //
WonkoVersionLocalLoadTask::WonkoVersionLocalLoadTask(WonkoVersion *version, QObject *parent)
: BaseWonkoEntityLocalLoadTask(version, parent)
{
}
QString WonkoVersionLocalLoadTask::filename() const
{
return version()->uid() + "/" + version()->version() + ".json";
}
QString WonkoVersionLocalLoadTask::name() const
{
return tr("Wonko Version for %1").arg(version()->name());
}
void WonkoVersionLocalLoadTask::parse(const QJsonObject &obj) const
{
WonkoFormat::parseVersion(obj, version());
}
WonkoVersion *WonkoVersionLocalLoadTask::version() const
{
return dynamic_cast<WonkoVersion *>(entity());
}

View File

@ -1,126 +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 "BaseWonkoEntityRemoteLoadTask.h"
#include "net/Download.h"
#include "net/HttpMetaCache.h"
#include "net/NetJob.h"
#include "wonko/format/WonkoFormat.h"
#include "wonko/WonkoUtil.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersion.h"
#include "wonko/WonkoVersionList.h"
#include "Env.h"
#include "Json.h"
BaseWonkoEntityRemoteLoadTask::BaseWonkoEntityRemoteLoadTask(BaseWonkoEntity *entity, QObject *parent)
: Task(parent), m_entity(entity)
{
}
void BaseWonkoEntityRemoteLoadTask::executeTask()
{
NetJob *job = new NetJob(name());
auto entry = ENV.metacache()->resolveEntry("wonko", url().toString());
entry->setStale(true);
m_dl = Net::Download::makeCached(url(), entry);
job->addNetAction(m_dl);
connect(job, &NetJob::failed, this, &BaseWonkoEntityRemoteLoadTask::emitFailed);
connect(job, &NetJob::succeeded, this, &BaseWonkoEntityRemoteLoadTask::networkFinished);
connect(job, &NetJob::status, this, &BaseWonkoEntityRemoteLoadTask::setStatus);
connect(job, &NetJob::progress, this, &BaseWonkoEntityRemoteLoadTask::setProgress);
job->start();
}
void BaseWonkoEntityRemoteLoadTask::networkFinished()
{
setStatus(tr("Parsing..."));
setProgress(0, 0);
try
{
parse(Json::requireObject(Json::requireDocument(m_dl->getTargetFilepath(), name()), name()));
m_entity->notifyRemoteLoadComplete();
emitSucceeded();
}
catch (Exception &e)
{
emitFailed(tr("Unable to parse response: %1").arg(e.cause()));
}
}
// WONKO INDEX //
WonkoIndexRemoteLoadTask::WonkoIndexRemoteLoadTask(WonkoIndex *index, QObject *parent)
: BaseWonkoEntityRemoteLoadTask(index, parent)
{
}
QUrl WonkoIndexRemoteLoadTask::url() const
{
return Wonko::indexUrl();
}
QString WonkoIndexRemoteLoadTask::name() const
{
return tr("Wonko Index");
}
void WonkoIndexRemoteLoadTask::parse(const QJsonObject &obj) const
{
WonkoFormat::parseIndex(obj, dynamic_cast<WonkoIndex *>(entity()));
}
// WONKO VERSION LIST //
WonkoVersionListRemoteLoadTask::WonkoVersionListRemoteLoadTask(WonkoVersionList *list, QObject *parent)
: BaseWonkoEntityRemoteLoadTask(list, parent)
{
}
QUrl WonkoVersionListRemoteLoadTask::url() const
{
return Wonko::versionListUrl(list()->uid());
}
QString WonkoVersionListRemoteLoadTask::name() const
{
return tr("Wonko Version List for %1").arg(list()->humanReadable());
}
void WonkoVersionListRemoteLoadTask::parse(const QJsonObject &obj) const
{
WonkoFormat::parseVersionList(obj, list());
}
WonkoVersionList *WonkoVersionListRemoteLoadTask::list() const
{
return dynamic_cast<WonkoVersionList *>(entity());
}
// WONKO VERSION //
WonkoVersionRemoteLoadTask::WonkoVersionRemoteLoadTask(WonkoVersion *version, QObject *parent)
: BaseWonkoEntityRemoteLoadTask(version, parent)
{
}
QUrl WonkoVersionRemoteLoadTask::url() const
{
return Wonko::versionUrl(version()->uid(), version()->version());
}
QString WonkoVersionRemoteLoadTask::name() const
{
return tr("Wonko Version for %1").arg(version()->name());
}
void WonkoVersionRemoteLoadTask::parse(const QJsonObject &obj) const
{
WonkoFormat::parseVersion(obj, version());
}
WonkoVersion *WonkoVersionRemoteLoadTask::version() const
{
return dynamic_cast<WonkoVersion *>(entity());
}

View File

@ -33,7 +33,6 @@ Config::Config()
VERSION_STR = "@MultiMC_VERSION_STRING@";
NEWS_RSS_URL = "@MultiMC_NEWS_RSS_URL@";
PASTE_EE_KEY = "@MultiMC_PASTE_EE_API_KEY@";
WONKO_ROOT_URL = "@MultiMC_WONKO_ROOT_URL@";
}
QString Config::printableVersionString() const

View File

@ -60,11 +60,6 @@ public:
*/
QString PASTE_EE_KEY;
/**
* Root URL for wonko things. Other wonko URLs will be resolved relative to this.
*/
QString WONKO_ROOT_URL;
/**
* \brief Converts the Version to a string.
* \return The version number in string format (major.minor.revision.build).

View File

@ -30,9 +30,6 @@ set(MultiMC_ANALYTICS_ID "" CACHE STRING "ID you can get from Google analytics")
include(GetGitRevisionDescription)
get_git_head_revision(MultiMC_GIT_REFSPEC MultiMC_GIT_COMMIT)
# Root URL for wonko files
set(MultiMC_WONKO_ROOT_URL "" CACHE STRING "Root URL for wonko stuff")
message(STATUS "Git commit: ${MultiMC_GIT_COMMIT}")
message(STATUS "Git refspec: ${MultiMC_GIT_REFSPEC}")
@ -99,8 +96,6 @@ SET(MULTIMC_SOURCES
VersionProxyModel.cpp
ColorCache.h
ColorCache.cpp
WonkoGui.h
WonkoGui.cpp
# GUI - windows
MainWindow.h
@ -189,8 +184,8 @@ SET(MULTIMC_SOURCES
pages/global/ProxyPage.h
pages/global/PasteEEPage.cpp
pages/global/PasteEEPage.h
pages/global/WonkoPage.cpp
pages/global/WonkoPage.h
pages/global/MetadataPage.cpp
pages/global/MetadataPage.h
# GUI - dialogs
dialogs/AboutDialog.cpp
@ -289,7 +284,7 @@ SET(MULTIMC_UIS
pages/global/MultiMCPage.ui
pages/global/ProxyPage.ui
pages/global/PasteEEPage.ui
pages/global/WonkoPage.ui
pages/global/MetadataPage.ui
# Dialogs
dialogs/CopyInstanceDialog.ui

View File

@ -1,74 +0,0 @@
#include "WonkoGui.h"
#include "dialogs/ProgressDialog.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersionList.h"
#include "wonko/WonkoVersion.h"
#include "Env.h"
WonkoIndexPtr Wonko::ensureIndexLoaded(QWidget *parent)
{
if (!ENV.wonkoIndex()->isLocalLoaded())
{
ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->localUpdateTask());
if (!ENV.wonkoIndex()->isRemoteLoaded() && ENV.wonkoIndex()->lists().size() == 0)
{
ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->remoteUpdateTask());
}
}
return ENV.wonkoIndex();
}
WonkoVersionListPtr Wonko::ensureVersionListExists(const QString &uid, QWidget *parent)
{
ensureIndexLoaded(parent);
if (!ENV.wonkoIndex()->isRemoteLoaded() && !ENV.wonkoIndex()->hasUid(uid))
{
ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->remoteUpdateTask());
}
return ENV.wonkoIndex()->getList(uid);
}
WonkoVersionListPtr Wonko::ensureVersionListLoaded(const QString &uid, QWidget *parent)
{
WonkoVersionListPtr list = ensureVersionListExists(uid, parent);
if (!list)
{
return nullptr;
}
if (!list->isLocalLoaded())
{
ProgressDialog(parent).execWithTask(list->localUpdateTask());
if (!list->isLocalLoaded())
{
ProgressDialog(parent).execWithTask(list->remoteUpdateTask());
}
}
return list->isComplete() ? list : nullptr;
}
WonkoVersionPtr Wonko::ensureVersionExists(const QString &uid, const QString &version, QWidget *parent)
{
WonkoVersionListPtr list = ensureVersionListLoaded(uid, parent);
if (!list)
{
return nullptr;
}
return list->getVersion(version);
}
WonkoVersionPtr Wonko::ensureVersionLoaded(const QString &uid, const QString &version, QWidget *parent, const UpdateType update)
{
WonkoVersionPtr vptr = ensureVersionExists(uid, version, parent);
if (!vptr)
{
return nullptr;
}
if (!vptr->isLocalLoaded() || update == AlwaysUpdate)
{
ProgressDialog(parent).execWithTask(vptr->localUpdateTask());
if (!vptr->isLocalLoaded() || update == AlwaysUpdate)
{
ProgressDialog(parent).execWithTask(vptr->remoteUpdateTask());
}
}
return vptr->isComplete() ? vptr : nullptr;
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <memory>
#include "QObjectPtr.h"
class QWidget;
class QString;
using WonkoIndexPtr = shared_qobject_ptr<class WonkoIndex>;
using WonkoVersionListPtr = std::shared_ptr<class WonkoVersionList>;
using WonkoVersionPtr = std::shared_ptr<class WonkoVersion>;
namespace Wonko
{
enum UpdateType
{
AlwaysUpdate,
UpdateIfNeeded
};
/// Ensures that the index has been loaded, either from the local cache or remotely
WonkoIndexPtr ensureIndexLoaded(QWidget *parent);
/// Ensures that the given uid exists. Returns a nullptr if it doesn't.
WonkoVersionListPtr ensureVersionListExists(const QString &uid, QWidget *parent);
/// Ensures that the given uid exists and is loaded, either from the local cache or remotely. Returns nullptr if it doesn't exist or couldn't be loaded.
WonkoVersionListPtr ensureVersionListLoaded(const QString &uid, QWidget *parent);
WonkoVersionPtr ensureVersionExists(const QString &uid, const QString &version, QWidget *parent);
WonkoVersionPtr ensureVersionLoaded(const QString &uid, const QString &version, QWidget *parent, const UpdateType update = UpdateIfNeeded);
}

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#include "WonkoPage.h"
#include "ui_WonkoPage.h"
#include "MetadataPage.h"
#include "ui_MetadataPage.h"
#include <QDateTime>
#include <QSortFilterProxyModel>
@ -23,18 +23,20 @@
#include "dialogs/ProgressDialog.h"
#include "VersionProxyModel.h"
#include "wonko/WonkoIndex.h"
#include "wonko/WonkoVersionList.h"
#include "wonko/WonkoVersion.h"
#include "meta/Index.h"
#include "meta/VersionList.h"
#include "meta/Version.h"
#include "Env.h"
#include "MultiMC.h"
static QString formatRequires(const WonkoVersionPtr &version)
using namespace Meta;
static QString formatRequires(const VersionPtr &version)
{
QStringList lines;
for (const WonkoReference &ref : version->requires())
for (const Reference &ref : version->requires())
{
const QString readable = ENV.wonkoIndex()->hasUid(ref.uid()) ? ENV.wonkoIndex()->getList(ref.uid())->humanReadable() : ref.uid();
const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->getList(ref.uid())->humanReadable() : ref.uid();
if (ref.version().isEmpty())
{
lines.append(readable);
@ -47,9 +49,9 @@ static QString formatRequires(const WonkoVersionPtr &version)
return lines.join('\n');
}
WonkoPage::WonkoPage(QWidget *parent) :
MetadataPage::MetadataPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::WonkoPage)
ui(new Ui::MetadataPage)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
@ -61,11 +63,11 @@ WonkoPage::WonkoPage(QWidget *parent) :
m_fileProxy->setFilterRole(Qt::DisplayRole);
m_fileProxy->setFilterKeyColumn(0);
m_fileProxy->sort(0);
m_fileProxy->setSourceModel(ENV.wonkoIndex().get());
m_fileProxy->setSourceModel(ENV.metadataIndex().get());
ui->indexView->setModel(m_fileProxy);
m_filterProxy = new QSortFilterProxyModel(this);
m_filterProxy->setSortRole(WonkoVersionList::SortRole);
m_filterProxy->setSortRole(VersionList::SortRole);
m_filterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_filterProxy->setFilterRole(Qt::DisplayRole);
m_filterProxy->setFilterKeyColumn(0);
@ -75,40 +77,40 @@ WonkoPage::WonkoPage(QWidget *parent) :
m_versionProxy = new VersionProxyModel(this);
m_filterProxy->setSourceModel(m_versionProxy);
connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WonkoPage::updateCurrentVersionList);
connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WonkoPage::updateVersion);
connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &WonkoPage::versionListDataChanged);
connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateCurrentVersionList);
connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateVersion);
connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &MetadataPage::versionListDataChanged);
updateCurrentVersionList(QModelIndex());
updateVersion();
}
WonkoPage::~WonkoPage()
MetadataPage::~MetadataPage()
{
delete ui;
}
QIcon WonkoPage::icon() const
QIcon MetadataPage::icon() const
{
return MMC->getThemedIcon("looney");
}
void WonkoPage::on_refreshIndexBtn_clicked()
void MetadataPage::on_refreshIndexBtn_clicked()
{
ProgressDialog(this).execWithTask(ENV.wonkoIndex()->remoteUpdateTask());
ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask());
}
void WonkoPage::on_refreshFileBtn_clicked()
void MetadataPage::on_refreshFileBtn_clicked()
{
WonkoVersionListPtr list = ui->indexView->currentIndex().data(WonkoIndex::ListPtrRole).value<WonkoVersionListPtr>();
VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value<VersionListPtr>();
if (!list)
{
return;
}
ProgressDialog(this).execWithTask(list->remoteUpdateTask());
}
void WonkoPage::on_refreshVersionBtn_clicked()
void MetadataPage::on_refreshVersionBtn_clicked()
{
WonkoVersionPtr version = ui->versionsView->currentIndex().data(WonkoVersionList::WonkoVersionPtrRole).value<WonkoVersionPtr>();
VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value<VersionPtr>();
if (!version)
{
return;
@ -116,7 +118,7 @@ void WonkoPage::on_refreshVersionBtn_clicked()
ProgressDialog(this).execWithTask(version->remoteUpdateTask());
}
void WonkoPage::on_fileSearchEdit_textChanged(const QString &search)
void MetadataPage::on_fileSearchEdit_textChanged(const QString &search)
{
if (search.isEmpty())
{
@ -129,7 +131,7 @@ void WonkoPage::on_fileSearchEdit_textChanged(const QString &search)
m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*");
}
}
void WonkoPage::on_versionSearchEdit_textChanged(const QString &search)
void MetadataPage::on_versionSearchEdit_textChanged(const QString &search)
{
if (search.isEmpty())
{
@ -143,11 +145,11 @@ void WonkoPage::on_versionSearchEdit_textChanged(const QString &search)
}
}
void WonkoPage::updateCurrentVersionList(const QModelIndex &index)
void MetadataPage::updateCurrentVersionList(const QModelIndex &index)
{
if (index.isValid())
{
WonkoVersionListPtr list = index.data(WonkoIndex::ListPtrRole).value<WonkoVersionListPtr>();
VersionListPtr list = index.data(Index::ListPtrRole).value<VersionListPtr>();
ui->versionsBox->setEnabled(true);
ui->refreshFileBtn->setEnabled(true);
ui->fileUidLabel->setEnabled(true);
@ -183,7 +185,7 @@ void WonkoPage::updateCurrentVersionList(const QModelIndex &index)
}
}
void WonkoPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br)
void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br)
{
if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex()))
{
@ -191,10 +193,10 @@ void WonkoPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex
}
}
void WonkoPage::updateVersion()
void MetadataPage::updateVersion()
{
WonkoVersionPtr version = std::dynamic_pointer_cast<WonkoVersion>(
ui->versionsView->currentIndex().data(WonkoVersionList::VersionPointerRole).value<BaseVersionPtr>());
VersionPtr version = std::dynamic_pointer_cast<Version>(
ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>());
if (version)
{
ui->refreshVersionBtn->setEnabled(true);
@ -223,16 +225,16 @@ void WonkoPage::updateVersion()
}
}
void WonkoPage::opened()
void MetadataPage::opened()
{
if (!ENV.wonkoIndex()->isLocalLoaded())
if (!ENV.metadataIndex()->isLocalLoaded())
{
std::unique_ptr<Task> task = ENV.wonkoIndex()->localUpdateTask();
std::unique_ptr<Task> task = ENV.metadataIndex()->localUpdateTask();
connect(task.get(), &Task::finished, this, [this]()
{
if (!ENV.wonkoIndex()->isRemoteLoaded())
if (!ENV.metadataIndex()->isRemoteLoaded())
{
ProgressDialog(this).execWithTask(ENV.wonkoIndex()->remoteUpdateTask());
ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask());
}
});
ProgressDialog(this).execWithTask(task);

View File

@ -20,21 +20,21 @@
#include "pages/BasePage.h"
namespace Ui {
class WonkoPage;
class MetadataPage;
}
class QSortFilterProxyModel;
class VersionProxyModel;
class WonkoPage : public QWidget, public BasePage
class MetadataPage : public QWidget, public BasePage
{
Q_OBJECT
public:
explicit WonkoPage(QWidget *parent = 0);
~WonkoPage();
explicit MetadataPage(QWidget *parent = 0);
~MetadataPage();
QString id() const override { return "wonko-global"; }
QString displayName() const override { return tr("Wonko"); }
QString id() const override { return "metadata-global"; }
QString displayName() const override { return tr("Metadata"); }
QIcon icon() const override;
void opened() override;
@ -48,7 +48,7 @@ private slots:
void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br);
private:
Ui::WonkoPage *ui;
Ui::MetadataPage *ui;
QSortFilterProxyModel *m_fileProxy;
QSortFilterProxyModel *m_filterProxy;
VersionProxyModel *m_versionProxy;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WonkoPage</class>
<widget class="QWidget" name="WonkoPage">
<class>MetadataPage</class>
<widget class="QWidget" name="MetadataPage">
<property name="geometry">
<rect>
<x>0</x>