Skip to content
8 changes: 8 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ set(CORE_SOURCES
Json.h
Json.cpp

# Toml parsing helpers
Toml.h
Toml.cpp

FileSystem.h
FileSystem.cpp

Expand Down Expand Up @@ -323,6 +327,7 @@ set(MINECRAFT_SOURCES
minecraft/mod/Mod.h
minecraft/mod/Mod.cpp
minecraft/mod/ModDetails.h
minecraft/mod/ModDetails.cpp
minecraft/mod/ModFolderModel.h
minecraft/mod/ModFolderModel.cpp
minecraft/mod/Resource.h
Expand Down Expand Up @@ -419,6 +424,9 @@ set(SETTINGS_SOURCES
settings/Setting.h
settings/SettingsObject.cpp
settings/SettingsObject.h
settings/TomlFile.cpp
settings/TomlFile.h
settings/SettingsFile.h
)

set(JAVA_SOURCES
Expand Down
4 changes: 0 additions & 4 deletions launcher/InstanceList.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ using InstanceId = QString;
using GroupId = QString;
using InstanceLocator = std::pair<InstancePtr, int>;

enum class InstCreateError { NoCreateError = 0, NoSuchVersion, UnknownCreateError, InstExists, CantCreateDir };

enum class GroupsState { NotLoaded, Steady, Dirty };

struct TrashHistoryItem {
QString id;
QString path;
Expand Down
46 changes: 46 additions & 0 deletions launcher/Toml.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2024 Trial97 <alexandru.tripon97@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "Toml.h"

namespace Toml {
QString getString(toml::table table, QString key, QString def)
{
return QString::fromStdString(table[key.toStdString()].value_or(def.toStdString()));
}

QStringList toStringList(toml::array* arr)
{
QStringList list;
if (arr) {
for (auto&& v : *arr) {
list.push_back(QString::fromStdString(v.value_or("")));
}
}
return list;
}

toml::array fromStringList(QStringList list)
{
toml::array arr;
for (auto v : list) {
arr.push_back(v.toStdString());
}
return arr;
}
} // namespace Toml
34 changes: 34 additions & 0 deletions launcher/Toml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2024 Trial97 <alexandru.tripon97@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <QString>
#include <QStringList>

#include <toml++/toml.hpp>

namespace Toml {

QString getString(toml::table table, QString key, QString def = {});

QStringList toStringList(toml::array* arr);

toml::array fromStringList(QStringList list);

} // namespace Toml
2 changes: 1 addition & 1 deletion launcher/minecraft/mod/Mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Mod : public Resource {
auto releaseType() const -> ModPlatform::IndexedVersionType;

/** Get the intneral path to the mod's icon file*/
QString iconPath() const { return m_local_details.icon_file; }
QString iconPath() const { return m_local_details.icon_path; }
/** Gets the icon of the mod, converted to a QPixmap for drawing, and scaled to size. */
[[nodiscard]] QPixmap icon(QSize size, Qt::AspectRatioMode mode = Qt::AspectRatioMode::IgnoreAspectRatio) const;
/** Thread-safe. */
Expand Down
Loading