From ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 11 Mar 2017 01:39:45 +0100 Subject: NOISSUE Wonko is the new Meta And then Wonko was the Meta. --- api/logic/wonko/BaseWonkoEntity.cpp | 39 --- api/logic/wonko/BaseWonkoEntity.h | 51 ---- api/logic/wonko/WonkoIndex.cpp | 147 ----------- api/logic/wonko/WonkoIndex.h | 68 ----- api/logic/wonko/WonkoIndex_test.cpp | 50 ---- api/logic/wonko/WonkoReference.cpp | 44 ---- api/logic/wonko/WonkoReference.h | 41 --- api/logic/wonko/WonkoUtil.cpp | 47 ---- api/logic/wonko/WonkoUtil.h | 31 --- api/logic/wonko/WonkoVersion.cpp | 102 -------- api/logic/wonko/WonkoVersion.h | 83 ------ api/logic/wonko/WonkoVersionList.cpp | 283 --------------------- api/logic/wonko/WonkoVersionList.h | 92 ------- api/logic/wonko/format/WonkoFormat.cpp | 80 ------ api/logic/wonko/format/WonkoFormat.h | 54 ---- api/logic/wonko/format/WonkoFormatV1.cpp | 158 ------------ api/logic/wonko/format/WonkoFormatV1.h | 30 --- .../wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp | 117 --------- .../wonko/tasks/BaseWonkoEntityLocalLoadTask.h | 81 ------ .../wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp | 126 --------- .../wonko/tasks/BaseWonkoEntityRemoteLoadTask.h | 90 ------- 21 files changed, 1814 deletions(-) delete mode 100644 api/logic/wonko/BaseWonkoEntity.cpp delete mode 100644 api/logic/wonko/BaseWonkoEntity.h delete mode 100644 api/logic/wonko/WonkoIndex.cpp delete mode 100644 api/logic/wonko/WonkoIndex.h delete mode 100644 api/logic/wonko/WonkoIndex_test.cpp delete mode 100644 api/logic/wonko/WonkoReference.cpp delete mode 100644 api/logic/wonko/WonkoReference.h delete mode 100644 api/logic/wonko/WonkoUtil.cpp delete mode 100644 api/logic/wonko/WonkoUtil.h delete mode 100644 api/logic/wonko/WonkoVersion.cpp delete mode 100644 api/logic/wonko/WonkoVersion.h delete mode 100644 api/logic/wonko/WonkoVersionList.cpp delete mode 100644 api/logic/wonko/WonkoVersionList.h delete mode 100644 api/logic/wonko/format/WonkoFormat.cpp delete mode 100644 api/logic/wonko/format/WonkoFormat.h delete mode 100644 api/logic/wonko/format/WonkoFormatV1.cpp delete mode 100644 api/logic/wonko/format/WonkoFormatV1.h delete mode 100644 api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp delete mode 100644 api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h delete mode 100644 api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp delete mode 100644 api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h (limited to 'api/logic/wonko') diff --git a/api/logic/wonko/BaseWonkoEntity.cpp b/api/logic/wonko/BaseWonkoEntity.cpp deleted file mode 100644 index e6a0e41e..00000000 --- a/api/logic/wonko/BaseWonkoEntity.cpp +++ /dev/null @@ -1,39 +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 "BaseWonkoEntity.h" - -#include "Json.h" -#include "WonkoUtil.h" - -BaseWonkoEntity::~BaseWonkoEntity() -{ -} - -void BaseWonkoEntity::store() const -{ - Json::write(serialized(), Wonko::localWonkoDir().absoluteFilePath(localFilename())); -} - -void BaseWonkoEntity::notifyLocalLoadComplete() -{ - m_localLoaded = true; - store(); -} -void BaseWonkoEntity::notifyRemoteLoadComplete() -{ - m_remoteLoaded = true; - store(); -} diff --git a/api/logic/wonko/BaseWonkoEntity.h b/api/logic/wonko/BaseWonkoEntity.h deleted file mode 100644 index c6e8c832..00000000 --- a/api/logic/wonko/BaseWonkoEntity.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "multimc_logic_export.h" - -class Task; - -class MULTIMC_LOGIC_EXPORT BaseWonkoEntity -{ -public: - virtual ~BaseWonkoEntity(); - - using Ptr = std::shared_ptr; - - virtual std::unique_ptr remoteUpdateTask() = 0; - virtual std::unique_ptr localUpdateTask() = 0; - virtual void merge(const std::shared_ptr &other) = 0; - - void store() const; - virtual QString localFilename() const = 0; - virtual QJsonObject serialized() const = 0; - - bool isComplete() const { return m_localLoaded || m_remoteLoaded; } - - bool isLocalLoaded() const { return m_localLoaded; } - bool isRemoteLoaded() const { return m_remoteLoaded; } - - void notifyLocalLoadComplete(); - void notifyRemoteLoadComplete(); - -private: - bool m_localLoaded = false; - bool m_remoteLoaded = false; -}; diff --git a/api/logic/wonko/WonkoIndex.cpp b/api/logic/wonko/WonkoIndex.cpp deleted file mode 100644 index f6ad201a..00000000 --- a/api/logic/wonko/WonkoIndex.cpp +++ /dev/null @@ -1,147 +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 "WonkoIndex.h" - -#include "WonkoVersionList.h" -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "format/WonkoFormat.h" - -WonkoIndex::WonkoIndex(QObject *parent) - : QAbstractListModel(parent) -{ -} -WonkoIndex::WonkoIndex(const QVector &lists, QObject *parent) - : QAbstractListModel(parent), m_lists(lists) -{ - for (int i = 0; i < m_lists.size(); ++i) - { - m_uids.insert(m_lists.at(i)->uid(), m_lists.at(i)); - connectVersionList(i, m_lists.at(i)); - } -} - -QVariant WonkoIndex::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()); - switch (role) - { - case Qt::DisplayRole: - switch (index.column()) - { - case 0: return list->humanReadable(); - default: break; - } - case UidRole: return list->uid(); - case NameRole: return list->name(); - case ListPtrRole: return QVariant::fromValue(list); - } - return QVariant(); -} -int WonkoIndex::rowCount(const QModelIndex &parent) const -{ - return m_lists.size(); -} -int WonkoIndex::columnCount(const QModelIndex &parent) const -{ - return 1; -} -QVariant WonkoIndex::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) - { - return tr("Name"); - } - else - { - return QVariant(); - } -} - -std::unique_ptr WonkoIndex::remoteUpdateTask() -{ - return std::unique_ptr(new WonkoIndexRemoteLoadTask(this, this)); -} -std::unique_ptr WonkoIndex::localUpdateTask() -{ - return std::unique_ptr(new WonkoIndexLocalLoadTask(this, this)); -} - -QJsonObject WonkoIndex::serialized() const -{ - return WonkoFormat::serializeIndex(this); -} - -bool WonkoIndex::hasUid(const QString &uid) const -{ - return m_uids.contains(uid); -} -WonkoVersionListPtr WonkoIndex::getList(const QString &uid) const -{ - return m_uids.value(uid, nullptr); -} -WonkoVersionListPtr WonkoIndex::getListGuaranteed(const QString &uid) const -{ - return m_uids.value(uid, std::make_shared(uid)); -} - -void WonkoIndex::merge(const Ptr &other) -{ - const QVector lists = std::dynamic_pointer_cast(other)->m_lists; - // initial load, no need to merge - if (m_lists.isEmpty()) - { - beginResetModel(); - m_lists = lists; - for (int i = 0; i < lists.size(); ++i) - { - m_uids.insert(lists.at(i)->uid(), lists.at(i)); - connectVersionList(i, lists.at(i)); - } - endResetModel(); - } - else - { - for (const WonkoVersionListPtr &list : lists) - { - if (m_uids.contains(list->uid())) - { - m_uids[list->uid()]->merge(list); - } - else - { - beginInsertRows(QModelIndex(), m_lists.size(), m_lists.size()); - connectVersionList(m_lists.size(), list); - m_lists.append(list); - m_uids.insert(list->uid(), list); - endInsertRows(); - } - } - } -} - -void WonkoIndex::connectVersionList(const int row, const WonkoVersionListPtr &list) -{ - connect(list.get(), &WonkoVersionList::nameChanged, this, [this, row]() - { - emit dataChanged(index(row), index(row), QVector() << Qt::DisplayRole); - }); -} diff --git a/api/logic/wonko/WonkoIndex.h b/api/logic/wonko/WonkoIndex.h deleted file mode 100644 index fe07c3ef..00000000 --- a/api/logic/wonko/WonkoIndex.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "BaseWonkoEntity.h" - -#include "multimc_logic_export.h" - -class Task; -using WonkoVersionListPtr = std::shared_ptr; - -class MULTIMC_LOGIC_EXPORT WonkoIndex : public QAbstractListModel, public BaseWonkoEntity -{ - Q_OBJECT -public: - explicit WonkoIndex(QObject *parent = nullptr); - explicit WonkoIndex(const QVector &lists, QObject *parent = nullptr); - - enum - { - UidRole = Qt::UserRole, - NameRole, - ListPtrRole - }; - - QVariant data(const QModelIndex &index, int role) const override; - int rowCount(const QModelIndex &parent) const override; - int columnCount(const QModelIndex &parent) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - - std::unique_ptr remoteUpdateTask() override; - std::unique_ptr localUpdateTask() override; - - QString localFilename() const override { return "index.json"; } - QJsonObject serialized() const override; - - // queries - bool hasUid(const QString &uid) const; - WonkoVersionListPtr getList(const QString &uid) const; - WonkoVersionListPtr getListGuaranteed(const QString &uid) const; - - QVector lists() const { return m_lists; } - -public: // for usage by parsers only - void merge(const BaseWonkoEntity::Ptr &other); - -private: - QVector m_lists; - QHash m_uids; - - void connectVersionList(const int row, const WonkoVersionListPtr &list); -}; diff --git a/api/logic/wonko/WonkoIndex_test.cpp b/api/logic/wonko/WonkoIndex_test.cpp deleted file mode 100644 index d7b92f21..00000000 --- a/api/logic/wonko/WonkoIndex_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#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("list1"), std::make_shared("list2"), std::make_shared("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("list1"), std::make_shared("list2"), std::make_shared("list3")}); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr(new WonkoIndex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}))); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr(new WonkoIndex({std::make_shared("list4"), std::make_shared("list2"), std::make_shared("list5")}))); - QCOMPARE(windex.lists().size(), 5); - windex.merge(std::shared_ptr(new WonkoIndex({std::make_shared("list6")}))); - QCOMPARE(windex.lists().size(), 6); - } -}; - -QTEST_GUILESS_MAIN(WonkoIndexTest) - -#include "WonkoIndex_test.moc" diff --git a/api/logic/wonko/WonkoReference.cpp b/api/logic/wonko/WonkoReference.cpp deleted file mode 100644 index 7193e56e..00000000 --- a/api/logic/wonko/WonkoReference.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WonkoReference.h" - -WonkoReference::WonkoReference(const QString &uid) - : m_uid(uid) -{ -} - -QString WonkoReference::uid() const -{ - return m_uid; -} - -QString WonkoReference::version() const -{ - return m_version; -} -void WonkoReference::setVersion(const QString &version) -{ - m_version = version; -} - -bool WonkoReference::operator==(const WonkoReference &other) const -{ - return m_uid == other.m_uid && m_version == other.m_version; -} -bool WonkoReference::operator!=(const WonkoReference &other) const -{ - return m_uid != other.m_uid || m_version != other.m_version; -} diff --git a/api/logic/wonko/WonkoReference.h b/api/logic/wonko/WonkoReference.h deleted file mode 100644 index ba7427b3..00000000 --- a/api/logic/wonko/WonkoReference.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT WonkoReference -{ -public: - WonkoReference() {} - explicit WonkoReference(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; - -private: - QString m_uid; - QString m_version; -}; -Q_DECLARE_METATYPE(WonkoReference) diff --git a/api/logic/wonko/WonkoUtil.cpp b/api/logic/wonko/WonkoUtil.cpp deleted file mode 100644 index 3b8049c4..00000000 --- a/api/logic/wonko/WonkoUtil.cpp +++ /dev/null @@ -1,47 +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 "WonkoUtil.h" - -#include -#include - -#include "Env.h" - -namespace Wonko -{ -QUrl rootUrl() -{ - return ENV.wonkoRootUrl(); -} -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() -{ - return QDir("wonko"); -} - -} diff --git a/api/logic/wonko/WonkoUtil.h b/api/logic/wonko/WonkoUtil.h deleted file mode 100644 index fb58ba1f..00000000 --- a/api/logic/wonko/WonkoUtil.h +++ /dev/null @@ -1,31 +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 "multimc_logic_export.h" - -class QUrl; -class QString; -class QDir; - -namespace Wonko -{ -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(); -} diff --git a/api/logic/wonko/WonkoVersion.cpp b/api/logic/wonko/WonkoVersion.cpp deleted file mode 100644 index f5a063be..00000000 --- a/api/logic/wonko/WonkoVersion.cpp +++ /dev/null @@ -1,102 +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 "WonkoVersion.h" - -#include - -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "format/WonkoFormat.h" - -WonkoVersion::WonkoVersion(const QString &uid, const QString &version) - : BaseVersion(), m_uid(uid), m_version(version) -{ -} - -QString WonkoVersion::descriptor() -{ - return m_version; -} -QString WonkoVersion::name() -{ - return m_version; -} -QString WonkoVersion::typeString() const -{ - return m_type; -} - -QDateTime WonkoVersion::time() const -{ - return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC); -} - -std::unique_ptr WonkoVersion::remoteUpdateTask() -{ - return std::unique_ptr(new WonkoVersionRemoteLoadTask(this, this)); -} -std::unique_ptr WonkoVersion::localUpdateTask() -{ - return std::unique_ptr(new WonkoVersionLocalLoadTask(this, this)); -} - -void WonkoVersion::merge(const std::shared_ptr &other) -{ - WonkoVersionPtr version = std::dynamic_pointer_cast(other); - if (m_type != version->m_type) - { - setType(version->m_type); - } - if (m_time != version->m_time) - { - setTime(version->m_time); - } - if (m_requires != version->m_requires) - { - setRequires(version->m_requires); - } - - setData(version->m_data); -} - -QString WonkoVersion::localFilename() const -{ - return m_uid + '/' + m_version + ".json"; -} -QJsonObject WonkoVersion::serialized() const -{ - return WonkoFormat::serializeVersion(this); -} - -void WonkoVersion::setType(const QString &type) -{ - m_type = type; - emit typeChanged(); -} -void WonkoVersion::setTime(const qint64 time) -{ - m_time = time; - emit timeChanged(); -} -void WonkoVersion::setRequires(const QVector &requires) -{ - m_requires = requires; - emit requiresChanged(); -} -void WonkoVersion::setData(const VersionFilePtr &data) -{ - m_data = data; -} diff --git a/api/logic/wonko/WonkoVersion.h b/api/logic/wonko/WonkoVersion.h deleted file mode 100644 index 397ff14e..00000000 --- a/api/logic/wonko/WonkoVersion.h +++ /dev/null @@ -1,83 +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 "BaseVersion.h" -#include "BaseWonkoEntity.h" - -#include -#include -#include -#include - -#include "minecraft/VersionFile.h" -#include "WonkoReference.h" - -#include "multimc_logic_export.h" - -using WonkoVersionPtr = std::shared_ptr; - -class MULTIMC_LOGIC_EXPORT WonkoVersion : public QObject, public BaseVersion, public BaseWonkoEntity -{ - 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 requires READ requires NOTIFY requiresChanged) -public: - explicit WonkoVersion(const QString &uid, const QString &version); - - QString descriptor() override; - QString name() override; - QString typeString() const override; - - QString uid() const { return m_uid; } - QString version() const { return m_version; } - QString type() const { return m_type; } - QDateTime time() const; - qint64 rawTime() const { return m_time; } - QVector requires() const { return m_requires; } - VersionFilePtr data() const { return m_data; } - - std::unique_ptr remoteUpdateTask() override; - std::unique_ptr localUpdateTask() override; - void merge(const std::shared_ptr &other) override; - - QString localFilename() const override; - QJsonObject serialized() const override; - -public: // for usage by format parsers only - void setType(const QString &type); - void setTime(const qint64 time); - void setRequires(const QVector &requires); - void setData(const VersionFilePtr &data); - -signals: - void typeChanged(); - void timeChanged(); - void requiresChanged(); - -private: - QString m_uid; - QString m_version; - QString m_type; - qint64 m_time; - QVector m_requires; - VersionFilePtr m_data; -}; - -Q_DECLARE_METATYPE(WonkoVersionPtr) diff --git a/api/logic/wonko/WonkoVersionList.cpp b/api/logic/wonko/WonkoVersionList.cpp deleted file mode 100644 index 191e00f9..00000000 --- a/api/logic/wonko/WonkoVersionList.cpp +++ /dev/null @@ -1,283 +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 "WonkoVersionList.h" - -#include - -#include "WonkoVersion.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "format/WonkoFormat.h" -#include "WonkoReference.h" - -class WVLLoadTask : public Task -{ - Q_OBJECT -public: - explicit WVLLoadTask(WonkoVersionList *list, QObject *parent = nullptr) - : Task(parent), m_list(list) - { - } - - bool canAbort() const override - { - return !m_currentTask || m_currentTask->canAbort(); - } - bool abort() override - { - return m_currentTask->abort(); - } - -private: - void executeTask() override - { - if (!m_list->isLocalLoaded()) - { - m_currentTask = m_list->localUpdateTask(); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::next); - } - else - { - m_currentTask = m_list->remoteUpdateTask(); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::emitSucceeded); - } - connect(m_currentTask.get(), &Task::status, this, &WVLLoadTask::setStatus); - connect(m_currentTask.get(), &Task::progress, this, &WVLLoadTask::setProgress); - connect(m_currentTask.get(), &Task::failed, this, &WVLLoadTask::emitFailed); - m_currentTask->start(); - } - - void next() - { - m_currentTask = m_list->remoteUpdateTask(); - connect(m_currentTask.get(), &Task::status, this, &WVLLoadTask::setStatus); - connect(m_currentTask.get(), &Task::progress, this, &WVLLoadTask::setProgress); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::emitSucceeded); - m_currentTask->start(); - } - - WonkoVersionList *m_list; - std::unique_ptr m_currentTask; -}; - -WonkoVersionList::WonkoVersionList(const QString &uid, QObject *parent) - : BaseVersionList(parent), m_uid(uid) -{ - setObjectName("Wonko version list: " + uid); -} - -Task *WonkoVersionList::getLoadTask() -{ - return new WVLLoadTask(this); -} - -bool WonkoVersionList::isLoaded() -{ - return isLocalLoaded() && isRemoteLoaded(); -} - -const BaseVersionPtr WonkoVersionList::at(int i) const -{ - return m_versions.at(i); -} -int WonkoVersionList::count() const -{ - return m_versions.size(); -} - -void WonkoVersionList::sortVersions() -{ - beginResetModel(); - std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b) - { - return *a.get() < *b.get(); - }); - endResetModel(); -} - -QVariant WonkoVersionList::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()); - - switch (role) - { - case VersionPointerRole: return QVariant::fromValue(std::dynamic_pointer_cast(version)); - case VersionRole: - case VersionIdRole: - return version->version(); - case ParentGameVersionRole: - { - const auto end = version->requires().end(); - const auto it = std::find_if(version->requires().begin(), end, - [](const WonkoReference &ref) { return ref.uid() == "net.minecraft"; }); - if (it != end) - { - return (*it).version(); - } - return QVariant(); - } - case TypeRole: return version->type(); - - case UidRole: return version->uid(); - case TimeRole: return version->time(); - case RequiresRole: return QVariant::fromValue(version->requires()); - case SortRole: return version->rawTime(); - case WonkoVersionPtrRole: return QVariant::fromValue(version); - case RecommendedRole: return version == getRecommended(); - case LatestRole: return version == getLatestStable(); - default: return QVariant(); - } -} - -BaseVersionList::RoleList WonkoVersionList::providesRoles() const -{ - return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, - TypeRole, UidRole, TimeRole, RequiresRole, SortRole, - RecommendedRole, LatestRole, WonkoVersionPtrRole}; -} - -QHash WonkoVersionList::roleNames() const -{ - QHash roles = BaseVersionList::roleNames(); - roles.insert(UidRole, "uid"); - roles.insert(TimeRole, "time"); - roles.insert(SortRole, "sort"); - roles.insert(RequiresRole, "requires"); - return roles; -} - -std::unique_ptr WonkoVersionList::remoteUpdateTask() -{ - return std::unique_ptr(new WonkoVersionListRemoteLoadTask(this, this)); -} -std::unique_ptr WonkoVersionList::localUpdateTask() -{ - return std::unique_ptr(new WonkoVersionListLocalLoadTask(this, this)); -} - -QString WonkoVersionList::localFilename() const -{ - return m_uid + ".json"; -} -QJsonObject WonkoVersionList::serialized() const -{ - return WonkoFormat::serializeVersionList(this); -} - -QString WonkoVersionList::humanReadable() const -{ - return m_name.isEmpty() ? m_uid : m_name; -} - -bool WonkoVersionList::hasVersion(const QString &version) const -{ - return m_lookup.contains(version); -} -WonkoVersionPtr WonkoVersionList::getVersion(const QString &version) const -{ - return m_lookup.value(version); -} - -void WonkoVersionList::setName(const QString &name) -{ - m_name = name; - emit nameChanged(name); -} -void WonkoVersionList::setVersions(const QVector &versions) -{ - beginResetModel(); - m_versions = versions; - std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b) - { - return a->rawTime() > b->rawTime(); - }); - for (int i = 0; i < m_versions.size(); ++i) - { - m_lookup.insert(m_versions.at(i)->version(), m_versions.at(i)); - setupAddedVersion(i, m_versions.at(i)); - } - - 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"; }); - m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt; - endResetModel(); -} - -void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other) -{ - const WonkoVersionListPtr list = std::dynamic_pointer_cast(other); - if (m_name != list->m_name) - { - setName(list->m_name); - } - - if (m_versions.isEmpty()) - { - setVersions(list->m_versions); - } - else - { - for (const WonkoVersionPtr &version : list->m_versions) - { - if (m_lookup.contains(version->version())) - { - m_lookup.value(version->version())->merge(version); - } - else - { - beginInsertRows(QModelIndex(), m_versions.size(), m_versions.size()); - setupAddedVersion(m_versions.size(), version); - m_versions.append(version); - m_lookup.insert(version->uid(), version); - endInsertRows(); - - if (!m_latest || version->rawTime() > m_latest->rawTime()) - { - m_latest = version; - emit dataChanged(index(0), index(m_versions.size() - 1), QVector() << LatestRole); - } - if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime())) - { - m_recommended = version; - emit dataChanged(index(0), index(m_versions.size() - 1), QVector() << RecommendedRole); - } - } - } - } -} - -void WonkoVersionList::setupAddedVersion(const int row, const WonkoVersionPtr &version) -{ - connect(version.get(), &WonkoVersion::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << RequiresRole); }); - connect(version.get(), &WonkoVersion::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TimeRole << SortRole); }); - connect(version.get(), &WonkoVersion::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TypeRole); }); -} - -BaseVersionPtr WonkoVersionList::getLatestStable() const -{ - return m_latest; -} -BaseVersionPtr WonkoVersionList::getRecommended() const -{ - return m_recommended; -} - -#include "WonkoVersionList.moc" diff --git a/api/logic/wonko/WonkoVersionList.h b/api/logic/wonko/WonkoVersionList.h deleted file mode 100644 index 43cf73fc..00000000 --- a/api/logic/wonko/WonkoVersionList.h +++ /dev/null @@ -1,92 +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 "BaseVersionList.h" -#include "BaseWonkoEntity.h" -#include - -using WonkoVersionPtr = std::shared_ptr; -using WonkoVersionListPtr = std::shared_ptr; - -class MULTIMC_LOGIC_EXPORT WonkoVersionList : public BaseVersionList, public BaseWonkoEntity -{ - 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); - - enum Roles - { - UidRole = Qt::UserRole + 100, - TimeRole, - RequiresRole, - WonkoVersionPtrRole - }; - - Task *getLoadTask() override; - bool isLoaded() override; - const BaseVersionPtr at(int i) const override; - int count() const override; - void sortVersions() override; - - BaseVersionPtr getLatestStable() const override; - BaseVersionPtr getRecommended() const override; - - QVariant data(const QModelIndex &index, int role) const override; - RoleList providesRoles() const override; - QHash roleNames() const override; - - std::unique_ptr remoteUpdateTask() override; - std::unique_ptr localUpdateTask() override; - - QString localFilename() const override; - QJsonObject serialized() const override; - - QString uid() const { return m_uid; } - QString name() const { return m_name; } - QString humanReadable() const; - - bool hasVersion(const QString &version) const; - WonkoVersionPtr getVersion(const QString &version) const; - - QVector versions() const { return m_versions; } - -public: // for usage only by parsers - void setName(const QString &name); - void setVersions(const QVector &versions); - void merge(const BaseWonkoEntity::Ptr &other); - -signals: - void nameChanged(const QString &name); - -protected slots: - void updateListData(QList versions) override {} - -private: - QVector m_versions; - QHash m_lookup; - QString m_uid; - QString m_name; - - WonkoVersionPtr m_recommended; - WonkoVersionPtr m_latest; - - void setupAddedVersion(const int row, const WonkoVersionPtr &version); -}; - -Q_DECLARE_METATYPE(WonkoVersionListPtr) diff --git a/api/logic/wonko/format/WonkoFormat.cpp b/api/logic/wonko/format/WonkoFormat.cpp deleted file mode 100644 index a5d593ca..00000000 --- a/api/logic/wonko/format/WonkoFormat.cpp +++ /dev/null @@ -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); -} diff --git a/api/logic/wonko/format/WonkoFormat.h b/api/logic/wonko/format/WonkoFormat.h deleted file mode 100644 index 63ea9473..00000000 --- a/api/logic/wonko/format/WonkoFormat.h +++ /dev/null @@ -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 -#include - -#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; -}; diff --git a/api/logic/wonko/format/WonkoFormatV1.cpp b/api/logic/wonko/format/WonkoFormatV1.cpp deleted file mode 100644 index 4cecb42f..00000000 --- a/api/logic/wonko/format/WonkoFormatV1.cpp +++ /dev/null @@ -1,158 +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 "WonkoFormatV1.h" -#include - -#include "Json.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" -#include "Env.h" - -using namespace Json; - -static WonkoVersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) -{ - const QVector requiresRaw = obj.contains("requires") ? requireIsArrayOf(obj, "requires") : QVector(); - QVector requires; - requires.reserve(requiresRaw.size()); - std::transform(requiresRaw.begin(), requiresRaw.end(), std::back_inserter(requires), [](const QJsonObject &rObj) - { - WonkoReference ref(requireString(rObj, "uid")); - ref.setVersion(ensureString(rObj, "version", QString())); - return ref; - }); - - WonkoVersionPtr version = std::make_shared(uid, requireString(obj, "version")); - if (obj.value("time").isString()) - { - version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000); - } - else - { - version->setTime(requireInteger(obj, "time")); - } - version->setType(ensureString(obj, "type", QString())); - version->setRequires(requires); - return version; -} -static void serializeCommonVersion(const WonkoVersion *version, QJsonObject &obj) -{ - QJsonArray requires; - for (const WonkoReference &ref : version->requires()) - { - if (ref.version().isEmpty()) - { - QJsonObject out; - out["uid"] = ref.uid(); - requires.append(out); - } - else - { - QJsonObject out; - out["uid"] = ref.uid(); - out["version"] = ref.version(); - requires.append(out); - } - } - - obj.insert("version", version->version()); - obj.insert("type", version->type()); - obj.insert("time", version->time().toString(Qt::ISODate)); - obj.insert("requires", requires); -} - -BaseWonkoEntity::Ptr WonkoFormatV1::parseIndexInternal(const QJsonObject &obj) const -{ - const QVector objects = requireIsArrayOf(obj, "index"); - QVector lists; - lists.reserve(objects.size()); - std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) - { - WonkoVersionListPtr list = std::make_shared(requireString(obj, "uid")); - list->setName(ensureString(obj, "name", QString())); - return list; - }); - return std::make_shared(lists); -} -BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionInternal(const QJsonObject &obj) const -{ - WonkoVersionPtr 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 -{ - const QString uid = requireString(obj, "uid"); - - const QVector versionsRaw = requireIsArrayOf(obj, "versions"); - QVector 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(uid); - list->setName(ensureString(obj, "name", QString())); - list->setVersions(versions); - return list; -} - -QJsonObject WonkoFormatV1::serializeIndexInternal(const WonkoIndex *ptr) const -{ - QJsonArray index; - for (const WonkoVersionListPtr &list : ptr->lists()) - { - QJsonObject out; - out["uid"] = list->uid(); - out["version"] = list->name(); - index.append(out); - } - QJsonObject out; - out["formatVersion"] = 1; - out["index"] = index; - return out; -} -QJsonObject WonkoFormatV1::serializeVersionInternal(const WonkoVersion *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()); - - return obj; -} -QJsonObject WonkoFormatV1::serializeVersionListInternal(const WonkoVersionList *ptr) const -{ - QJsonArray versions; - for (const WonkoVersionPtr &version : ptr->versions()) - { - QJsonObject obj; - serializeCommonVersion(version.get(), obj); - versions.append(obj); - } - QJsonObject out; - out["formatVersion"] = 10; - out["uid"] = ptr->uid(); - out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name(); - out["versions"] = versions; - return out; -} diff --git a/api/logic/wonko/format/WonkoFormatV1.h b/api/logic/wonko/format/WonkoFormatV1.h deleted file mode 100644 index 2ae3acd1..00000000 --- a/api/logic/wonko/format/WonkoFormatV1.h +++ /dev/null @@ -1,30 +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 "WonkoFormat.h" - -class WonkoFormatV1 : public WonkoFormat -{ -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; - - QJsonObject serializeIndexInternal(const WonkoIndex *ptr) const override; - QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const override; - QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const override; -}; diff --git a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp b/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp deleted file mode 100644 index caffa744..00000000 --- a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp +++ /dev/null @@ -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 - -#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(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(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(entity()); -} diff --git a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h b/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h deleted file mode 100644 index a4f530c7..00000000 --- a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h +++ /dev/null @@ -1,81 +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 "tasks/Task.h" -#include - -class BaseWonkoEntity; -class WonkoIndex; -class WonkoVersionList; -class WonkoVersion; - -class BaseWonkoEntityLocalLoadTask : public Task -{ - Q_OBJECT -public: - explicit BaseWonkoEntityLocalLoadTask(BaseWonkoEntity *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; } - -private: - void executeTask() override; - - BaseWonkoEntity *m_entity; -}; - -class WonkoIndexLocalLoadTask : public BaseWonkoEntityLocalLoadTask -{ - Q_OBJECT -public: - explicit WonkoIndexLocalLoadTask(WonkoIndex *index, QObject *parent = nullptr); - -private: - QString filename() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; -}; -class WonkoVersionListLocalLoadTask : public BaseWonkoEntityLocalLoadTask -{ - Q_OBJECT -public: - explicit WonkoVersionListLocalLoadTask(WonkoVersionList *list, QObject *parent = nullptr); - -private: - QString filename() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - WonkoVersionList *list() const; -}; -class WonkoVersionLocalLoadTask : public BaseWonkoEntityLocalLoadTask -{ - Q_OBJECT -public: - explicit WonkoVersionLocalLoadTask(WonkoVersion *version, QObject *parent = nullptr); - -private: - QString filename() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - WonkoVersion *version() const; -}; diff --git a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp b/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp deleted file mode 100644 index 999d245b..00000000 --- a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp +++ /dev/null @@ -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(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(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(entity()); -} diff --git a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h b/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h deleted file mode 100644 index 0eab089a..00000000 --- a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h +++ /dev/null @@ -1,90 +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 "tasks/Task.h" -#include - -namespace Net -{ - class Download; -} - -class BaseWonkoEntity; -class WonkoIndex; -class WonkoVersionList; -class WonkoVersion; - -class BaseWonkoEntityRemoteLoadTask : public Task -{ - Q_OBJECT -public: - explicit BaseWonkoEntityRemoteLoadTask(BaseWonkoEntity *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; } - -private slots: - void networkFinished(); - -private: - void executeTask() override; - - BaseWonkoEntity *m_entity; - std::shared_ptr m_dl; -}; - -class WonkoIndexRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask -{ - Q_OBJECT -public: - explicit WonkoIndexRemoteLoadTask(WonkoIndex *index, QObject *parent = nullptr); - -private: - QUrl url() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; -}; -class WonkoVersionListRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask -{ - Q_OBJECT -public: - explicit WonkoVersionListRemoteLoadTask(WonkoVersionList *list, QObject *parent = nullptr); - -private: - QUrl url() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - WonkoVersionList *list() const; -}; -class WonkoVersionRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask -{ - Q_OBJECT -public: - explicit WonkoVersionRemoteLoadTask(WonkoVersion *version, QObject *parent = nullptr); - -private: - QUrl url() const override; - QString name() const override; - void parse(const QJsonObject &obj) const override; - - WonkoVersion *version() const; -}; -- cgit v1.2.3