summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/JarMod.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-05-09 17:16:25 +0200
committerPetr Mrázek <peterix@gmail.com>2014-06-09 01:38:30 +0200
commit9860d5ee12acde8f7893848dac53f59ea66da281 (patch)
tree966e1d9ba1bbb1d4303bfc742faaaccd0957de8f /logic/minecraft/JarMod.cpp
parent8a3a0f5a529a95c7511436051b63887dff158c50 (diff)
downloadMultiMC-9860d5ee12acde8f7893848dac53f59ea66da281.tar
MultiMC-9860d5ee12acde8f7893848dac53f59ea66da281.tar.gz
MultiMC-9860d5ee12acde8f7893848dac53f59ea66da281.tar.lz
MultiMC-9860d5ee12acde8f7893848dac53f59ea66da281.tar.xz
MultiMC-9860d5ee12acde8f7893848dac53f59ea66da281.zip
Introducing VersionPatch base class for version files and minecraft versions
Diffstat (limited to 'logic/minecraft/JarMod.cpp')
-rw-r--r--logic/minecraft/JarMod.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/logic/minecraft/JarMod.cpp b/logic/minecraft/JarMod.cpp
new file mode 100644
index 00000000..99a30aa5
--- /dev/null
+++ b/logic/minecraft/JarMod.cpp
@@ -0,0 +1,44 @@
+#include "JarMod.h"
+#include "logic/MMCJson.h"
+
+JarmodPtr Jarmod::fromJson(const QJsonObject &libObj, const QString &filename)
+{
+ JarmodPtr out(new Jarmod());
+ if (!libObj.contains("name"))
+ {
+ throw JSONValidationError(filename +
+ "contains a jarmod that doesn't have a 'name' field");
+ }
+ out->name = libObj.value("name").toString();
+
+ auto readString = [libObj, filename](const QString & key, QString & variable)
+ {
+ if (libObj.contains(key))
+ {
+ QJsonValue val = libObj.value(key);
+ if (!val.isString())
+ {
+ QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
+ }
+ else
+ {
+ variable = val.toString();
+ }
+ }
+ };
+
+ readString("url", out->baseurl);
+ readString("MMC-absoluteUrl", out->absoluteUrl);
+ if(!out->baseurl.isEmpty() && out->absoluteUrl.isEmpty())
+ {
+ out->absoluteUrl = out->baseurl + out->name;
+ }
+ return out;
+}
+
+QString Jarmod::url()
+{
+ if(!absoluteUrl.isEmpty())
+ return absoluteUrl;
+ else return baseurl + name;
+}