mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
chore: ensure the setting is saved as string
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -279,4 +279,29 @@ QJsonValue requireIsType<QJsonValue>(const QJsonValue& value, const QString& wha
|
||||
return value;
|
||||
}
|
||||
|
||||
QStringList toStringList(const QString& jsonString)
|
||||
{
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonString.toUtf8(), &parseError);
|
||||
|
||||
if (parseError.error != QJsonParseError::NoError || !doc.isArray())
|
||||
return {};
|
||||
try {
|
||||
return ensureIsArrayOf<QString>(doc.array(), "");
|
||||
} catch (Json::JsonException& e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
QString fromStringList(const QStringList& list)
|
||||
{
|
||||
QJsonArray array;
|
||||
for (const QString& str : list) {
|
||||
array.append(str);
|
||||
}
|
||||
|
||||
QJsonDocument doc(toJsonArray(list));
|
||||
return QString::fromUtf8(doc.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
} // namespace Json
|
||||
|
@ -99,7 +99,7 @@ template <typename T>
|
||||
QJsonArray toJsonArray(const QList<T>& container)
|
||||
{
|
||||
QJsonArray array;
|
||||
for (const T item : container) {
|
||||
for (const T& item : container) {
|
||||
array.append(toJson<T>(item));
|
||||
}
|
||||
return array;
|
||||
@ -278,5 +278,9 @@ JSON_HELPERFUNCTIONS(Variant, QVariant)
|
||||
|
||||
#undef JSON_HELPERFUNCTIONS
|
||||
|
||||
// helper functions for settings
|
||||
QStringList toStringList(const QString& jsonString);
|
||||
QString fromStringList(const QStringList& list);
|
||||
|
||||
} // namespace Json
|
||||
using JSONValidationError = Json::JsonException;
|
||||
|
@ -252,7 +252,7 @@ void MinecraftInstance::loadSpecificSettings()
|
||||
|
||||
// Join server on launch, this does not have a global override
|
||||
m_settings->registerSetting("OverrideModDownloadLoaders", false);
|
||||
m_settings->registerSetting("ModDownloadLoaders", QStringList());
|
||||
m_settings->registerSetting("ModDownloadLoaders", "[]");
|
||||
|
||||
qDebug() << "Instance-type specific settings were loaded!";
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include "Application.h"
|
||||
#include "BuildConfig.h"
|
||||
#include "Json.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/WorldList.h"
|
||||
#include "minecraft/auth/AccountList.h"
|
||||
@ -242,7 +243,7 @@ void MinecraftSettingsWidget::loadSettings()
|
||||
m_ui->liteLoader->blockSignals(true);
|
||||
auto instLoaders = m_instance->getPackProfile()->getSupportedModLoaders().value();
|
||||
m_ui->loaderGroup->setChecked(settings->get("OverrideModDownloadLoaders").toBool());
|
||||
auto loaders = settings->get("ModDownloadLoaders").toStringList();
|
||||
auto loaders = Json::toStringList(settings->get("ModDownloadLoaders").toString());
|
||||
if (loaders.isEmpty()) {
|
||||
m_ui->neoForge->setChecked(instLoaders & ModPlatform::NeoForge);
|
||||
m_ui->forge->setChecked(instLoaders & ModPlatform::Forge);
|
||||
@ -499,5 +500,5 @@ void MinecraftSettingsWidget::selectedLoadersChanged()
|
||||
loaders << getModLoaderAsString(ModPlatform::Quilt);
|
||||
if (m_ui->liteLoader->isChecked())
|
||||
loaders << getModLoaderAsString(ModPlatform::LiteLoader);
|
||||
m_instance->settings()->set("ModDownloadLoaders", loaders);
|
||||
m_instance->settings()->set("ModDownloadLoaders", Json::fromStringList(loaders));
|
||||
}
|
@ -40,6 +40,7 @@
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include "BaseVersionList.h"
|
||||
#include "Json.h"
|
||||
#include "Version.h"
|
||||
#include "meta/Index.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
@ -220,7 +221,7 @@ void ModFilterWidget::prepareBasicFilter()
|
||||
m_filter->side = ""; // or "both"
|
||||
ModPlatform::ModLoaderTypes loaders;
|
||||
if (m_instance->settings()->get("OverrideModDownloadLoaders").toBool()) {
|
||||
for (auto loader : m_instance->settings()->get("ModDownloadLoaders").toStringList()) {
|
||||
for (auto loader : Json::toStringList(m_instance->settings()->get("ModDownloadLoaders").toString())) {
|
||||
loaders |= ModPlatform::getModLoaderFromString(loader);
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user