diff options
-rw-r--r-- | api/logic/meta/Util.cpp | 2 | ||||
-rw-r--r-- | api/logic/meta/VersionList.cpp | 2 | ||||
-rw-r--r-- | api/logic/meta/format/Format.cpp | 28 | ||||
-rw-r--r-- | api/logic/meta/format/FormatV1.cpp | 119 | ||||
-rw-r--r-- | application/CMakeLists.txt | 6 | ||||
-rw-r--r-- | application/MultiMC.cpp | 2 | ||||
-rw-r--r-- | application/VersionProxyModel.cpp | 2 | ||||
-rw-r--r-- | application/pages/global/PackagesPage.cpp (renamed from application/pages/global/MetadataPage.cpp) | 42 | ||||
-rw-r--r-- | application/pages/global/PackagesPage.h (renamed from application/pages/global/MetadataPage.h) | 14 | ||||
-rw-r--r-- | application/pages/global/PackagesPage.ui (renamed from application/pages/global/MetadataPage.ui) | 12 |
10 files changed, 123 insertions, 106 deletions
diff --git a/api/logic/meta/Util.cpp b/api/logic/meta/Util.cpp index 2ccbe5c4..76941f83 100644 --- a/api/logic/meta/Util.cpp +++ b/api/logic/meta/Util.cpp @@ -34,7 +34,7 @@ QUrl indexUrl() QUrl versionListUrl(const QString &uid) { - return rootUrl().resolved(uid + ".json"); + return rootUrl().resolved(uid + "/index.json"); } QUrl versionUrl(const QString &uid, const QString &version) diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 11e20c12..aab3e0f7 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -178,7 +178,7 @@ std::unique_ptr<Task> VersionList::localUpdateTask() QString VersionList::localFilename() const { - return m_uid + ".json"; + return m_uid + "/index.json"; } QJsonObject VersionList::serialized() const { diff --git a/api/logic/meta/format/Format.cpp b/api/logic/meta/format/Format.cpp index a3f9f730..e0fddb0b 100644 --- a/api/logic/meta/format/Format.cpp +++ b/api/logic/meta/format/Format.cpp @@ -39,46 +39,52 @@ void Format::parseIndex(const QJsonObject &obj, Index *ptr) { const int version = formatVersion(obj); switch (version) { - case 1: + case 0: ptr->merge(FormatV1().parseIndexInternal(obj)); break; default: throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); } } -void Format::parseVersion(const QJsonObject &obj, Version *ptr) + +void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr) { const int version = formatVersion(obj); switch (version) { - case 1: - ptr->merge(FormatV1().parseVersionInternal(obj)); + case 0: + ptr->merge(FormatV1().parseVersionListInternal(obj)); break; default: throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); } } -void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr) + +void Format::parseVersion(const QJsonObject &obj, Version *ptr) { const int version = formatVersion(obj); switch (version) { - case 10: - ptr->merge(FormatV1().parseVersionListInternal(obj)); + case 0: + ptr->merge(FormatV1().parseVersionInternal(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); } + +QJsonObject Format::serializeVersion(const Version *ptr) +{ + return FormatV1().serializeVersionInternal(ptr); +} + } diff --git a/api/logic/meta/format/FormatV1.cpp b/api/logic/meta/format/FormatV1.cpp index 23f57100..ee2c5291 100644 --- a/api/logic/meta/format/FormatV1.cpp +++ b/api/logic/meta/format/FormatV1.cpp @@ -27,6 +27,44 @@ using namespace Json; namespace Meta { + +static const int currentFormatVersion = 0; + +// Index + +BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const +{ + const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages"); + QVector<VersionListPtr> lists; + lists.reserve(objects.size()); + std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) + { + VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid")); + list->setName(ensureString(obj, "name", QString())); + return list; + }); + return std::make_shared<Index>(lists); +} + +QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const +{ + QJsonArray packages; + for (const VersionListPtr &list : ptr->lists()) + { + QJsonObject out; + out["uid"] = list->uid(); + out["name"] = list->name(); + packages.append(out); + } + QJsonObject out; + out["formatVersion"] = currentFormatVersion; + out["packages"] = packages; + return out; +} + + +// Version + static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) { const QVector<QJsonObject> requiresRaw = obj.contains("requires") ? requireIsArrayOf<QJsonObject>(obj, "requires") : QVector<QJsonObject>(); @@ -40,18 +78,22 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) }); 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); - } - else - { - version->setTime(requireInteger(obj, "time")); - } + version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000); version->setType(ensureString(obj, "type", QString())); version->setRequires(requires); return version; } + +BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const +{ + 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; +} + static void serializeCommonVersion(const Version *version, QJsonObject &obj) { QJsonArray requires; @@ -74,32 +116,25 @@ static void serializeCommonVersion(const Version *version, QJsonObject &obj) obj.insert("version", version->version()); obj.insert("type", version->type()); - obj.insert("time", version->time().toString(Qt::ISODate)); + obj.insert("releaseTime", version->time().toString(Qt::ISODate)); obj.insert("requires", requires); } -BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const -{ - const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "index"); - QVector<VersionListPtr> lists; - lists.reserve(objects.size()); - std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) - { - VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid")); - list->setName(ensureString(obj, "name", QString())); - return list; - }); - return std::make_shared<Index>(lists); -} -BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const +QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const { - VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); + QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); + serializeCommonVersion(ptr, obj); + obj.insert("formatVersion", currentFormatVersion); + obj.insert("uid", ptr->uid()); + // TODO: the name should be looked up in the UI based on the uid + obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name()); - version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), - QString("%1/%2.json").arg(version->uid(), version->version()), - obj.contains("order"))); - return version; + return obj; } + + +// Version list / package + BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const { const QString uid = requireString(obj, "uid"); @@ -116,32 +151,6 @@ BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const return list; } -QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const -{ - QJsonArray index; - for (const VersionListPtr &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 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.metadataIndex()->getListGuaranteed(ptr->uid())->name()); - - return obj; -} QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const { QJsonArray versions; @@ -152,7 +161,7 @@ QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const versions.append(obj); } QJsonObject out; - out["formatVersion"] = 10; + out["formatVersion"] = currentFormatVersion; out["uid"] = ptr->uid(); out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name(); out["versions"] = versions; diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 55457b1c..1b6ff3fd 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -184,8 +184,8 @@ SET(MULTIMC_SOURCES pages/global/ProxyPage.h pages/global/PasteEEPage.cpp pages/global/PasteEEPage.h - pages/global/MetadataPage.cpp - pages/global/MetadataPage.h + pages/global/PackagesPage.cpp + pages/global/PackagesPage.h # GUI - dialogs dialogs/AboutDialog.cpp @@ -284,7 +284,7 @@ SET(MULTIMC_UIS pages/global/MultiMCPage.ui pages/global/ProxyPage.ui pages/global/PasteEEPage.ui - pages/global/MetadataPage.ui + pages/global/PackagesPage.ui # Dialogs dialogs/CopyInstanceDialog.ui diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 081de41c..3a91fb5f 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -10,6 +10,7 @@ #include "pages/global/ExternalToolsPage.h" #include "pages/global/AccountListPage.h" #include "pages/global/PasteEEPage.h" +#include "pages/global/PackagesPage.h" #include "themes/ITheme.h" #include "themes/SystemTheme.h" @@ -842,6 +843,7 @@ void MultiMC::initGlobalSettings() m_globalSettingsProvider->addPage<MinecraftPage>(); m_globalSettingsProvider->addPage<JavaPage>(); m_globalSettingsProvider->addPage<ProxyPage>(); + m_globalSettingsProvider->addPage<PackagesPage>(); m_globalSettingsProvider->addPage<ExternalToolsPage>(); m_globalSettingsProvider->addPage<AccountListPage>(); m_globalSettingsProvider->addPage<PasteEEPage>(); diff --git a/application/VersionProxyModel.cpp b/application/VersionProxyModel.cpp index 22df7e09..50b94d9e 100644 --- a/application/VersionProxyModel.cpp +++ b/application/VersionProxyModel.cpp @@ -313,9 +313,9 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel *replacingRaw) auto replacing = dynamic_cast<BaseVersionList *>(replacingRaw); beginResetModel(); + m_columns.clear(); if(!replacing) { - m_columns.clear(); roles.clear(); filterModel->setSourceModel(replacing); return; diff --git a/application/pages/global/MetadataPage.cpp b/application/pages/global/PackagesPage.cpp index 4e355997..52efaf9a 100644 --- a/application/pages/global/MetadataPage.cpp +++ b/application/pages/global/PackagesPage.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "MetadataPage.h" -#include "ui_MetadataPage.h" +#include "PackagesPage.h" +#include "ui_PackagesPage.h" #include <QDateTime> #include <QSortFilterProxyModel> @@ -49,9 +49,9 @@ static QString formatRequires(const VersionPtr &version) return lines.join('\n'); } -MetadataPage::MetadataPage(QWidget *parent) : +PackagesPage::PackagesPage(QWidget *parent) : QWidget(parent), - ui(new Ui::MetadataPage) + ui(new Ui::PackagesPage) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -77,29 +77,29 @@ MetadataPage::MetadataPage(QWidget *parent) : m_versionProxy = new VersionProxyModel(this); m_filterProxy->setSourceModel(m_versionProxy); - 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); + connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateCurrentVersionList); + connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateVersion); + connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &PackagesPage::versionListDataChanged); updateCurrentVersionList(QModelIndex()); updateVersion(); } -MetadataPage::~MetadataPage() +PackagesPage::~PackagesPage() { delete ui; } -QIcon MetadataPage::icon() const +QIcon PackagesPage::icon() const { - return MMC->getThemedIcon("looney"); + return MMC->getThemedIcon("packages"); } -void MetadataPage::on_refreshIndexBtn_clicked() +void PackagesPage::on_refreshIndexBtn_clicked() { ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); } -void MetadataPage::on_refreshFileBtn_clicked() +void PackagesPage::on_refreshFileBtn_clicked() { VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value<VersionListPtr>(); if (!list) @@ -108,7 +108,7 @@ void MetadataPage::on_refreshFileBtn_clicked() } ProgressDialog(this).execWithTask(list->remoteUpdateTask()); } -void MetadataPage::on_refreshVersionBtn_clicked() +void PackagesPage::on_refreshVersionBtn_clicked() { VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value<VersionPtr>(); if (!version) @@ -118,7 +118,7 @@ void MetadataPage::on_refreshVersionBtn_clicked() ProgressDialog(this).execWithTask(version->remoteUpdateTask()); } -void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) +void PackagesPage::on_fileSearchEdit_textChanged(const QString &search) { if (search.isEmpty()) { @@ -131,7 +131,7 @@ void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); } } -void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) +void PackagesPage::on_versionSearchEdit_textChanged(const QString &search) { if (search.isEmpty()) { @@ -145,7 +145,7 @@ void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) } } -void MetadataPage::updateCurrentVersionList(const QModelIndex &index) +void PackagesPage::updateCurrentVersionList(const QModelIndex &index) { if (index.isValid()) { @@ -181,11 +181,11 @@ void MetadataPage::updateCurrentVersionList(const QModelIndex &index) ui->fileNameLabel->setEnabled(false); ui->fileName->clear(); m_versionProxy->setSourceModel(nullptr); - ui->refreshFileBtn->setText(tr("Refresh ___")); + ui->refreshFileBtn->setText(tr("Refresh")); } } -void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) +void PackagesPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) { if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex())) { @@ -193,7 +193,7 @@ void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelInd } } -void MetadataPage::updateVersion() +void PackagesPage::updateVersion() { VersionPtr version = std::dynamic_pointer_cast<Version>( ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>()); @@ -221,11 +221,11 @@ void MetadataPage::updateVersion() ui->versionType->clear(); ui->versionRequiresLabel->setEnabled(false); ui->versionRequires->clear(); - ui->refreshVersionBtn->setText(tr("Refresh ___")); + ui->refreshVersionBtn->setText(tr("Refresh")); } } -void MetadataPage::opened() +void PackagesPage::opened() { if (!ENV.metadataIndex()->isLocalLoaded()) { diff --git a/application/pages/global/MetadataPage.h b/application/pages/global/PackagesPage.h index f75b4952..80c2886d 100644 --- a/application/pages/global/MetadataPage.h +++ b/application/pages/global/PackagesPage.h @@ -20,21 +20,21 @@ #include "pages/BasePage.h" namespace Ui { -class MetadataPage; +class PackagesPage; } class QSortFilterProxyModel; class VersionProxyModel; -class MetadataPage : public QWidget, public BasePage +class PackagesPage : public QWidget, public BasePage { Q_OBJECT public: - explicit MetadataPage(QWidget *parent = 0); - ~MetadataPage(); + explicit PackagesPage(QWidget *parent = 0); + ~PackagesPage(); - QString id() const override { return "metadata-global"; } - QString displayName() const override { return tr("Metadata"); } + QString id() const override { return "packages-global"; } + QString displayName() const override { return tr("Packages"); } QIcon icon() const override; void opened() override; @@ -48,7 +48,7 @@ private slots: void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br); private: - Ui::MetadataPage *ui; + Ui::PackagesPage *ui; QSortFilterProxyModel *m_fileProxy; QSortFilterProxyModel *m_filterProxy; VersionProxyModel *m_versionProxy; diff --git a/application/pages/global/MetadataPage.ui b/application/pages/global/PackagesPage.ui index 0bd33f32..158bf1b4 100644 --- a/application/pages/global/MetadataPage.ui +++ b/application/pages/global/PackagesPage.ui @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>MetadataPage</class> - <widget class="QWidget" name="MetadataPage"> + <class>PackagesPage</class> + <widget class="QWidget" name="PackagesPage"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>640</width> - <height>480</height> + <width>636</width> + <height>621</height> </rect> </property> <property name="windowTitle"> @@ -67,7 +67,7 @@ <item> <widget class="QPushButton" name="refreshVersionBtn"> <property name="text"> - <string>Refresh ___</string> + <string>Refresh</string> </property> </widget> </item> @@ -180,7 +180,7 @@ <item> <widget class="QPushButton" name="refreshFileBtn"> <property name="text"> - <string>Refresh ___</string> + <string>Refresh</string> </property> </widget> </item> |