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)
{
return rootUrl().resolved(uid + ".json");
return rootUrl().resolved(uid + "/index.json");
}
QUrl versionUrl(const QString &uid, const QString &version)

View File

@ -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
{

View File

@ -39,29 +39,19 @@ 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)
{
const int version = formatVersion(obj);
switch (version) {
case 1:
ptr->merge(FormatV1().parseVersionInternal(obj));
break;
default:
throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version));
}
}
void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr)
{
const int version = formatVersion(obj);
switch (version) {
case 10:
case 0:
ptr->merge(FormatV1().parseVersionListInternal(obj));
break;
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)
{
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);
}
}

View File

@ -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
QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) 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
{
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;

View File

@ -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

View File

@ -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>();

View File

@ -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;

View File

@ -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())
{

View File

@ -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;

View File

@ -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>