aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/helpers
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-27 16:57:30 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-07-14 23:34:21 +0300
commit9a3931dac6e75a79989f13b10604a142dbafcfbb (patch)
tree5df84ddc6f9d01c14dd8feeef22c04f056ff1043 /launcher/modplatform/helpers
parent515197fba2da1d674dbe7bd17dae4e0f22f64097 (diff)
downloadPrismLauncher-9a3931dac6e75a79989f13b10604a142dbafcfbb.tar.gz
PrismLauncher-9a3931dac6e75a79989f13b10604a142dbafcfbb.tar.bz2
PrismLauncher-9a3931dac6e75a79989f13b10604a142dbafcfbb.zip
Added json and csv format
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
Diffstat (limited to 'launcher/modplatform/helpers')
-rw-r--r--launcher/modplatform/helpers/ExportToModList.cpp56
-rw-r--r--launcher/modplatform/helpers/ExportToModList.h2
2 files changed, 57 insertions, 1 deletions
diff --git a/launcher/modplatform/helpers/ExportToModList.cpp b/launcher/modplatform/helpers/ExportToModList.cpp
index d837fb0b..86bb9c41 100644
--- a/launcher/modplatform/helpers/ExportToModList.cpp
+++ b/launcher/modplatform/helpers/ExportToModList.cpp
@@ -16,6 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ExportToModList.h"
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
namespace ExportToModList {
QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData)
@@ -94,6 +97,59 @@ QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData
}
return lines.join("\n");
}
+ case JSON: {
+ QJsonArray lines;
+ for (auto mod : mods) {
+ auto meta = mod->metadata();
+ auto modName = mod->name();
+ QJsonObject line;
+ line["name"] = modName;
+ if (extraData & Url) {
+ auto url = mod->metaurl();
+ if (!url.isEmpty())
+ line["url"] = url;
+ }
+ if (extraData & Version) {
+ auto ver = mod->version();
+ if (ver.isEmpty() && meta != nullptr)
+ ver = meta->version().toString();
+ if (!ver.isEmpty())
+ line["version"] = ver;
+ }
+ if (extraData & Authors && !mod->authors().isEmpty())
+ line["authors"] = QJsonArray::fromStringList(mod->authors());
+ lines << line;
+ }
+ QJsonDocument doc;
+ doc.setArray(lines);
+ return doc.toJson();
+ }
+ case CSV: {
+ QStringList lines;
+ for (auto mod : mods) {
+ QStringList data;
+ auto meta = mod->metadata();
+ auto modName = mod->name();
+
+ data << modName;
+ if (extraData & Url) {
+ auto url = mod->metaurl();
+ if (!url.isEmpty())
+ data << url;
+ }
+ if (extraData & Version) {
+ auto ver = mod->version();
+ if (ver.isEmpty() && meta != nullptr)
+ ver = meta->version().toString();
+ if (!ver.isEmpty())
+ data << ver;
+ }
+ if (extraData & Authors && !mod->authors().isEmpty())
+ data << QString("\"%1\"").arg(mod->authors().join(","));
+ lines << data.join(",");
+ }
+ return lines.join("\n");
+ }
default: {
return QString("unknown format:%1").arg(format);
}
diff --git a/launcher/modplatform/helpers/ExportToModList.h b/launcher/modplatform/helpers/ExportToModList.h
index 9ff8d25a..abd6e9bc 100644
--- a/launcher/modplatform/helpers/ExportToModList.h
+++ b/launcher/modplatform/helpers/ExportToModList.h
@@ -22,7 +22,7 @@
namespace ExportToModList {
-enum Formats { HTML, MARKDOWN, PLAINTXT, CUSTOM };
+enum Formats { HTML, MARKDOWN, PLAINTXT, JSON, CSV, CUSTOM };
enum OptionalData {
Authors = 1 << 0,
Url = 1 << 1,