propagate side as enum instead of Qstring
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include "FileSystem.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include "minecraft/mod/Mod.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
|
||||
#include <toml++/toml.h>
|
||||
@@ -113,7 +112,7 @@ auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
|
||||
mod.provider = mod_pack.provider;
|
||||
mod.file_id = mod_version.fileId;
|
||||
mod.project_id = mod_pack.addonId;
|
||||
mod.side = stringToSide(mod_version.side.isEmpty() ? mod_pack.side : mod_version.side);
|
||||
mod.side = mod_version.side == ModPlatform::Side::NoSide ? mod_pack.side : mod_version.side;
|
||||
mod.loaders = mod_version.loaders;
|
||||
mod.mcVersions = mod_version.mcVersion;
|
||||
mod.mcVersions.sort();
|
||||
@@ -126,18 +125,6 @@ auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
|
||||
return mod;
|
||||
}
|
||||
|
||||
auto V1::createModFormat(const QDir& index_dir, [[maybe_unused]] ::Mod& internal_mod, QString slug) -> Mod
|
||||
{
|
||||
// Try getting metadata if it exists
|
||||
Mod mod{ getIndexForMod(index_dir, slug) };
|
||||
if (mod.isValid())
|
||||
return mod;
|
||||
|
||||
qWarning() << QString("Tried to create mod metadata with a Mod without metadata!");
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void V1::updateModIndex(const QDir& index_dir, Mod& mod)
|
||||
{
|
||||
if (!mod.isValid()) {
|
||||
@@ -208,7 +195,7 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod)
|
||||
{
|
||||
auto tbl = toml::table{ { "name", mod.name.toStdString() },
|
||||
{ "filename", mod.filename.toStdString() },
|
||||
{ "side", sideToString(mod.side).toStdString() },
|
||||
{ "side", ModPlatform::SideUtils::toString(mod.side).toStdString() },
|
||||
{ "x-prismlauncher-loaders", loaders },
|
||||
{ "x-prismlauncher-mc-versions", mcVersions },
|
||||
{ "x-prismlauncher-release-type", mod.releaseType.toString().toStdString() },
|
||||
@@ -249,18 +236,6 @@ void V1::deleteModIndex(const QDir& index_dir, QString& mod_slug)
|
||||
}
|
||||
}
|
||||
|
||||
void V1::deleteModIndex(const QDir& index_dir, QVariant& mod_id)
|
||||
{
|
||||
for (auto& file_name : index_dir.entryList(QDir::Filter::Files)) {
|
||||
auto mod = getIndexForMod(index_dir, file_name);
|
||||
|
||||
if (mod.mod_id() == mod_id) {
|
||||
deleteModIndex(index_dir, mod.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod
|
||||
{
|
||||
Mod mod;
|
||||
@@ -296,7 +271,7 @@ auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod
|
||||
{ // Basic info
|
||||
mod.name = stringEntry(table, "name");
|
||||
mod.filename = stringEntry(table, "filename");
|
||||
mod.side = stringToSide(stringEntry(table, "side"));
|
||||
mod.side = ModPlatform::SideUtils::fromString(stringEntry(table, "side"));
|
||||
mod.releaseType = ModPlatform::IndexedVersionType(table["x-prismlauncher-release-type"].value_or(""));
|
||||
if (auto loaders = table["x-prismlauncher-loaders"]; loaders && loaders.is_array()) {
|
||||
for (auto&& loader : *loaders.as_array()) {
|
||||
@@ -371,28 +346,4 @@ auto V1::getIndexForMod(const QDir& index_dir, QVariant& mod_id) -> Mod
|
||||
return {};
|
||||
}
|
||||
|
||||
auto V1::sideToString(Side side) -> QString
|
||||
{
|
||||
switch (side) {
|
||||
case Side::ClientSide:
|
||||
return "client";
|
||||
case Side::ServerSide:
|
||||
return "server";
|
||||
case Side::UniversalSide:
|
||||
return "both";
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto V1::stringToSide(QString side) -> Side
|
||||
{
|
||||
if (side == "client")
|
||||
return Side::ClientSide;
|
||||
if (side == "server")
|
||||
return Side::ServerSide;
|
||||
if (side == "both")
|
||||
return Side::UniversalSide;
|
||||
return Side::UniversalSide;
|
||||
}
|
||||
|
||||
} // namespace Packwiz
|
||||
|
||||
@@ -27,23 +27,18 @@
|
||||
|
||||
class QDir;
|
||||
|
||||
// Mod from launcher/minecraft/mod/Mod.h
|
||||
class Mod;
|
||||
|
||||
namespace Packwiz {
|
||||
|
||||
auto getRealIndexName(const QDir& index_dir, QString normalized_index_name, bool should_match = false) -> QString;
|
||||
|
||||
class V1 {
|
||||
public:
|
||||
enum class Side { ClientSide = 1 << 0, ServerSide = 1 << 1, UniversalSide = ClientSide | ServerSide };
|
||||
|
||||
// can also represent other resources beside loader mods - but this is what packwiz calls it
|
||||
struct Mod {
|
||||
QString slug{};
|
||||
QString name{};
|
||||
QString filename{};
|
||||
Side side{ Side::UniversalSide };
|
||||
ModPlatform::Side side{ ModPlatform::Side::UniversalSide };
|
||||
ModPlatform::ModLoaderTypes loaders;
|
||||
QStringList mcVersions;
|
||||
ModPlatform::IndexedVersionType releaseType;
|
||||
@@ -74,10 +69,6 @@ class V1 {
|
||||
* its common representation in the launcher, when downloading mods.
|
||||
* */
|
||||
static auto createModFormat(const QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod;
|
||||
/* Generates the object representing the information in a mod.pw.toml file via
|
||||
* its common representation in the launcher, plus a necessary slug.
|
||||
* */
|
||||
static auto createModFormat(const QDir& index_dir, ::Mod& internal_mod, QString slug) -> Mod;
|
||||
|
||||
/* Updates the mod index for the provided mod.
|
||||
* This creates a new index if one does not exist already
|
||||
@@ -88,9 +79,6 @@ class V1 {
|
||||
/* Deletes the metadata for the mod with the given slug. If the metadata doesn't exist, it does nothing. */
|
||||
static void deleteModIndex(const QDir& index_dir, QString& mod_slug);
|
||||
|
||||
/* Deletes the metadata for the mod with the given id. If the metadata doesn't exist, it does nothing. */
|
||||
static void deleteModIndex(const QDir& index_dir, QVariant& mod_id);
|
||||
|
||||
/* Gets the metadata for a mod with a particular file name.
|
||||
* If the mod doesn't have a metadata, it simply returns an empty Mod object.
|
||||
* */
|
||||
@@ -100,9 +88,6 @@ class V1 {
|
||||
* If the mod doesn't have a metadata, it simply returns an empty Mod object.
|
||||
* */
|
||||
static auto getIndexForMod(const QDir& index_dir, QVariant& mod_id) -> Mod;
|
||||
|
||||
static auto sideToString(Side side) -> QString;
|
||||
static auto stringToSide(QString side) -> Side;
|
||||
};
|
||||
|
||||
} // namespace Packwiz
|
||||
|
||||
Reference in New Issue
Block a user