NOISSUE fix downloading of metadata files

This commit is contained in:
Petr Mrázek 2017-03-12 16:00:06 +01:00
parent ab868df50e
commit 8321187a20
10 changed files with 129 additions and 112 deletions

View File

@ -34,7 +34,7 @@ QUrl indexUrl()
QUrl versionListUrl(const QString &uid) QUrl versionListUrl(const QString &uid)
{ {
return rootUrl().resolved(uid + ".json"); return rootUrl().resolved(uid + "/index.json");
} }
QUrl versionUrl(const QString &uid, const QString &version) QUrl versionUrl(const QString &uid, const QString &version)

View File

@ -178,7 +178,7 @@ std::unique_ptr<Task> VersionList::localUpdateTask()
QString VersionList::localFilename() const QString VersionList::localFilename() const
{ {
return m_uid + ".json"; return m_uid + "/index.json";
} }
QJsonObject VersionList::serialized() const QJsonObject VersionList::serialized() const
{ {

View File

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

View File

@ -27,6 +27,44 @@ using namespace Json;
namespace Meta 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) static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
{ {
const QVector<QJsonObject> requiresRaw = obj.contains("requires") ? requireIsArrayOf<QJsonObject>(obj, "requires") : QVector<QJsonObject>(); 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")); VersionPtr version = std::make_shared<Version>(uid, requireString(obj, "version"));
if (obj.value("time").isString()) version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
{
version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
}
else
{
version->setTime(requireInteger(obj, "time"));
}
version->setType(ensureString(obj, "type", QString())); version->setType(ensureString(obj, "type", QString()));
version->setRequires(requires); version->setRequires(requires);
return version; 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) static void serializeCommonVersion(const Version *version, QJsonObject &obj)
{ {
QJsonArray requires; QJsonArray requires;
@ -74,32 +116,25 @@ static void serializeCommonVersion(const Version *version, QJsonObject &obj)
obj.insert("version", version->version()); obj.insert("version", version->version());
obj.insert("type", version->type()); 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); obj.insert("requires", requires);
} }
BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const
{ {
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "index"); QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object();
QVector<VersionListPtr> lists; serializeCommonVersion(ptr, obj);
lists.reserve(objects.size()); obj.insert("formatVersion", currentFormatVersion);
std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) obj.insert("uid", ptr->uid());
{ // TODO: the name should be looked up in the UI based on the uid
VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid")); obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name());
list->setName(ensureString(obj, "name", QString()));
return list;
});
return std::make_shared<Index>(lists);
}
BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const
{
VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj);
version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), return obj;
QString("%1/%2.json").arg(version->uid(), version->version()),
obj.contains("order")));
return version;
} }
// Version list / package
BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const
{ {
const QString uid = requireString(obj, "uid"); const QString uid = requireString(obj, "uid");
@ -116,32 +151,6 @@ BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const
return list; 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 QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const
{ {
QJsonArray versions; QJsonArray versions;
@ -152,7 +161,7 @@ QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const
versions.append(obj); versions.append(obj);
} }
QJsonObject out; QJsonObject out;
out["formatVersion"] = 10; out["formatVersion"] = currentFormatVersion;
out["uid"] = ptr->uid(); out["uid"] = ptr->uid();
out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name(); out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name();
out["versions"] = versions; out["versions"] = versions;

View File

@ -184,8 +184,8 @@ SET(MULTIMC_SOURCES
pages/global/ProxyPage.h pages/global/ProxyPage.h
pages/global/PasteEEPage.cpp pages/global/PasteEEPage.cpp
pages/global/PasteEEPage.h pages/global/PasteEEPage.h
pages/global/MetadataPage.cpp pages/global/PackagesPage.cpp
pages/global/MetadataPage.h pages/global/PackagesPage.h
# GUI - dialogs # GUI - dialogs
dialogs/AboutDialog.cpp dialogs/AboutDialog.cpp
@ -284,7 +284,7 @@ SET(MULTIMC_UIS
pages/global/MultiMCPage.ui pages/global/MultiMCPage.ui
pages/global/ProxyPage.ui pages/global/ProxyPage.ui
pages/global/PasteEEPage.ui pages/global/PasteEEPage.ui
pages/global/MetadataPage.ui pages/global/PackagesPage.ui
# Dialogs # Dialogs
dialogs/CopyInstanceDialog.ui dialogs/CopyInstanceDialog.ui

View File

@ -10,6 +10,7 @@
#include "pages/global/ExternalToolsPage.h" #include "pages/global/ExternalToolsPage.h"
#include "pages/global/AccountListPage.h" #include "pages/global/AccountListPage.h"
#include "pages/global/PasteEEPage.h" #include "pages/global/PasteEEPage.h"
#include "pages/global/PackagesPage.h"
#include "themes/ITheme.h" #include "themes/ITheme.h"
#include "themes/SystemTheme.h" #include "themes/SystemTheme.h"
@ -842,6 +843,7 @@ void MultiMC::initGlobalSettings()
m_globalSettingsProvider->addPage<MinecraftPage>(); m_globalSettingsProvider->addPage<MinecraftPage>();
m_globalSettingsProvider->addPage<JavaPage>(); m_globalSettingsProvider->addPage<JavaPage>();
m_globalSettingsProvider->addPage<ProxyPage>(); m_globalSettingsProvider->addPage<ProxyPage>();
m_globalSettingsProvider->addPage<PackagesPage>();
m_globalSettingsProvider->addPage<ExternalToolsPage>(); m_globalSettingsProvider->addPage<ExternalToolsPage>();
m_globalSettingsProvider->addPage<AccountListPage>(); m_globalSettingsProvider->addPage<AccountListPage>();
m_globalSettingsProvider->addPage<PasteEEPage>(); m_globalSettingsProvider->addPage<PasteEEPage>();

View File

@ -313,9 +313,9 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel *replacingRaw)
auto replacing = dynamic_cast<BaseVersionList *>(replacingRaw); auto replacing = dynamic_cast<BaseVersionList *>(replacingRaw);
beginResetModel(); beginResetModel();
m_columns.clear();
if(!replacing) if(!replacing)
{ {
m_columns.clear();
roles.clear(); roles.clear();
filterModel->setSourceModel(replacing); filterModel->setSourceModel(replacing);
return; return;

View File

@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "MetadataPage.h" #include "PackagesPage.h"
#include "ui_MetadataPage.h" #include "ui_PackagesPage.h"
#include <QDateTime> #include <QDateTime>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
@ -49,9 +49,9 @@ static QString formatRequires(const VersionPtr &version)
return lines.join('\n'); return lines.join('\n');
} }
MetadataPage::MetadataPage(QWidget *parent) : PackagesPage::PackagesPage(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::MetadataPage) ui(new Ui::PackagesPage)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->tabWidget->tabBar()->hide(); ui->tabWidget->tabBar()->hide();
@ -77,29 +77,29 @@ MetadataPage::MetadataPage(QWidget *parent) :
m_versionProxy = new VersionProxyModel(this); m_versionProxy = new VersionProxyModel(this);
m_filterProxy->setSourceModel(m_versionProxy); m_filterProxy->setSourceModel(m_versionProxy);
connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateCurrentVersionList); connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateCurrentVersionList);
connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateVersion); connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateVersion);
connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &MetadataPage::versionListDataChanged); connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &PackagesPage::versionListDataChanged);
updateCurrentVersionList(QModelIndex()); updateCurrentVersionList(QModelIndex());
updateVersion(); updateVersion();
} }
MetadataPage::~MetadataPage() PackagesPage::~PackagesPage()
{ {
delete ui; 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()); 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>(); VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value<VersionListPtr>();
if (!list) if (!list)
@ -108,7 +108,7 @@ void MetadataPage::on_refreshFileBtn_clicked()
} }
ProgressDialog(this).execWithTask(list->remoteUpdateTask()); 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>(); VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value<VersionPtr>();
if (!version) if (!version)
@ -118,7 +118,7 @@ void MetadataPage::on_refreshVersionBtn_clicked()
ProgressDialog(this).execWithTask(version->remoteUpdateTask()); ProgressDialog(this).execWithTask(version->remoteUpdateTask());
} }
void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) void PackagesPage::on_fileSearchEdit_textChanged(const QString &search)
{ {
if (search.isEmpty()) if (search.isEmpty())
{ {
@ -131,7 +131,7 @@ void MetadataPage::on_fileSearchEdit_textChanged(const QString &search)
m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*");
} }
} }
void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) void PackagesPage::on_versionSearchEdit_textChanged(const QString &search)
{ {
if (search.isEmpty()) 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()) if (index.isValid())
{ {
@ -181,11 +181,11 @@ void MetadataPage::updateCurrentVersionList(const QModelIndex &index)
ui->fileNameLabel->setEnabled(false); ui->fileNameLabel->setEnabled(false);
ui->fileName->clear(); ui->fileName->clear();
m_versionProxy->setSourceModel(nullptr); 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())) 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>( VersionPtr version = std::dynamic_pointer_cast<Version>(
ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>()); ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>());
@ -221,11 +221,11 @@ void MetadataPage::updateVersion()
ui->versionType->clear(); ui->versionType->clear();
ui->versionRequiresLabel->setEnabled(false); ui->versionRequiresLabel->setEnabled(false);
ui->versionRequires->clear(); ui->versionRequires->clear();
ui->refreshVersionBtn->setText(tr("Refresh ___")); ui->refreshVersionBtn->setText(tr("Refresh"));
} }
} }
void MetadataPage::opened() void PackagesPage::opened()
{ {
if (!ENV.metadataIndex()->isLocalLoaded()) if (!ENV.metadataIndex()->isLocalLoaded())
{ {

View File

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

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>MetadataPage</class> <class>PackagesPage</class>
<widget class="QWidget" name="MetadataPage"> <widget class="QWidget" name="PackagesPage">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>640</width> <width>636</width>
<height>480</height> <height>621</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -67,7 +67,7 @@
<item> <item>
<widget class="QPushButton" name="refreshVersionBtn"> <widget class="QPushButton" name="refreshVersionBtn">
<property name="text"> <property name="text">
<string>Refresh ___</string> <string>Refresh</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -180,7 +180,7 @@
<item> <item>
<widget class="QPushButton" name="refreshFileBtn"> <widget class="QPushButton" name="refreshFileBtn">
<property name="text"> <property name="text">
<string>Refresh ___</string> <string>Refresh</string>
</property> </property>
</widget> </widget>
</item> </item>