aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules5
-rw-r--r--CMakeLists.txt12
-rw-r--r--COPYING.md30
-rw-r--r--flake.lock19
-rw-r--r--flake.nix7
-rw-r--r--launcher/CMakeLists.txt2
-rw-r--r--launcher/minecraft/mod/tasks/LocalModParseTask.cpp263
-rw-r--r--launcher/modplatform/packwiz/Packwiz.cpp156
-rw-r--r--libraries/README.md16
-rw-r--r--libraries/tomlc99/CMakeLists.txt10
-rw-r--r--libraries/tomlc99/LICENSE22
-rw-r--r--libraries/tomlc99/README.md197
-rw-r--r--libraries/tomlc99/include/toml.h175
-rw-r--r--libraries/tomlc99/src/toml.c2300
m---------libraries/tomlplusplus0
-rw-r--r--nix/default.nix6
16 files changed, 227 insertions, 2993 deletions
diff --git a/.gitmodules b/.gitmodules
index 08b94c96..534ffd37 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,8 +1,9 @@
[submodule "depends/libnbtplusplus"]
path = libraries/libnbtplusplus
url = https://github.com/PolyMC/libnbtplusplus.git
- pushurl = git@github.com:PolyMC/libnbtplusplus.git
-
[submodule "libraries/quazip"]
path = libraries/quazip
url = https://github.com/stachenov/quazip.git
+[submodule "libraries/tomlplusplus"]
+ path = libraries/tomlplusplus
+ url = https://github.com/marzer/tomlplusplus.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7100ab1b..46192414 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -192,6 +192,11 @@ if (Qt5_POSITION_INDEPENDENT_CODE)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
+# Find toml++
+if(NOT Launcher_FORCE_BUNDLED_LIBS)
+ find_package(tomlplusplus 3.2.0 QUIET)
+endif()
+
####################################### Program Info #######################################
set(Launcher_APP_BINARY_NAME "polymc" CACHE STRING "Name of the Launcher binary")
@@ -312,7 +317,12 @@ endif()
add_subdirectory(libraries/rainbow) # Qt extension for colors
add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions
add_subdirectory(libraries/classparser) # class parser library
-add_subdirectory(libraries/tomlc99) # toml parser
+if(NOT tomlplusplus_FOUND)
+ message(STATUS "Using bundled tomlplusplus")
+ add_subdirectory(libraries/tomlplusplus) # toml parser
+else()
+ message(STATUS "Using system tomlplusplus")
+endif()
add_subdirectory(libraries/katabasis) # An OAuth2 library that tried to do too much
add_subdirectory(libraries/gamemode)
add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API
diff --git a/COPYING.md b/COPYING.md
index c94c51c3..11c1fc3a 100644
--- a/COPYING.md
+++ b/COPYING.md
@@ -315,30 +315,24 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-## tomlc99
+## tomlplusplus
MIT License
- Copyright (c) 2017 CK Tan
- https://github.com/cktan/tomlc99
+ Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
+ Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## O2 (Katabasis fork)
diff --git a/flake.lock b/flake.lock
index bfc9ac6d..a72286bb 100644
--- a/flake.lock
+++ b/flake.lock
@@ -52,7 +52,24 @@
"inputs": {
"flake-compat": "flake-compat",
"libnbtplusplus": "libnbtplusplus",
- "nixpkgs": "nixpkgs"
+ "nixpkgs": "nixpkgs",
+ "tomlplusplus": "tomlplusplus"
+ }
+ },
+ "tomlplusplus": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1664034574,
+ "narHash": "sha256-EFMAl6tsTvkgK0DWC/pZfOIq06b2e5SnxJa1ngGRIQA=",
+ "owner": "marzer",
+ "repo": "tomlplusplus",
+ "rev": "8aa5c8b2a4ff2c440d4630addf64fa4f62146170",
+ "type": "github"
+ },
+ "original": {
+ "owner": "marzer",
+ "repo": "tomlplusplus",
+ "type": "github"
}
}
},
diff --git a/flake.nix b/flake.nix
index 51bc1fda..93192725 100644
--- a/flake.nix
+++ b/flake.nix
@@ -5,9 +5,10 @@
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
libnbtplusplus = { url = "github:PolyMC/libnbtplusplus"; flake = false; };
+ tomlplusplus = { url = "github:marzer/tomlplusplus"; flake = false; };
};
- outputs = { self, nixpkgs, libnbtplusplus, ... }:
+ outputs = { self, nixpkgs, libnbtplusplus, tomlplusplus, ... }:
let
# User-friendly version number.
version = builtins.substring 0 8 self.lastModifiedDate;
@@ -22,8 +23,8 @@
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
packagesFn = pkgs: rec {
- polymc = pkgs.libsForQt5.callPackage ./nix { inherit version self libnbtplusplus; };
- polymc-qt6 = pkgs.qt6Packages.callPackage ./nix { inherit version self libnbtplusplus; };
+ polymc = pkgs.libsForQt5.callPackage ./nix { inherit version self libnbtplusplus tomlplusplus; };
+ polymc-qt6 = pkgs.qt6Packages.callPackage ./nix { inherit version self libnbtplusplus tomlplusplus; };
};
in
{
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 2ff700ad..0bdfcd44 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -973,7 +973,7 @@ target_link_libraries(Launcher_logic
Launcher_murmur2
nbt++
${ZLIB_LIBRARIES}
- tomlc99
+ tomlplusplus::tomlplusplus
BuildConfig
Katabasis
Qt${QT_VERSION_MAJOR}::Widgets
diff --git a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp
index 8a6e54d8..a694e7b2 100644
--- a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp
+++ b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp
@@ -1,17 +1,17 @@
#include "LocalModParseTask.h"
+#include <quazip/quazip.h>
+#include <quazip/quazipfile.h>
+#include <toml++/toml.h>
+#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
-#include <QJsonArray>
#include <QJsonValue>
#include <QString>
-#include <quazip/quazip.h>
-#include <quazip/quazipfile.h>
-#include <toml.h>
+#include "FileSystem.h"
#include "Json.h"
#include "settings/INIFile.h"
-#include "FileSystem.h"
namespace {
@@ -22,8 +22,7 @@ namespace {
// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc
ModDetails ReadMCModInfo(QByteArray contents)
{
- auto getInfoFromArray = [&](QJsonArray arr) -> ModDetails
- {
+ auto getInfoFromArray = [&](QJsonArray arr) -> ModDetails {
if (!arr.at(0).isObject()) {
return {};
}
@@ -32,16 +31,14 @@ ModDetails ReadMCModInfo(QByteArray contents)
details.mod_id = firstObj.value("modid").toString();
auto name = firstObj.value("name").toString();
// NOTE: ignore stupid example mods copies where the author didn't even bother to change the name
- if(name != "Example Mod") {
+ if (name != "Example Mod") {
details.name = name;
}
details.version = firstObj.value("version").toString();
auto homeurl = firstObj.value("url").toString().trimmed();
- if(!homeurl.isEmpty())
- {
+ if (!homeurl.isEmpty()) {
// fix up url.
- if (!homeurl.startsWith("http://") && !homeurl.startsWith("https://") && !homeurl.startsWith("ftp://"))
- {
+ if (!homeurl.startsWith("http://") && !homeurl.startsWith("https://") && !homeurl.startsWith("ftp://")) {
homeurl.prepend("http://");
}
}
@@ -53,8 +50,7 @@ ModDetails ReadMCModInfo(QByteArray contents)
authors = firstObj.value("authors").toArray();
}
- for (auto author: authors)
- {
+ for (auto author : authors) {
details.authors.append(author.toString());
}
return details;
@@ -62,14 +58,11 @@ ModDetails ReadMCModInfo(QByteArray contents)
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
// this is the very old format that had just the array
- if (jsonDoc.isArray())
- {
+ if (jsonDoc.isArray()) {
return getInfoFromArray(jsonDoc.array());
- }
- else if (jsonDoc.isObject())
- {
+ } else if (jsonDoc.isObject()) {
auto val = jsonDoc.object().value("modinfoversion");
- if(val.isUndefined()) {
+ if (val.isUndefined()) {
val = jsonDoc.object().value("modListVersion");
}
@@ -79,18 +72,16 @@ ModDetails ReadMCModInfo(QByteArray contents)
if (version < 0)
version = Json::ensureString(val, "").toInt();
- if (version != 2)
- {
+ if (version != 2) {
qCritical() << "BAD stuff happened to mod json:";
qCritical() << contents;
return {};
}
auto arrVal = jsonDoc.object().value("modlist");
- if(arrVal.isUndefined()) {
+ if (arrVal.isUndefined()) {
arrVal = jsonDoc.object().value("modList");
}
- if (arrVal.isArray())
- {
+ if (arrVal.isArray()) {
return getInfoFromArray(arrVal.toArray());
}
}
@@ -102,109 +93,76 @@ ModDetails ReadMCModTOML(QByteArray contents)
{
ModDetails details;
- char errbuf[200];
- // top-level table
- toml_table_t* tomlData = toml_parse(contents.data(), errbuf, sizeof(errbuf));
-
- if(!tomlData)
- {
+ toml::table tomlData;
+#if TOML_EXCEPTIONS
+ try {
+ tomlData = toml::parse(contents.toStdString());
+ } catch (const toml::parse_error& err) {
+ return {};
+ }
+#else
+ tomlData = toml::parse(contents.toStdString());
+ if (!tomlData) {
return {};
}
+#endif
// array defined by [[mods]]
- toml_array_t* tomlModsArr = toml_array_in(tomlData, "mods");
- if(!tomlModsArr)
- {
+ auto tomlModsArr = tomlData["mods"].as_array();
+ if (!tomlModsArr) {
qWarning() << "Corrupted mods.toml? Couldn't find [[mods]] array!";
return {};
}
// we only really care about the first element, since multiple mods in one file is not supported by us at the moment
- toml_table_t* tomlModsTable0 = toml_table_at(tomlModsArr, 0);
- if(!tomlModsTable0)
- {
+ auto tomlModsTable0 = tomlModsArr->get(0);
+ if (!tomlModsTable0) {
qWarning() << "Corrupted mods.toml? [[mods]] didn't have an element at index 0!";
return {};
}
+ auto modsTable = tomlModsTable0->as_table();
+ if (!tomlModsTable0) {
+ qWarning() << "Corrupted mods.toml? [[mods]] was not a table!";
+ return {};
+ }
// mandatory properties - always in [[mods]]
- toml_datum_t modIdDatum = toml_string_in(tomlModsTable0, "modId");
- if(modIdDatum.ok)
- {
- details.mod_id = modIdDatum.u.s;
- // library says this is required for strings
- free(modIdDatum.u.s);
+ if (auto modIdDatum = (*modsTable)["modId"].as_string()) {
+ details.mod_id = QString::fromStdString(modIdDatum->get());
}
- toml_datum_t versionDatum = toml_string_in(tomlModsTable0, "version");
- if(versionDatum.ok)
- {
- details.version = versionDatum.u.s;
- free(versionDatum.u.s);
+ if (auto versionDatum = (*modsTable)["version"].as_string()) {
+ details.version = QString::fromStdString(versionDatum->get());
}
- toml_datum_t displayNameDatum = toml_string_in(tomlModsTable0, "displayName");
- if(displayNameDatum.ok)
- {
- details.name = displayNameDatum.u.s;
- free(displayNameDatum.u.s);
+ if (auto displayNameDatum = (*modsTable)["displayName"].as_string()) {
+ details.name = QString::fromStdString(displayNameDatum->get());
}
- toml_datum_t descriptionDatum = toml_string_in(tomlModsTable0, "description");
- if(descriptionDatum.ok)
- {
- details.description = descriptionDatum.u.s;
- free(descriptionDatum.u.s);
+ if (auto descriptionDatum = (*modsTable)["description"].as_string()) {
+ details.description = QString::fromStdString(descriptionDatum->get());
}
// optional properties - can be in the root table or [[mods]]
- toml_datum_t authorsDatum = toml_string_in(tomlData, "authors");
QString authors = "";
- if(authorsDatum.ok)
- {
- authors = authorsDatum.u.s;
- free(authorsDatum.u.s);
- }
- else
- {
- authorsDatum = toml_string_in(tomlModsTable0, "authors");
- if(authorsDatum.ok)
- {
- authors = authorsDatum.u.s;
- free(authorsDatum.u.s);
- }
+ if (auto authorsDatum = tomlData["authors"].as_string()) {
+ authors = QString::fromStdString(authorsDatum->get());
+ } else if (auto authorsDatum = (*modsTable)["authors"].as_string()) {
+ authors = QString::fromStdString(authorsDatum->get());
}
- if(!authors.isEmpty())
- {
+ if (!authors.isEmpty()) {
details.authors.append(authors);
}
- toml_datum_t homeurlDatum = toml_string_in(tomlData, "displayURL");
QString homeurl = "";
- if(homeurlDatum.ok)
- {
- homeurl = homeurlDatum.u.s;
- free(homeurlDatum.u.s);
- }
- else
- {
- homeurlDatum = toml_string_in(tomlModsTable0, "displayURL");
- if(homeurlDatum.ok)
- {
- homeurl = homeurlDatum.u.s;
- free(homeurlDatum.u.s);
- }
+ if (auto homeurlDatum = tomlData["displayURL"].as_string()) {
+ homeurl = QString::fromStdString(homeurlDatum->get());
+ } else if (auto homeurlDatum = (*modsTable)["displayURL"].as_string()) {
+ homeurl = QString::fromStdString(homeurlDatum->get());
}
- if(!homeurl.isEmpty())
- {
- // fix up url.
- if (!homeurl.startsWith("http://") && !homeurl.startsWith("https://") && !homeurl.startsWith("ftp://"))
- {
- homeurl.prepend("http://");
- }
+ // fix up url.
+ if (!homeurl.isEmpty() && !homeurl.startsWith("http://") && !homeurl.startsWith("https://") && !homeurl.startsWith("ftp://")) {
+ homeurl.prepend("http://");
}
details.homeurl = homeurl;
- // this seems to be recursive, so it should free everything
- toml_free(tomlData);
-
return details;
}
@@ -224,25 +182,20 @@ ModDetails ReadFabricModInfo(QByteArray contents)
details.name = object.contains("name") ? object.value("name").toString() : details.mod_id;
details.description = object.value("description").toString();
- if (schemaVersion >= 1)
- {
+ if (schemaVersion >= 1) {
QJsonArray authors = object.value("authors").toArray();
- for (auto author: authors)
- {
- if(author.isObject()) {
+ for (auto author : authors) {
+ if (author.isObject()) {
details.authors.append(author.toObject().value("name").toString());
- }
- else {
+ } else {
details.authors.append(author.toString());
}
}
- if (object.contains("contact"))
- {
+ if (object.contains("contact")) {
QJsonObject contact = object.value("contact").toObject();
- if (contact.contains("homepage"))
- {
+ if (contact.contains("homepage")) {
details.homeurl = contact.value("homepage").toString();
}
}
@@ -261,8 +214,7 @@ ModDetails ReadQuiltModInfo(QByteArray contents)
ModDetails details;
// https://github.com/QuiltMC/rfcs/blob/be6ba280d785395fefa90a43db48e5bfc1d15eb4/specification/0002-quilt.mod.json.md
- if (schemaVersion == 1)
- {
+ if (schemaVersion == 1) {
auto modInfo = Json::requireObject(object.value("quilt_loader"), "Quilt mod info");
details.mod_id = Json::requireString(modInfo.value("id"), "Mod ID");
@@ -280,8 +232,7 @@ ModDetails ReadQuiltModInfo(QByteArray contents)
auto modContact = Json::ensureObject(modMetadata.value("contact"));
- if (modContact.contains("homepage"))
- {
+ if (modContact.contains("homepage")) {
details.homeurl = Json::requireString(modContact.value("homepage"));
}
}
@@ -314,21 +265,17 @@ ModDetails ReadLiteModInfo(QByteArray contents)
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
auto object = jsonDoc.object();
- if (object.contains("name"))
- {
+ if (object.contains("name")) {
details.mod_id = details.name = object.value("name").toString();
}
- if (object.contains("version"))
- {
+ if (object.contains("version")) {
details.version = object.value("version").toString("");
- }
- else
- {
+ } else {
details.version = object.value("revision").toString("");
}
details.mcversion = object.value("mcversion").toString();
auto author = object.value("author").toString();
- if(!author.isEmpty()) {
+ if (!author.isEmpty()) {
details.authors.append(author);
}
details.description = object.value("description").toString();
@@ -336,14 +283,10 @@ ModDetails ReadLiteModInfo(QByteArray contents)
return details;
}
-}
+} // namespace
-LocalModParseTask::LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile):
- Task(nullptr, false),
- m_token(token),
- m_type(type),
- m_modFile(modFile),
- m_result(new Result())
+LocalModParseTask::LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile)
+ : Task(nullptr, false), m_token(token), m_type(type), m_modFile(modFile), m_result(new Result())
{}
void LocalModParseTask::processAsZip()
@@ -354,10 +297,8 @@ void LocalModParseTask::processAsZip()
QuaZipFile file(&zip);
- if (zip.setCurrentFile("META-INF/mods.toml"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ if (zip.setCurrentFile("META-INF/mods.toml")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -366,12 +307,9 @@ void LocalModParseTask::processAsZip()
file.close();
// to replace ${file.jarVersion} with the actual version, as needed
- if (m_result->details.version == "${file.jarVersion}")
- {
- if (zip.setCurrentFile("META-INF/MANIFEST.MF"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ if (m_result->details.version == "${file.jarVersion}") {
+ if (zip.setCurrentFile("META-INF/MANIFEST.MF")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -379,10 +317,8 @@ void LocalModParseTask::processAsZip()
// quick and dirty line-by-line parser
auto manifestLines = file.readAll().split('\n');
QString manifestVersion = "";
- for (auto &line : manifestLines)
- {
- if (QString(line).startsWith("Implementation-Version: "))
- {
+ for (auto& line : manifestLines) {
+ if (QString(line).startsWith("Implementation-Version: ")) {
manifestVersion = QString(line).remove("Implementation-Version: ");
break;
}
@@ -390,8 +326,7 @@ void LocalModParseTask::processAsZip()
// some mods use ${projectversion} in their build.gradle, causing this mess to show up in MANIFEST.MF
// also keep with forge's behavior of setting the version to "NONE" if none is found
- if (manifestVersion.contains("task ':jar' property 'archiveVersion'") || manifestVersion == "")
- {
+ if (manifestVersion.contains("task ':jar' property 'archiveVersion'") || manifestVersion == "") {
manifestVersion = "NONE";
}
@@ -403,11 +338,8 @@ void LocalModParseTask::processAsZip()
zip.close();
return;
- }
- else if (zip.setCurrentFile("mcmod.info"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ } else if (zip.setCurrentFile("mcmod.info")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -416,11 +348,8 @@ void LocalModParseTask::processAsZip()
file.close();
zip.close();
return;
- }
- else if (zip.setCurrentFile("quilt.mod.json"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ } else if (zip.setCurrentFile("quilt.mod.json")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -429,11 +358,8 @@ void LocalModParseTask::processAsZip()
file.close();
zip.close();
return;
- }
- else if (zip.setCurrentFile("fabric.mod.json"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ } else if (zip.setCurrentFile("fabric.mod.json")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -442,11 +368,8 @@ void LocalModParseTask::processAsZip()
file.close();
zip.close();
return;
- }
- else if (zip.setCurrentFile("forgeversion.properties"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ } else if (zip.setCurrentFile("forgeversion.properties")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -463,8 +386,7 @@ void LocalModParseTask::processAsZip()
void LocalModParseTask::processAsFolder()
{
QFileInfo mcmod_info(FS::PathCombine(m_modFile.filePath(), "mcmod.info"));
- if (mcmod_info.isFile())
- {
+ if (mcmod_info.isFile()) {
QFile mcmod(mcmod_info.filePath());
if (!mcmod.open(QIODevice::ReadOnly))
return;
@@ -483,10 +405,8 @@ void LocalModParseTask::processAsLitemod()
QuaZipFile file(&zip);
- if (zip.setCurrentFile("litemod.json"))
- {
- if (!file.open(QIODevice::ReadOnly))
- {
+ if (zip.setCurrentFile("litemod.json")) {
+ if (!file.open(QIODevice::ReadOnly)) {
zip.close();
return;
}
@@ -505,8 +425,7 @@ bool LocalModParseTask::abort()
void LocalModParseTask::executeTask()
{
- switch(m_type)
- {
+ switch (m_type) {
case ResourceType::ZIPFILE:
processAsZip();
break;
diff --git a/launcher/modplatform/packwiz/Packwiz.cpp b/launcher/modplatform/packwiz/Packwiz.cpp
index c3561093..b1fe963e 100644
--- a/launcher/modplatform/packwiz/Packwiz.cpp
+++ b/launcher/modplatform/packwiz/Packwiz.cpp
@@ -1,20 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
-* PolyMC - Minecraft Launcher
-* Copyright (c) 2022 flowln <flowlnlnln@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/>.
-*/
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@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 "Packwiz.h"
@@ -22,9 +22,7 @@
#include <QDir>
#include <QObject>
-#include "toml.h"
-#include "FileSystem.h"
-
+#include <toml++/toml.h>
#include "minecraft/mod/Mod.h"
#include "modplatform/ModIndex.h"
@@ -44,7 +42,7 @@ auto getRealIndexName(QDir& index_dir, QString normalized_fname, bool should_fin
}
}
- if(should_find_match && !QString::compare(normalized_fname, real_fname, Qt::CaseSensitive)){
+ if (should_find_match && !QString::compare(normalized_fname, real_fname, Qt::CaseSensitive)) {
qCritical() << "Could not find a match for a valid metadata file!";
qCritical() << "File: " << normalized_fname;
return {};
@@ -57,7 +55,7 @@ auto getRealIndexName(QDir& index_dir, QString normalized_fname, bool should_fin
// Helpers
static inline auto indexFileName(QString const& mod_slug) -> QString
{
- if(mod_slug.endsWith(".pw.toml"))
+ if (mod_slug.endsWith(".pw.toml"))
return mod_slug;
return QString("%1.pw.toml").arg(mod_slug);
}
@@ -65,32 +63,28 @@ static inline auto indexFileName(QString const& mod_slug) -> QString
static ModPlatform::ProviderCapabilities ProviderCaps;
// Helper functions for extracting data from the TOML file
-auto stringEntry(toml_table_t* parent, const char* entry_name) -> QString
+auto stringEntry(toml::table table, const std::string entry_name) -> QString
{
- toml_datum_t var = toml_string_in(parent, entry_name);
- if (!var.ok) {
- qCritical() << QString("Failed to read str property '%1' in mod metadata.").arg(entry_name);
+ auto node = table[entry_name];
+ if (!node) {
+ qCritical() << QString::fromStdString("Failed to read str property '" + entry_name + "' in mod metadata.");
return {};
}
- QString tmp = var.u.s;
- free(var.u.s);
-
- return tmp;
+ return QString::fromStdString(node.value_or(""));
}
-auto intEntry(toml_table_t* parent, const char* entry_name) -> int
+auto intEntry(toml::table table, const std::string entry_name) -> int
{
- toml_datum_t var = toml_int_in(parent, entry_name);
- if (!var.ok) {
- qCritical() << QString("Failed to read int property '%1' in mod metadata.").arg(entry_name);
+ auto node = table[entry_name];
+ if (!node) {
+ qCritical() << QString::fromStdString("Failed to read int property '" + entry_name + "' in mod metadata.");
return {};
}
- return var.u.i;
+ return node.value_or(0);
}
-
auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod
{
Mod mod;
@@ -99,10 +93,9 @@ auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, Mo
mod.name = mod_pack.name;
mod.filename = mod_version.fileName;
- if(mod_pack.provider == ModPlatform::Provider::FLAME){
+ if (mod_pack.provider == ModPlatform::Provider::FLAME) {
mod.mode = "metadata:curseforge";
- }
- else {
+ } else {
mod.mode = "url";
mod.url = mod_version.downloadUrl;
}
@@ -120,8 +113,8 @@ auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, Mo
auto V1::createModFormat(QDir& index_dir, ::Mod& internal_mod, QString slug) -> Mod
{
// Try getting metadata if it exists
- Mod mod { getIndexForMod(index_dir, slug) };
- if(mod.isValid())
+ Mod mod{ getIndexForMod(index_dir, slug) };
+ if (mod.isValid())
return mod;
qWarning() << QString("Tried to create mod metadata with a Mod without metadata!");
@@ -131,7 +124,7 @@ auto V1::createModFormat(QDir& index_dir, ::Mod& internal_mod, QString slug) ->
void V1::updateModIndex(QDir& index_dir, Mod& mod)
{
- if(!mod.isValid()){
+ if (!mod.isValid()) {
qCritical() << QString("Tried to update metadata of an invalid mod!");
return;
}
@@ -150,7 +143,9 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
// TODO: We should do more stuff here, as the user is likely trying to
// override a file. In this case, check versions and ask the user what
// they want to do!
- if (index_file.exists()) { index_file.remove(); }
+ if (index_file.exists()) {
+ index_file.remove();
+ }
if (!index_file.open(QIODevice::ReadWrite)) {
qCritical() << QString("Could not open file %1!").arg(indexFileName(mod.name));
@@ -174,15 +169,15 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
in_stream << QString("\n[update]\n");
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());
- in_stream << QString("project-id = %1\n").arg(mod.project_id.toString());
- break;
- case(ModPlatform::Provider::MODRINTH):
- addToStream("mod-id", mod.mod_id().toString());
- addToStream("version", mod.version().toString());
- break;
+ switch (mod.provider) {
+ case (ModPlatform::Provider::FLAME):
+ in_stream << QString("file-id = %1\n").arg(mod.file_id.toString());
+ in_stream << QString("project-id = %1\n").arg(mod.project_id.toString());
+ break;
+ case (ModPlatform::Provider::MODRINTH):
+ addToStream("mod-id", mod.mod_id().toString());
+ addToStream("version", mod.version().toString());
+ break;
}
}
@@ -230,27 +225,25 @@ auto V1::getIndexForMod(QDir& index_dir, QString slug) -> Mod
if (real_fname.isEmpty())
return {};
- QFile index_file(index_dir.absoluteFilePath(real_fname));
-
- if (!index_file.open(QIODevice::ReadOnly)) {
- qWarning() << QString("Failed to open mod metadata for %1").arg(slug);
+ toml::table table;
+#if TOML_EXCEPTIONS
+ try {
+ table = toml::parse_file(index_dir.absoluteFilePath(real_fname).toStdString());
+ } catch (const toml::parse_error& err) {
+ qWarning() << QString("Could not open file %1!").arg(normalized_fname);
+ qWarning() << "Reason: " << QString(err.what());
return {};
}
-
- toml_table_t* table = nullptr;
-
- // NOLINTNEXTLINE(modernize-avoid-c-arrays)
- char errbuf[200];
- auto file_bytearray = index_file.readAll();
- table = toml_parse(file_bytearray.data(), errbuf, sizeof(errbuf));
-
- index_file.close();
-
+#else
+ table = toml::parse_file(index_dir.absoluteFilePath(real_fname).toStdString());
if (!table) {
qWarning() << QString("Could not open file %1!").arg(normalized_fname);
- qWarning() << "Reason: " << QString(errbuf);
+ qWarning() << "Reason: " << QString(table.error().what());
return {};
}
+#endif
+
+ // index_file.close();
mod.slug = slug;
@@ -261,45 +254,42 @@ auto V1::getIndexForMod(QDir& index_dir, QString slug) -> Mod
}
{ // [download] info
- toml_table_t* download_table = toml_table_in(table, "download");
+ auto download_table = table["download"].as_table();
if (!download_table) {
qCritical() << QString("No [download] section found on mod metadata!");
return {};
}