aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/helpers
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-22 16:00:45 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-06-22 16:07:55 +0300
commit9d2516a199ae4c33f773ab00ce59ecb2a6dfd0a5 (patch)
tree0d3534bd7da20122bfffec5ac032f1fe0d0a9184 /launcher/modplatform/helpers
parent2e82c1d40cd43aef4745726d51dd6a9df2d8f78b (diff)
downloadPrismLauncher-9d2516a199ae4c33f773ab00ce59ecb2a6dfd0a5.tar.gz
PrismLauncher-9d2516a199ae4c33f773ab00ce59ecb2a6dfd0a5.tar.bz2
PrismLauncher-9d2516a199ae4c33f773ab00ce59ecb2a6dfd0a5.zip
Added ExportModsToStringTask
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
Diffstat (limited to 'launcher/modplatform/helpers')
-rw-r--r--launcher/modplatform/helpers/ExportModsToStringTask.cpp114
-rw-r--r--launcher/modplatform/helpers/ExportModsToStringTask.h33
2 files changed, 147 insertions, 0 deletions
diff --git a/launcher/modplatform/helpers/ExportModsToStringTask.cpp b/launcher/modplatform/helpers/ExportModsToStringTask.cpp
new file mode 100644
index 00000000..a105fc35
--- /dev/null
+++ b/launcher/modplatform/helpers/ExportModsToStringTask.cpp
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 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 "ExportModsToStringTask.h"
+#include "modplatform/ModIndex.h"
+
+namespace ExportToString {
+QString ExportModsToStringTask(QList<Mod*> mods, Formats format, OptionalData extraData)
+{
+ switch (format) {
+ case HTML: {
+ QStringList lines;
+ for (auto mod : mods) {
+ auto meta = mod->metadata();
+ auto modName = mod->name();
+ if (extraData & Url) {
+ auto url = mod->homeurl();
+ if (meta != nullptr) {
+ url = (meta->provider == ModPlatform::ResourceProvider::FLAME ? "https://www.curseforge.com/minecraft/mc-mods/"
+ : "https://modrinth.com/mod/") +
+ meta->project_id.toString();
+ }
+ if (!url.isEmpty())
+ modName = QString("<a href=\"%1\">%2</a>").arg(url, modName);
+ }
+ auto line = modName;
+ if (extraData & Version) {
+ auto ver = mod->version();
+ if (ver.isEmpty() && meta != nullptr)
+ ver = meta->version().toString();
+ if (!ver.isEmpty())
+ line += QString("[%1]").arg(ver);
+ }
+ if (extraData & Authors && !mod->authors().isEmpty())
+ line += " by " + mod->authors().join(", ");
+ lines.append(QString("<ul>%1</ul>").arg(line));
+ }
+ return QString("<html><body>\n\t%1\n</body></html>").arg(lines.join("\n\t"));
+ }
+ case MARKDOWN: {
+ QStringList lines;
+ for (auto mod : mods) {
+ auto meta = mod->metadata();
+ auto modName = mod->name();
+ if (extraData & Url) {
+ auto url = mod->homeurl();
+ if (meta != nullptr) {
+ url = (meta->provider == ModPlatform::ResourceProvider::FLAME ? "https://www.curseforge.com/minecraft/mc-mods/"
+ : "https://modrinth.com/mod/") +
+ meta->project_id.toString();
+ }
+ if (!url.isEmpty())
+ modName = QString("[%1](%2)").arg(modName, url);
+ }
+ auto line = modName;
+ if (extraData & Version) {
+ auto ver = mod->version();
+ if (ver.isEmpty() && meta != nullptr)
+ ver = meta->version().toString();
+ if (!ver.isEmpty())
+ line += QString("[%1]").arg(ver);
+ }
+ if (extraData & Authors && !mod->authors().isEmpty())
+ line += " by " + mod->authors().join(", ");
+ lines << line;
+ }
+ return lines.join("\n");
+ }
+ default: {
+ return QString("unknown format:%1").arg(format);
+ }
+ }
+}
+
+QString ExportModsToStringTask(QList<Mod*> mods, QString lineTemplate)
+{
+ QStringList lines;
+ for (auto mod : mods) {
+ auto meta = mod->metadata();
+ auto modName = mod->name();
+
+ auto url = mod->homeurl();
+ if (meta != nullptr) {
+ url = (meta->provider == ModPlatform::ResourceProvider::FLAME ? "https://www.curseforge.com/minecraft/mc-mods/"
+ : "https://modrinth.com/mod/") +
+ meta->project_id.toString();
+ }
+ auto ver = mod->version();
+ if (ver.isEmpty() && meta != nullptr)
+ ver = meta->version().toString();
+ auto authors = mod->authors().join(", ");
+ lines << QString(lineTemplate)
+ .replace("{name}", modName)
+ .replace("{url}", url)
+ .replace("{version}", ver)
+ .replace("{authors}", authors);
+ }
+ return lines.join("\n");
+}
+} // namespace ExportToString \ No newline at end of file
diff --git a/launcher/modplatform/helpers/ExportModsToStringTask.h b/launcher/modplatform/helpers/ExportModsToStringTask.h
new file mode 100644
index 00000000..756c69f7
--- /dev/null
+++ b/launcher/modplatform/helpers/ExportModsToStringTask.h
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (c) 2023 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 <qlist.h>
+#include <QString>
+#include "minecraft/mod/Mod.h"
+
+namespace ExportToString {
+
+enum Formats { HTML, MARKDOWN };
+enum OptionalData {
+ Authors = 1 << 0,
+ Url = 1 << 1,
+ Version = 1 << 2,
+};
+QString ExportModsToStringTask(QList<Mod*> mods, Formats format, OptionalData extraData);
+QString ExportModsToStringTask(QList<Mod*> mods, QString lineTemplate);
+} // namespace ExportToString