Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
Sebastian-byte
2021-04-21 19:43:17 -05:00
18 changed files with 370 additions and 243 deletions

View File

@@ -466,6 +466,8 @@ set(FTB_SOURCES
set(FLAME_SOURCES
# Flame
modplatform/flame/FlamePackIndex.cpp
modplatform/flame/FlamePackIndex.h
modplatform/flame/PackManifest.h
modplatform/flame/PackManifest.cpp
modplatform/flame/FileResolvingTask.h

View File

@@ -73,13 +73,13 @@ void PackInstallTask::onDownloadSucceeded()
auto vlist = ENV.metadataIndex()->get("net.minecraft");
if(!vlist)
{
emitFailed(tr("Failed to get local metadata index for ") + "net.minecraft");
emitFailed(tr("Failed to get local metadata index for %1").arg("net.minecraft"));
return;
}
auto ver = vlist->getVersion(m_version.minecraft);
if (!ver) {
emitFailed(tr("Failed to get local metadata index for ") + "net.minecraft" + " " + m_version.minecraft);
emitFailed(tr("Failed to get local metadata index for '%1' v%2").arg("net.minecraft").arg(m_version.minecraft));
return;
}
ver->load(Net::Mode::Online);
@@ -141,7 +141,7 @@ QString PackInstallTask::getDirForModType(ModType type, QString raw)
qWarning() << "Unsupported mod type: " + raw;
return Q_NULLPTR;
case ModType::Unknown:
emitFailed(tr("Unknown mod type: ") + raw);
emitFailed(tr("Unknown mod type: %1").arg(raw));
return Q_NULLPTR;
}
@@ -271,7 +271,7 @@ bool PackInstallTask::createLibrariesComponent(QString instanceRoot, std::shared
break;
case DownloadType::Browser:
case DownloadType::Unknown:
emitFailed(tr("Unknown or unsupported download type: ") + lib.download_raw);
emitFailed(tr("Unknown or unsupported download type: %1").arg(lib.download_raw));
return false;
}
@@ -437,13 +437,13 @@ void PackInstallTask::downloadMods()
url = BuildConfig.ATL_DOWNLOAD_SERVER_URL + mod.url;
break;
case DownloadType::Browser:
emitFailed(tr("Unsupported download type: ") + mod.download_raw);
emitFailed(tr("Unsupported download type: %1").arg(mod.download_raw));
return;
case DownloadType::Direct:
url = mod.url;
break;
case DownloadType::Unknown:
emitFailed(tr("Unknown download type: ") + mod.download_raw);
emitFailed(tr("Unknown download type: %1").arg(mod.download_raw));
return;
}

View File

@@ -0,0 +1,92 @@
#include "FlamePackIndex.h"
#include "Json.h"
void Flame::loadIndexedPack(Flame::IndexedPack & pack, QJsonObject & obj)
{
pack.addonId = Json::requireInteger(obj, "id");
pack.name = Json::requireString(obj, "name");
pack.websiteUrl = Json::ensureString(obj, "websiteUrl", "");
pack.description = Json::ensureString(obj, "summary", "");
bool thumbnailFound = false;
auto attachments = Json::requireArray(obj, "attachments");
for(auto attachmentRaw: attachments) {
auto attachmentObj = Json::requireObject(attachmentRaw);
bool isDefault = attachmentObj.value("isDefault").toBool(false);
if(isDefault) {
thumbnailFound = true;
pack.logoName = Json::requireString(attachmentObj, "title");
pack.logoUrl = Json::requireString(attachmentObj, "thumbnailUrl");
break;
}
}
if(!thumbnailFound) {
throw JSONValidationError(QString("Pack without an icon, skipping: %1").arg(pack.name));
}
auto authors = Json::requireArray(obj, "authors");
for(auto authorIter: authors) {
auto author = Json::requireObject(authorIter);
Flame::ModpackAuthor packAuthor;
packAuthor.name = Json::requireString(author, "name");
packAuthor.url = Json::requireString(author, "url");
pack.authors.append(packAuthor);
}
int defaultFileId = Json::requireInteger(obj, "defaultFileId");
bool found = false;
// check if there are some files before adding the pack
auto files = Json::requireArray(obj, "latestFiles");
for(auto fileIter: files) {
auto file = Json::requireObject(fileIter);
int id = Json::requireInteger(file, "id");
// NOTE: for now, ignore everything that's not the default...
if(id != defaultFileId) {
continue;
}
auto versionArray = Json::requireArray(file, "gameVersion");
if(versionArray.size() < 1) {
continue;
}
found = true;
break;
}
if(!found) {
throw JSONValidationError(QString("Pack with no good file, skipping: %1").arg(pack.name));
}
}
void Flame::loadIndexedPackVersions(Flame::IndexedPack & pack, QJsonArray & arr)
{
QVector<Flame::IndexedVersion> unsortedVersions;
for(auto versionIter: arr) {
auto version = Json::requireObject(versionIter);
Flame::IndexedVersion file;
file.addonId = pack.addonId;
file.fileId = Json::requireInteger(version, "id");
auto versionArray = Json::requireArray(version, "gameVersion");
if(versionArray.size() < 1) {
continue;
}
// pick the latest version supported
file.mcVersion = versionArray[0].toString();
file.version = Json::requireString(version, "displayName");
file.downloadUrl = Json::requireString(version, "downloadUrl");
unsortedVersions.append(file);
}
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
{
return a.fileId > b.fileId;
};
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
pack.versions = unsortedVersions;
pack.versionsLoaded = true;
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include <QList>
#include <QMetaType>
#include <QString>
#include <QVector>
#include "multimc_logic_export.h"
namespace Flame {
struct ModpackAuthor {
QString name;
QString url;
};
struct IndexedVersion {
int addonId;
int fileId;
QString version;
QString mcVersion;
QString downloadUrl;
};
struct IndexedPack
{
int addonId;
QString name;
QString description;
QList<ModpackAuthor> authors;
QString logoName;
QString logoUrl;
QString websiteUrl;
bool versionsLoaded = false;
QVector<IndexedVersion> versions;
};
MULTIMC_LOGIC_EXPORT void loadIndexedPack(IndexedPack & m, QJsonObject & obj);
MULTIMC_LOGIC_EXPORT void loadIndexedPackVersions(IndexedPack & m, QJsonArray & arr);
}
Q_DECLARE_METATYPE(Flame::IndexedPack)

View File

@@ -35,7 +35,7 @@ void PackInstallTask::executeTask()
}
if(!found) {
emitFailed("failed to find pack version " + m_version_name);
emitFailed(tr("Failed to find pack version %1").arg(m_version_name));
return;
}

View File

@@ -15,7 +15,19 @@
#include "POTranslator.h"
const static QLatin1Literal defaultLangCode("en");
const static QLatin1Literal defaultLangCode("en_US");
static QLocale getLocaleFromKey(const QString &key) {
if(key == "pt") {
return QLocale("pt_PT");
}
else if (key == "en") {
return QLocale("en_GB");
}
else {
return QLocale(key);
}
}
enum class FileType
{
@@ -33,12 +45,7 @@ struct Language
Language(const QString & _key)
{
key = _key;
if(key == "pt") {
locale = QLocale("pt_PT");
}
else {
locale = QLocale(key);
}
locale = getLocaleFromKey(key);
updated = (key == defaultLangCode);
}
@@ -452,7 +459,7 @@ bool TranslationsModel::selectLanguage(QString key)
* In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.
* This function is not reentrant.
*/
QLocale locale(langCode);
QLocale locale = getLocaleFromKey(langCode);
QLocale::setDefault(locale);
// if it's the default UI language, finish