GH-3234 Add support for custom meta URLs at build time

This is not particularly interesting for non-developers.
Also includes some internal restructuring of URL constants in general.
This commit is contained in:
Petr Mrázek
2020-07-18 16:18:02 +02:00
parent 3158082b16
commit e7f373496e
27 changed files with 75 additions and 99 deletions

View File

@ -119,8 +119,6 @@ set(NET_SOURCES
net/PasteUpload.cpp
net/PasteUpload.h
net/Sink.h
net/URLConstants.cpp
net/URLConstants.h
net/Validator.h
)
@ -491,7 +489,7 @@ set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISI
generate_export_header(MultiMC_logic)
# Link
target_link_libraries(MultiMC_logic systeminfo MultiMC_quazip MultiMC_classparser ${NBT_NAME} ${ZLIB_LIBRARIES})
target_link_libraries(MultiMC_logic systeminfo MultiMC_quazip MultiMC_classparser ${NBT_NAME} ${ZLIB_LIBRARIES} BuildConfig)
target_link_libraries(MultiMC_logic Qt5::Core Qt5::Xml Qt5::Network Qt5::Concurrent)
# Mark and export headers

View File

@ -24,6 +24,8 @@
#include "Env.h"
#include "Json.h"
#include "BuildConfig.h"
class ParsingValidator : public Net::Validator
{
public: /* con/des */
@ -76,7 +78,7 @@ Meta::BaseEntity::~BaseEntity()
QUrl Meta::BaseEntity::url() const
{
return QUrl("https://meta.multimc.org/v1/").resolved(localFilename());
return QUrl(BuildConfig.META_URL).resolved(localFilename());
}
bool Meta::BaseEntity::loadLocalFile()

View File

@ -27,7 +27,7 @@
#include "FileSystem.h"
#include "net/Download.h"
#include "net/ChecksumValidator.h"
#include "net/URLConstants.h"
#include "BuildConfig.h"
namespace {
QSet<QString> collectPathsFromDir(QString dirPath)
@ -308,7 +308,7 @@ QString AssetObject::getLocalPath()
QUrl AssetObject::getUrl()
{
return URLConstants::RESOURCE_BASE + getRelPath();
return BuildConfig.RESOURCE_BASE + getRelPath();
}
QString AssetObject::getRelPath()

View File

@ -5,6 +5,7 @@
#include <net/ChecksumValidator.h>
#include <Env.h>
#include <FileSystem.h>
#include <BuildConfig.h>
void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32,
@ -171,7 +172,7 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
if (m_repositoryURL.isEmpty())
{
return URLConstants::LIBRARY_BASE + raw_storage;
return BuildConfig.LIBRARY_BASE + raw_storage;
}
if(m_repositoryURL.endsWith('/'))

View File

@ -12,7 +12,6 @@
#include "Rule.h"
#include "minecraft/OpSys.h"
#include "GradleSpecifier.h"
#include "net/URLConstants.h"
#include "MojangDownloadInfo.h"
#include "multimc_logic_export.h"

View File

@ -25,7 +25,6 @@
#include "BaseInstance.h"
#include "minecraft/PackProfile.h"
#include "minecraft/Library.h"
#include "net/URLConstants.h"
#include <FileSystem.h>
#include "update/FoldersTask.h"

View File

@ -198,7 +198,10 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
// FIXME: this will eventually break...
else
{
lib->setAbsoluteUrl(URLConstants::getLegacyJarUrl(out->minecraftVersion));
out->addProblem(
ProblemSeverity::Error,
QObject::tr("URL for the main jar could not be determined - Mojang removed the server that we used as fallback.")
);
}
out->mainJar = lib;
}

View File

@ -25,7 +25,7 @@
#include <Env.h>
#include <net/URLConstants.h>
#include <BuildConfig.h>
#include <QDebug>
@ -42,7 +42,7 @@ void YggdrasilTask::executeTask()
// Get the content of the request we're going to send to the server.
QJsonDocument doc(getRequestContent());
QUrl reqUrl(URLConstants::AUTH_BASE + getEndpoint());
QUrl reqUrl(BuildConfig.AUTH_BASE + getEndpoint());
QNetworkRequest netRequest(reqUrl);
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");

View File

@ -4,6 +4,7 @@
#include "FMLLibrariesTask.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "BuildConfig.h"
FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance * inst)
{
@ -63,7 +64,7 @@ void FMLLibrariesTask::executeTask()
for (auto &lib : fmlLibsToProcess)
{
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
QString urlString = (lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL : URLConstants::FMLLIBS_FORGE_BASE_URL) + lib.filename;
QString urlString = (lib.ours ? BuildConfig.FMLLIBS_OUR_BASE_URL : BuildConfig.FMLLIBS_FORGE_BASE_URL) + lib.filename;
dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry));
}

View File

@ -2,7 +2,7 @@
#include "PrivatePackManager.h"
#include <QDomDocument>
#include "net/URLConstants.h"
#include <BuildConfig.h>
namespace LegacyFTB {
@ -13,11 +13,11 @@ void PackFetchTask::fetch()
NetJob *netJob = new NetJob("LegacyFTB::ModpackFetch");
QUrl publicPacksUrl = QUrl(URLConstants::LEGACY_FTB_CDN_BASE_URL + "static/modpacks.xml");
QUrl publicPacksUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/modpacks.xml");
qDebug() << "Downloading public version info from" << publicPacksUrl.toString();
netJob->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData));
QUrl thirdPartyUrl = QUrl(URLConstants::LEGACY_FTB_CDN_BASE_URL + "static/thirdparty.xml");
QUrl thirdPartyUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/thirdparty.xml");
qDebug() << "Downloading thirdparty version info from" << thirdPartyUrl.toString();
netJob->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData));
@ -30,7 +30,7 @@ void PackFetchTask::fetch()
void PackFetchTask::fetchPrivate(const QStringList & toFetch)
{
QString privatePackBaseUrl = URLConstants::LEGACY_FTB_CDN_BASE_URL + "static/%1.xml";
QString privatePackBaseUrl = BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1.xml";
for (auto &packCode: toFetch)
{

View File

@ -9,7 +9,7 @@
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "minecraft/GradleSpecifier.h"
#include "net/URLConstants.h"
#include "BuildConfig.h"
#include <QtConcurrent>
@ -38,11 +38,11 @@ void PackInstallTask::downloadPack()
QString url;
if(m_pack.type == PackType::Private)
{
url = QString(URLConstants::LEGACY_FTB_CDN_BASE_URL + "privatepacks/%1").arg(packoffset);
url = QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "privatepacks/%1").arg(packoffset);
}
else
{
url = QString(URLConstants::LEGACY_FTB_CDN_BASE_URL + "modpacks/%1").arg(packoffset);
url = QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "modpacks/%1").arg(packoffset);
}
job->addNetAction(Net::Download::makeCached(url, entry));
archivePath = entry->getFullPath();
@ -210,4 +210,4 @@ bool PackInstallTask::abort()
return false;
}
}
}

View File

@ -1,16 +0,0 @@
#include "URLConstants.h"
namespace URLConstants {
QString getLegacyJarUrl(QString version)
{
return AWS_DOWNLOAD_VERSIONS + getJarPath(version);
}
QString getJarPath(QString version)
{
return version + "/" + version + ".jar";
}
}

View File

@ -1,37 +0,0 @@
/* Copyright 2013-2019 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 <QString>
namespace URLConstants
{
const QString AWS_DOWNLOAD_VERSIONS("https://s3.amazonaws.com/Minecraft.Download/versions/");
const QString RESOURCE_BASE("https://resources.download.minecraft.net/");
const QString LIBRARY_BASE("https://libraries.minecraft.net/");
const QString SKINS_BASE("https://crafatar.com/skins/");
const QString AUTH_BASE("https://authserver.mojang.com/");
const QString MOJANG_STATUS_URL("https://status.mojang.com/check");
const QString IMGUR_BASE_URL("https://api.imgur.com/3/");
const QString FMLLIBS_OUR_BASE_URL("https://files.multimc.org/fmllibs/");
const QString FMLLIBS_FORGE_BASE_URL("https://files.minecraftforge.net/fmllibs/");
const QString TRANSLATIONS_BASE_URL("https://files.multimc.org/translations/");
const QString LEGACY_FTB_CDN_BASE_URL("https://dist.creeper.host/FTB2/");
QString getJarPath(QString version);
QString getLegacyJarUrl(QString version);
}

View File

@ -6,13 +6,13 @@
#include <QUrl>
#include <QStringList>
#include "net/URLConstants.h"
#include "BuildConfig.h"
#include "Env.h"
#include <QDebug>
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
{
m_url = URLConstants::IMGUR_BASE_URL + "album.json";
m_url = BuildConfig.IMGUR_BASE_URL + "album.json";
m_status = Job_NotStarted;
}

View File

@ -8,13 +8,13 @@
#include <QFile>
#include <QUrl>
#include "net/URLConstants.h"
#include "BuildConfig.h"
#include "Env.h"
#include <QDebug>
ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot)
{
m_url = URLConstants::IMGUR_BASE_URL + "upload.json";
m_url = BuildConfig.IMGUR_BASE_URL + "upload.json";
m_status = Job_NotStarted;
}

View File

@ -15,12 +15,12 @@
#include "StatusChecker.h"
#include <net/URLConstants.h>
#include <QByteArray>
#include <QDebug>
#include <BuildConfig.h>
StatusChecker::StatusChecker()
{
@ -43,7 +43,7 @@ void StatusChecker::reloadStatus()
// qDebug() << "Reloading status.";
NetJob* job = new NetJob("Status JSON");
job->addNetAction(Net::Download::makeByteArray(URLConstants::MOJANG_STATUS_URL, &dataSink));
job->addNetAction(Net::Download::makeByteArray(BuildConfig.MOJANG_STATUS_URL, &dataSink));
QObject::connect(job, &NetJob::succeeded, this, &StatusChecker::statusDownloadFinished);
QObject::connect(job, &NetJob::failed, this, &StatusChecker::statusDownloadFailed);
m_statusNetJob.reset(job);

View File

@ -10,7 +10,7 @@
#include <net/NetJob.h>
#include <net/ChecksumValidator.h>
#include <Env.h>
#include <net/URLConstants.h>
#include <BuildConfig.h>
#include "Json.h"
#include "POTranslator.h"
@ -606,7 +606,7 @@ void TranslationsModel::downloadTranslation(QString key)
MetaEntryPtr entry = ENV.metacache()->resolveEntry("translations", "mmc_" + key + ".qm");
entry->setStale(true);
auto dl = Net::Download::makeCached(QUrl(URLConstants::TRANSLATIONS_BASE_URL + lang->file_name), entry);
auto dl = Net::Download::makeCached(QUrl(BuildConfig.TRANSLATIONS_BASE_URL + lang->file_name), entry);
auto rawHash = QByteArray::fromHex(lang->file_sha1.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
dl->m_total_progress = lang->file_size;