enables meta server to override some mojang urls
Signed-off-by: wohaopa <2411829240@qq.com>
This commit is contained in:
parent
b3a09fca1e
commit
ab721409ab
@ -688,7 +688,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
||||
|
||||
if (!resourceUrl.isValid() || (resourceUrl.scheme() != "http" && resourceUrl.scheme() != "https"))
|
||||
m_settings->reset("MinecraftResourceURLOverride");
|
||||
if (!librariesUrl.isValid() || (librariesUrl.scheme() != "http" && resourceUrl.scheme() != "https"))
|
||||
if (!librariesUrl.isValid() || (librariesUrl.scheme() != "http" && librariesUrl.scheme() != "https"))
|
||||
m_settings->reset("MinecraftLibrariesURLOverride");
|
||||
}
|
||||
|
||||
|
@ -461,6 +461,8 @@ set(META_SOURCES
|
||||
meta/Version.h
|
||||
meta/Index.cpp
|
||||
meta/Index.h
|
||||
meta/Property.cpp
|
||||
meta/Property.h
|
||||
)
|
||||
|
||||
set(API_SOURCES
|
||||
|
@ -126,4 +126,12 @@ void Index::connectVersionList(const int row, const VersionList::Ptr& list)
|
||||
connect(list.get(), &VersionList::nameChanged, this,
|
||||
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << Qt::DisplayRole); });
|
||||
}
|
||||
|
||||
shared_qobject_ptr<Meta::Property> Index::property()
|
||||
{
|
||||
if (!m_property) {
|
||||
m_property.reset(new Meta::Property());
|
||||
}
|
||||
return m_property;
|
||||
}
|
||||
} // namespace Meta
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "BaseEntity.h"
|
||||
#include "Property.h"
|
||||
#include "meta/VersionList.h"
|
||||
|
||||
class Task;
|
||||
@ -47,6 +48,9 @@ class Index : public QAbstractListModel, public BaseEntity {
|
||||
|
||||
QVector<VersionList::Ptr> lists() const { return m_lists; }
|
||||
|
||||
// Properties
|
||||
shared_qobject_ptr<Meta::Property> property();
|
||||
|
||||
public: // for usage by parsers only
|
||||
void merge(const std::shared_ptr<Index>& other);
|
||||
void parse(const QJsonObject& obj) override;
|
||||
@ -54,6 +58,7 @@ class Index : public QAbstractListModel, public BaseEntity {
|
||||
private:
|
||||
QVector<VersionList::Ptr> m_lists;
|
||||
QHash<QString, VersionList::Ptr> m_uids;
|
||||
shared_qobject_ptr<Meta::Property> m_property;
|
||||
|
||||
void connectVersionList(const int row, const VersionList::Ptr& list);
|
||||
};
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "minecraft/OneSixVersionFormat.h"
|
||||
|
||||
#include "Index.h"
|
||||
#include "Property.h"
|
||||
#include "Version.h"
|
||||
#include "VersionList.h"
|
||||
|
||||
@ -46,6 +47,33 @@ static std::shared_ptr<Index> parseIndexInternal(const QJsonObject& obj)
|
||||
return std::make_shared<Index>(lists);
|
||||
}
|
||||
|
||||
// Property
|
||||
static std::shared_ptr<Property> parsePropertyInternal(const QJsonObject& obj){
|
||||
|
||||
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "properties");
|
||||
QVector<QPair<QString, QString>> properties;
|
||||
properties.reserve(objects.size());
|
||||
|
||||
for (const auto& object : objects)
|
||||
{
|
||||
auto type = requireString(object, "type");
|
||||
if (type == "override")
|
||||
{
|
||||
auto field1 = requireString(object, "target");
|
||||
auto field2 = requireString(object, "value");
|
||||
if (!field1.endsWith("Override") || !field2.startsWith("https"))
|
||||
continue;
|
||||
|
||||
QPair<QString, QString> aProperty;
|
||||
aProperty.first = field1;
|
||||
aProperty.second = field2;
|
||||
|
||||
properties.append(aProperty);
|
||||
}
|
||||
}
|
||||
return std::make_shared<Property>(properties);
|
||||
}
|
||||
|
||||
// Version
|
||||
static Version::Ptr parseCommonVersion(const QString& uid, const QJsonObject& obj)
|
||||
{
|
||||
@ -130,6 +158,18 @@ void parseIndex(const QJsonObject& obj, Index* ptr)
|
||||
}
|
||||
}
|
||||
|
||||
void parseProperty(const QJsonObject& obj, Property* ptr)
|
||||
{
|
||||
const MetadataVersion version = parseFormatVersion(obj);
|
||||
switch (version) {
|
||||
case MetadataVersion::InitialRelease:
|
||||
ptr->merge(parsePropertyInternal(obj));
|
||||
break;
|
||||
case MetadataVersion::Invalid:
|
||||
throw ParseException(QObject::tr("Unknown format version!"));
|
||||
}
|
||||
}
|
||||
|
||||
void parseVersionList(const QJsonObject& obj, VersionList* ptr)
|
||||
{
|
||||
const MetadataVersion version = parseFormatVersion(obj);
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
namespace Meta {
|
||||
class Index;
|
||||
class Property;
|
||||
class Version;
|
||||
class VersionList;
|
||||
|
||||
@ -45,6 +46,7 @@ struct Require {
|
||||
using RequireSet = std::set<Require>;
|
||||
|
||||
void parseIndex(const QJsonObject& obj, Index* ptr);
|
||||
void parseProperty(const QJsonObject& obj, Property* ptr);
|
||||
void parseVersion(const QJsonObject& obj, Version* ptr);
|
||||
void parseVersionList(const QJsonObject& obj, VersionList* ptr);
|
||||
|
||||
|
52
launcher/meta/Property.cpp
Normal file
52
launcher/meta/Property.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/* Copyright 2015-2021 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 "Property.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "JsonFormat.h"
|
||||
|
||||
namespace Meta {
|
||||
Property::Property(QObject* parent) : QObject(parent) {}
|
||||
|
||||
Property::Property(const QVector<QPair<QString, QString>>& properties, QObject* parent) : QObject(parent)
|
||||
{
|
||||
m_properties = properties;
|
||||
}
|
||||
|
||||
void Property::parse(const QJsonObject& obj)
|
||||
{
|
||||
parseProperty(obj, this);
|
||||
}
|
||||
|
||||
void Property::merge(const std::shared_ptr<Property>& other)
|
||||
{
|
||||
m_properties = other->m_properties;
|
||||
}
|
||||
|
||||
void Property::applyProperties() {
|
||||
if (!isLoaded())
|
||||
{
|
||||
load(Net::Mode::Online);
|
||||
}
|
||||
|
||||
auto s = APPLICATION->settings();
|
||||
for (auto& property : m_properties)
|
||||
{
|
||||
if (s->contains(property.first))
|
||||
s->set(property.first,property.second);
|
||||
}
|
||||
}
|
||||
} // namespace Meta
|
46
launcher/meta/Property.h
Normal file
46
launcher/meta/Property.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* Copyright 2015-2021 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 <QAbstractListModel>
|
||||
#include <memory>
|
||||
|
||||
#include "BaseEntity.h"
|
||||
#include "meta/VersionList.h"
|
||||
|
||||
class Task;
|
||||
|
||||
namespace Meta {
|
||||
|
||||
class Property : public QObject, public BaseEntity {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Property(QObject* parent = nullptr);
|
||||
explicit Property(const QVector<QPair<QString, QString>>& properties, QObject* parent = nullptr);
|
||||
|
||||
QString localFilename() const override { return "property.json"; }
|
||||
|
||||
// Properties
|
||||
void applyProperties();
|
||||
|
||||
public: // for usage by parsers only
|
||||
void merge(const std::shared_ptr<Property>& other);
|
||||
void parse(const QJsonObject& obj) override;
|
||||
|
||||
private:
|
||||
QVector<QPair<QString, QString>> m_properties;
|
||||
};
|
||||
} // namespace Meta
|
@ -52,6 +52,7 @@
|
||||
#include "net/PasteUpload.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "tools/BaseProfiler.h"
|
||||
#include "meta/Index.h"
|
||||
|
||||
APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage)
|
||||
{
|
||||
@ -218,3 +219,9 @@ void APIPage::retranslate()
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
|
||||
void APIPage::on_applyPropertiesBtn_clicked()
|
||||
{
|
||||
APPLICATION->metadataIndex()->property()->applyProperties();
|
||||
loadSettings();
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ class APIPage : public QWidget, public BasePage {
|
||||
QString helpPage() const override { return "APIs"; }
|
||||
virtual bool apply() override;
|
||||
void retranslate() override;
|
||||
public slots:
|
||||
void on_applyPropertiesBtn_clicked();
|
||||
|
||||
private:
|
||||
int baseURLPasteType;
|
||||
|
@ -163,6 +163,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="applyPropertiesBtn">
|
||||
<property name="text">
|
||||
<string>Apply Meta Server Properties</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user