mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-28 21:00:20 +02:00
De-OOP ProviderCapabilities
There was no reason for it to be a class, and imo it created quite a code-smell needing to initialise it everywhere. Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
97ee0a19b5
commit
82d0f204e2
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
Resource::Resource(QObject* parent) : QObject(parent) {}
|
Resource::Resource(QObject* parent) : QObject(parent) {}
|
||||||
|
|
||||||
Resource::Resource(QFileInfo file_info) : QObject()
|
Resource::Resource(QFileInfo file_info) : QObject()
|
||||||
@ -74,7 +72,7 @@ static void removeThePrefix(QString& string)
|
|||||||
auto Resource::provider() const -> QString
|
auto Resource::provider() const -> QString
|
||||||
{
|
{
|
||||||
if (metadata())
|
if (metadata())
|
||||||
return ProviderCaps.readableName(metadata()->provider);
|
return ModPlatform::ProviderCapabilities::readableName(metadata()->provider);
|
||||||
|
|
||||||
return tr("Unknown");
|
return tr("Unknown");
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
#include "modplatform/modrinth/ModrinthAPI.h"
|
#include "modplatform/modrinth/ModrinthAPI.h"
|
||||||
#include "modplatform/modrinth/ModrinthPackIndex.h"
|
#include "modplatform/modrinth/ModrinthPackIndex.h"
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
static ModrinthAPI modrinth_api;
|
static ModrinthAPI modrinth_api;
|
||||||
static FlameAPI flame_api;
|
static FlameAPI flame_api;
|
||||||
|
|
||||||
@ -162,10 +160,10 @@ void EnsureMetadataTask::executeTask()
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (m_resources.size() > 1)
|
if (m_resources.size() > 1)
|
||||||
setStatus(tr("Requesting metadata information from %1...").arg(ProviderCaps.readableName(m_provider)));
|
setStatus(tr("Requesting metadata information from %1...").arg(ModPlatform::ProviderCapabilities::readableName(m_provider)));
|
||||||
else if (!m_resources.empty())
|
else if (!m_resources.empty())
|
||||||
setStatus(tr("Requesting metadata information from %1 for '%2'...")
|
setStatus(tr("Requesting metadata information from %1 for '%2'...")
|
||||||
.arg(ProviderCaps.readableName(m_provider), m_resources.begin().value()->name()));
|
.arg(ModPlatform::ProviderCapabilities::readableName(m_provider), m_resources.begin().value()->name()));
|
||||||
|
|
||||||
m_current_task = version_task;
|
m_current_task = version_task;
|
||||||
version_task->start();
|
version_task->start();
|
||||||
@ -215,7 +213,7 @@ void EnsureMetadataTask::emitFail(Resource* resource, QString key, RemoveFromLis
|
|||||||
|
|
||||||
Task::Ptr EnsureMetadataTask::modrinthVersionsTask()
|
Task::Ptr EnsureMetadataTask::modrinthVersionsTask()
|
||||||
{
|
{
|
||||||
auto hash_type = ProviderCaps.hashType(ModPlatform::ResourceProvider::MODRINTH).first();
|
auto hash_type = ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first();
|
||||||
|
|
||||||
auto response = std::make_shared<QByteArray>();
|
auto response = std::make_shared<QByteArray>();
|
||||||
auto ver_task = modrinth_api.currentVersions(m_resources.keys(), hash_type, response);
|
auto ver_task = modrinth_api.currentVersions(m_resources.keys(), hash_type, response);
|
||||||
|
@ -40,8 +40,7 @@ enum class ResourceType { MOD, RESOURCE_PACK, SHADER_PACK };
|
|||||||
|
|
||||||
enum class DependencyType { REQUIRED, OPTIONAL, INCOMPATIBLE, EMBEDDED, TOOL, INCLUDE, UNKNOWN };
|
enum class DependencyType { REQUIRED, OPTIONAL, INCOMPATIBLE, EMBEDDED, TOOL, INCLUDE, UNKNOWN };
|
||||||
|
|
||||||
class ProviderCapabilities {
|
namespace ProviderCapabilities {
|
||||||
public:
|
|
||||||
auto name(ResourceProvider) -> const char*;
|
auto name(ResourceProvider) -> const char*;
|
||||||
auto readableName(ResourceProvider) -> QString;
|
auto readableName(ResourceProvider) -> QString;
|
||||||
auto hashType(ResourceProvider) -> QStringList;
|
auto hashType(ResourceProvider) -> QStringList;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "modplatform/flame/FlameAPI.h"
|
#include "modplatform/flame/FlameAPI.h"
|
||||||
|
|
||||||
static FlameAPI api;
|
static FlameAPI api;
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||||
{
|
{
|
||||||
@ -158,7 +157,7 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) ->
|
|||||||
auto hash_list = Json::ensureArray(obj, "hashes");
|
auto hash_list = Json::ensureArray(obj, "hashes");
|
||||||
for (auto h : hash_list) {
|
for (auto h : hash_list) {
|
||||||
auto hash_entry = Json::ensureObject(h);
|
auto hash_entry = Json::ensureObject(h);
|
||||||
auto hash_types = ProviderCaps.hashType(ModPlatform::ResourceProvider::FLAME);
|
auto hash_types = ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::FLAME);
|
||||||
auto hash_algo = enumToString(Json::ensureInteger(hash_entry, "algo", 1, "algorithm"));
|
auto hash_algo = enumToString(Json::ensureInteger(hash_entry, "algo", 1, "algorithm"));
|
||||||
if (hash_types.contains(hash_algo)) {
|
if (hash_types.contains(hash_algo)) {
|
||||||
file.hash = Json::requireString(hash_entry, "value");
|
file.hash = Json::requireString(hash_entry, "value");
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
namespace Hashing {
|
namespace Hashing {
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
Hasher::Ptr createHasher(QString file_path, ModPlatform::ResourceProvider provider)
|
Hasher::Ptr createHasher(QString file_path, ModPlatform::ResourceProvider provider)
|
||||||
{
|
{
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
@ -62,8 +60,8 @@ void ModrinthHasher::executeTask()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hash_type = ProviderCaps.hashType(ModPlatform::ResourceProvider::MODRINTH).first();
|
auto hash_type = ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first();
|
||||||
m_hash = ProviderCaps.hash(ModPlatform::ResourceProvider::MODRINTH, &file, hash_type);
|
m_hash = ModPlatform::ProviderCapabilities::hash(ModPlatform::ResourceProvider::MODRINTH, &file, hash_type);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
@ -96,7 +94,7 @@ void FlameHasher::executeTask()
|
|||||||
BlockedModHasher::BlockedModHasher(QString file_path, ModPlatform::ResourceProvider provider) : Hasher(file_path), provider(provider)
|
BlockedModHasher::BlockedModHasher(QString file_path, ModPlatform::ResourceProvider provider) : Hasher(file_path), provider(provider)
|
||||||
{
|
{
|
||||||
setObjectName(QString("BlockedModHasher: %1").arg(file_path));
|
setObjectName(QString("BlockedModHasher: %1").arg(file_path));
|
||||||
hash_type = ProviderCaps.hashType(provider).first();
|
hash_type = ModPlatform::ProviderCapabilities::hashType(provider).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockedModHasher::executeTask()
|
void BlockedModHasher::executeTask()
|
||||||
@ -113,7 +111,7 @@ void BlockedModHasher::executeTask()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hash = ProviderCaps.hash(provider, &file, hash_type);
|
m_hash = ModPlatform::ProviderCapabilities::hash(provider, &file, hash_type);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
@ -127,12 +125,12 @@ void BlockedModHasher::executeTask()
|
|||||||
|
|
||||||
QStringList BlockedModHasher::getHashTypes()
|
QStringList BlockedModHasher::getHashTypes()
|
||||||
{
|
{
|
||||||
return ProviderCaps.hashType(provider);
|
return ModPlatform::ProviderCapabilities::hashType(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockedModHasher::useHashType(QString type)
|
bool BlockedModHasher::useHashType(QString type)
|
||||||
{
|
{
|
||||||
auto types = ProviderCaps.hashType(provider);
|
auto types = ModPlatform::ProviderCapabilities::hashType(provider);
|
||||||
if (types.contains(type)) {
|
if (types.contains(type)) {
|
||||||
hash_type = type;
|
hash_type = type;
|
||||||
return true;
|
return true;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
|
||||||
static ModrinthAPI api;
|
static ModrinthAPI api;
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
bool ModrinthCheckUpdate::abort()
|
bool ModrinthCheckUpdate::abort()
|
||||||
{
|
{
|
||||||
@ -36,7 +35,7 @@ void ModrinthCheckUpdate::executeTask()
|
|||||||
|
|
||||||
// Create all hashes
|
// Create all hashes
|
||||||
QStringList hashes;
|
QStringList hashes;
|
||||||
auto best_hash_type = ProviderCaps.hashType(ModPlatform::ResourceProvider::MODRINTH).first();
|
auto best_hash_type = ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first();
|
||||||
|
|
||||||
ConcurrentTask hashing_task(this, "MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
ConcurrentTask hashing_task(this, "MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
||||||
for (auto* resource : m_resources) {
|
for (auto* resource : m_resources) {
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include "modplatform/ModIndex.h"
|
#include "modplatform/ModIndex.h"
|
||||||
|
|
||||||
static ModrinthAPI api;
|
static ModrinthAPI api;
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
bool shouldDownloadOnSide(QString side)
|
bool shouldDownloadOnSide(QString side)
|
||||||
{
|
{
|
||||||
@ -233,7 +232,7 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject& obj, QString preferred_hash_t
|
|||||||
file.hash = Json::requireString(hash_list, preferred_hash_type);
|
file.hash = Json::requireString(hash_list, preferred_hash_type);
|
||||||
file.hash_type = preferred_hash_type;
|
file.hash_type = preferred_hash_type;
|
||||||
} else {
|
} else {
|
||||||
auto hash_types = ProviderCaps.hashType(ModPlatform::ResourceProvider::MODRINTH);
|
auto hash_types = ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH);
|
||||||
for (auto& hash_type : hash_types) {
|
for (auto& hash_type : hash_types) {
|
||||||
if (hash_list.contains(hash_type)) {
|
if (hash_list.contains(hash_type)) {
|
||||||
file.hash = Json::requireString(hash_list, hash_type);
|
file.hash = Json::requireString(hash_list, hash_type);
|
||||||
|
@ -66,8 +66,6 @@ static inline auto indexFileName(QString const& mod_slug) -> QString
|
|||||||
return QString("%1.pw.toml").arg(mod_slug);
|
return QString("%1.pw.toml").arg(mod_slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
// Helper functions for extracting data from the TOML file
|
// Helper functions for extracting data from the TOML file
|
||||||
auto stringEntry(toml::table table, QString entry_name) -> QString
|
auto stringEntry(toml::table table, QString entry_name) -> QString
|
||||||
{
|
{
|
||||||
@ -201,7 +199,7 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod)
|
|||||||
{ "hash-format", mod.hash_format.toStdString() },
|
{ "hash-format", mod.hash_format.toStdString() },
|
||||||
{ "hash", mod.hash.toStdString() },
|
{ "hash", mod.hash.toStdString() },
|
||||||
} },
|
} },
|
||||||
{ "update", toml::table{ { ProviderCaps.name(mod.provider), update },
|
{ "update", toml::table{ { ModPlatform::ProviderCapabilities::name(mod.provider), update },
|
||||||
{ "x-prismlauncher-version-number", mod.version_number.toStdString() } } } };
|
{ "x-prismlauncher-version-number", mod.version_number.toStdString() } } } };
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << tbl;
|
ss << tbl;
|
||||||
@ -306,11 +304,11 @@ auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod
|
|||||||
mod.version_number = stringEntry(*update_table, "x-prismlauncher-version-number");
|
mod.version_number = stringEntry(*update_table, "x-prismlauncher-version-number");
|
||||||
|
|
||||||
toml::table* mod_provider_table = nullptr;
|
toml::table* mod_provider_table = nullptr;
|
||||||
if ((mod_provider_table = (*update_table)[ProviderCaps.name(Provider::FLAME)].as_table())) {
|
if ((mod_provider_table = (*update_table)[ModPlatform::ProviderCapabilities::name(Provider::FLAME)].as_table())) {
|
||||||
mod.provider = Provider::FLAME;
|
mod.provider = Provider::FLAME;
|
||||||
mod.file_id = intEntry(*mod_provider_table, "file-id");
|
mod.file_id = intEntry(*mod_provider_table, "file-id");
|
||||||
mod.project_id = intEntry(*mod_provider_table, "project-id");
|
mod.project_id = intEntry(*mod_provider_table, "project-id");
|
||||||
} else if ((mod_provider_table = (*update_table)[ProviderCaps.name(Provider::MODRINTH)].as_table())) {
|
} else if ((mod_provider_table = (*update_table)[ModPlatform::ProviderCapabilities::name(Provider::MODRINTH)].as_table())) {
|
||||||
mod.provider = Provider::MODRINTH;
|
mod.provider = Provider::MODRINTH;
|
||||||
mod.mod_id() = stringEntry(*mod_provider_table, "mod-id");
|
mod.mod_id() = stringEntry(*mod_provider_table, "mod-id");
|
||||||
mod.version() = stringEntry(*mod_provider_table, "version");
|
mod.version() = stringEntry(*mod_provider_table, "version");
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
#include "modplatform/ModIndex.h"
|
#include "modplatform/ModIndex.h"
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
ChooseProviderDialog::ChooseProviderDialog(QWidget* parent, bool single_choice, bool allow_skipping)
|
ChooseProviderDialog::ChooseProviderDialog(QWidget* parent, bool single_choice, bool allow_skipping)
|
||||||
: QDialog(parent), ui(new Ui::ChooseProviderDialog)
|
: QDialog(parent), ui(new Ui::ChooseProviderDialog)
|
||||||
{
|
{
|
||||||
@ -78,7 +76,7 @@ void ChooseProviderDialog::addProviders()
|
|||||||
QRadioButton* btn;
|
QRadioButton* btn;
|
||||||
|
|
||||||
for (auto& provider : { ModPlatform::ResourceProvider::MODRINTH, ModPlatform::ResourceProvider::FLAME }) {
|
for (auto& provider : { ModPlatform::ResourceProvider::MODRINTH, ModPlatform::ResourceProvider::FLAME }) {
|
||||||
btn = new QRadioButton(ProviderCaps.readableName(provider), this);
|
btn = new QRadioButton(ModPlatform::ProviderCapabilities::readableName(provider), this);
|
||||||
m_providers.addButton(btn, btn_index++);
|
m_providers.addButton(btn, btn_index++);
|
||||||
ui->providersLayout->addWidget(btn);
|
ui->providersLayout->addWidget(btn);
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,6 @@ void ResourceDownloadDialog::connectButtons()
|
|||||||
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
|
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
void ResourceDownloadDialog::confirm()
|
void ResourceDownloadDialog::confirm()
|
||||||
{
|
{
|
||||||
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
|
auto confirm_dialog = ReviewMessageBox::create(this, tr("Confirm %1 to download").arg(resourcesString()));
|
||||||
@ -167,7 +165,7 @@ void ResourceDownloadDialog::confirm()
|
|||||||
});
|
});
|
||||||
for (auto& task : selected) {
|
for (auto& task : selected) {
|
||||||
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(),
|
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(),
|
||||||
ProviderCaps.name(task->getProvider()), getRequiredBy.value(task->getPack()->addonId.toString()),
|
ModPlatform::ProviderCapabilities::name(task->getProvider()), getRequiredBy.value(task->getPack()->addonId.toString()),
|
||||||
task->getVersion().version_type.toString() });
|
task->getVersion().version_type.toString() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
||||||
|
|
||||||
static std::list<Version> mcVersions(BaseInstance* inst)
|
static std::list<Version> mcVersions(BaseInstance* inst)
|
||||||
{
|
{
|
||||||
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getComponent("net.minecraft")->getVersion() };
|
return { static_cast<MinecraftInstance*>(inst)->getPackProfile()->getComponent("net.minecraft")->getVersion() };
|
||||||
@ -423,7 +421,7 @@ void ResourceUpdateDialog::appendResource(CheckUpdateTask::Update const& info, Q
|
|||||||
item_top->setExpanded(true);
|
item_top->setExpanded(true);
|
||||||
|
|
||||||
auto provider_item = new QTreeWidgetItem(item_top);
|
auto provider_item = new QTreeWidgetItem(item_top);
|
||||||
provider_item->setText(0, tr("Provider: %1").arg(ProviderCaps.readableName(info.provider)));
|
provider_item->setText(0, tr("Provider: %1").arg(ModPlatform::ProviderCapabilities::readableName(info.provider)));
|
||||||
|
|
||||||
auto old_version_item = new QTreeWidgetItem(item_top);
|
auto old_version_item = new QTreeWidgetItem(item_top);
|
||||||
old_version_item->setText(0, tr("Old version: %1").arg(info.old_version));
|
old_version_item->setText(0, tr("Old version: %1").arg(info.old_version));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user