refactor: move code out of ModIndex.h

Now it's in ModIndex.cpp
This commit is contained in:
flow 2022-04-19 21:10:12 -03:00 committed by flow
parent ba50765c30
commit a99858c64d
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
6 changed files with 37 additions and 25 deletions

View File

@ -500,6 +500,9 @@ set(META_SOURCES
)
set(API_SOURCES
modplatform/ModIndex.h
modplatform/ModIndex.cpp
modplatform/ModAPI.h
modplatform/flame/FlameAPI.h

View File

@ -0,0 +1,24 @@
#include "modplatform/ModIndex.h"
namespace ModPlatform{
auto ProviderCapabilities::name(Provider p) -> const char*
{
switch(p){
case Provider::MODRINTH:
return "modrinth";
case Provider::FLAME:
return "curseforge";
}
}
auto ProviderCapabilities::hashType(Provider p) -> QString
{
switch(p){
case Provider::MODRINTH:
return "sha512";
case Provider::FLAME:
return "murmur2";
}
}
} // namespace ModPlatform

View File

@ -15,26 +15,8 @@ enum class Provider{
class ProviderCapabilities {
public:
static QString hashType(Provider p)
{
switch(p){
case Provider::MODRINTH:
return "sha512";
case Provider::FLAME:
return "murmur2";
}
return "";
}
static const char* providerName(Provider p)
{
switch(p){
case Provider::MODRINTH:
return "modrinth";
case Provider::FLAME:
return "curseforge";
}
return "";
}
auto name(Provider) -> const char*;
auto hashType(Provider) -> QString;
};
struct ModpackAuthor {

View File

@ -1,5 +1,6 @@
#pragma once
#include "modplatform/ModIndex.h"
#include "modplatform/helpers/NetworkModAPI.h"
class FlameAPI : public NetworkModAPI {

View File

@ -20,6 +20,7 @@
#include "BuildConfig.h"
#include "modplatform/ModAPI.h"
#include "modplatform/ModIndex.h"
#include "modplatform/helpers/NetworkModAPI.h"
#include <QDebug>

View File

@ -19,6 +19,8 @@ static inline auto indexFileName(QString const& mod_name) -> QString
return QString("%1.toml").arg(mod_name);
}
static ModPlatform::ProviderCapabilities ProviderCaps;
auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod
{
Mod mod;
@ -27,7 +29,7 @@ auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, Mo
mod.filename = mod_version.fileName;
mod.url = mod_version.downloadUrl;
mod.hash_format = ModPlatform::ProviderCapabilities::hashType(mod_pack.provider);
mod.hash_format = ProviderCaps.hashType(mod_pack.provider);
mod.hash = ""; // FIXME
mod.provider = mod_pack.provider;
@ -92,7 +94,7 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
addToStream("hash", mod.hash);
in_stream << QString("\n[update]\n");
in_stream << QString("[update.%1]\n").arg(ModPlatform::ProviderCapabilities::providerName(mod.provider));
in_stream << QString("[update.%1]\n").arg(ProviderCaps.name(mod.provider));
switch(mod.provider){
case(ModPlatform::Provider::FLAME):
in_stream << QString("file-id = %1\n").arg(mod.file_id.toString());
@ -193,7 +195,6 @@ auto V1::getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod
}
{ // [update] info
using ProviderCaps = ModPlatform::ProviderCapabilities;
using Provider = ModPlatform::Provider;
toml_table_t* update_table = toml_table_in(table, "update");
@ -203,11 +204,11 @@ auto V1::getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod
}
toml_table_t* mod_provider_table = nullptr;
if ((mod_provider_table = toml_table_in(update_table, ProviderCaps::providerName(Provider::FLAME)))) {
if ((mod_provider_table = toml_table_in(update_table, ProviderCaps.name(Provider::FLAME)))) {
mod.provider = Provider::FLAME;
mod.file_id = intEntry(mod_provider_table, "file-id");
mod.project_id = intEntry(mod_provider_table, "project-id");
} else if ((mod_provider_table = toml_table_in(update_table, ProviderCaps::providerName(Provider::MODRINTH)))) {
} else if ((mod_provider_table = toml_table_in(update_table, ProviderCaps.name(Provider::MODRINTH)))) {
mod.provider = Provider::MODRINTH;
mod.mod_id() = stringEntry(mod_provider_table, "mod-id");
mod.version() = stringEntry(mod_provider_table, "version");