fix: separate types of std::string in Packwiz

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-11-03 16:59:50 -03:00
parent dff5fea976
commit d35c2db41e
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 16 additions and 14 deletions

View File

@ -22,10 +22,14 @@
#include <QDir> #include <QDir>
#include <QObject> #include <QObject>
#include <toml++/toml.h> #include "FileSystem.h"
#include "StringUtils.h"
#include "minecraft/mod/Mod.h" #include "minecraft/mod/Mod.h"
#include "modplatform/ModIndex.h" #include "modplatform/ModIndex.h"
#include <toml++/toml.h>
namespace Packwiz { namespace Packwiz {
auto getRealIndexName(QDir& index_dir, QString normalized_fname, bool should_find_match) -> QString auto getRealIndexName(QDir& index_dir, QString normalized_fname, bool should_find_match) -> QString
@ -63,22 +67,22 @@ static inline auto indexFileName(QString const& mod_slug) -> QString
static ModPlatform::ProviderCapabilities ProviderCaps; 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, const std::string entry_name) -> QString auto stringEntry(toml::table table, QString entry_name) -> QString
{ {
auto node = table[entry_name]; auto node = table[StringUtils::toStdString(entry_name)];
if (!node) { if (!node) {
qCritical() << QString::fromStdString("Failed to read str property '" + entry_name + "' in mod metadata."); qCritical() << "Failed to read str property '" + entry_name + "' in mod metadata.";
return {}; return {};
} }
return QString::fromStdString(node.value_or("")); return node.value_or("");
} }
auto intEntry(toml::table table, const std::string entry_name) -> int auto intEntry(toml::table table, QString entry_name) -> int
{ {
auto node = table[entry_name]; auto node = table[StringUtils::toStdString(entry_name)];
if (!node) { if (!node) {
qCritical() << QString::fromStdString("Failed to read int property '" + entry_name + "' in mod metadata."); qCritical() << "Failed to read int property '" + entry_name + "' in mod metadata.";
return {}; return {};
} }
@ -145,6 +149,8 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
// they want to do! // they want to do!
if (index_file.exists()) { if (index_file.exists()) {
index_file.remove(); index_file.remove();
} else {
FS::ensureFilePathExists(index_file.fileName());
} }
if (!index_file.open(QIODevice::ReadWrite)) { if (!index_file.open(QIODevice::ReadWrite)) {
@ -228,14 +234,14 @@ auto V1::getIndexForMod(QDir& index_dir, QString slug) -> Mod
toml::table table; toml::table table;
#if TOML_EXCEPTIONS #if TOML_EXCEPTIONS
try { try {
table = toml::parse_file(index_dir.absoluteFilePath(real_fname).toStdString()); table = toml::parse_file(StringUtils::toStdString(index_dir.absoluteFilePath(real_fname)));
} catch (const toml::parse_error& err) { } catch (const toml::parse_error& err) {
qWarning() << QString("Could not open file %1!").arg(normalized_fname); qWarning() << QString("Could not open file %1!").arg(normalized_fname);
qWarning() << "Reason: " << QString(err.what()); qWarning() << "Reason: " << QString(err.what());
return {}; return {};
} }
#else #else
table = toml::parse_file(index_dir.absoluteFilePath(real_fname).toStdString()); table = toml::parse_file(StringUtils::toStdString(index_dir.absoluteFilePath(real_fname)));
if (!table) { if (!table) {
qWarning() << QString("Could not open file %1!").arg(normalized_fname); qWarning() << QString("Could not open file %1!").arg(normalized_fname);
qWarning() << "Reason: " << QString(table.error().what()); qWarning() << "Reason: " << QString(table.error().what());

View File

@ -24,7 +24,6 @@
#include <QUrl> #include <QUrl>
#include <QVariant> #include <QVariant>
struct toml_table_t;
class QDir; class QDir;
// Mod from launcher/minecraft/mod/Mod.h // Mod from launcher/minecraft/mod/Mod.h
@ -34,9 +33,6 @@ namespace Packwiz {
auto getRealIndexName(QDir& index_dir, QString normalized_index_name, bool should_match = false) -> QString; auto getRealIndexName(QDir& index_dir, QString normalized_index_name, bool should_match = false) -> QString;
auto stringEntry(toml_table_t* parent, const char* entry_name) -> QString;
auto intEntry(toml_table_t* parent, const char* entry_name) -> int;
class V1 { class V1 {
public: public:
struct Mod { struct Mod {