summaryrefslogtreecommitdiffstats
path: root/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-07-16 02:03:52 +0200
committerPetr Mrázek <peterix@gmail.com>2014-07-16 02:03:52 +0200
commit8a56ab6780f525472dce4dccdd53fec41390d586 (patch)
treef7d2ecf90a404e3ef0768890c85cb2101d948445 /logic/minecraft
parent71575a5022a4e682a9960256ade7ea5672d1210d (diff)
downloadMultiMC-8a56ab6780f525472dce4dccdd53fec41390d586.tar
MultiMC-8a56ab6780f525472dce4dccdd53fec41390d586.tar.gz
MultiMC-8a56ab6780f525472dce4dccdd53fec41390d586.tar.lz
MultiMC-8a56ab6780f525472dce4dccdd53fec41390d586.tar.xz
MultiMC-8a56ab6780f525472dce4dccdd53fec41390d586.zip
Implement gradle spec reader/writer
Diffstat (limited to 'logic/minecraft')
-rw-r--r--logic/minecraft/GradleSpecifier.h83
-rw-r--r--logic/minecraft/OneSixLibrary.cpp5
-rw-r--r--logic/minecraft/RawLibrary.cpp22
-rw-r--r--logic/minecraft/RawLibrary.h5
4 files changed, 101 insertions, 14 deletions
diff --git a/logic/minecraft/GradleSpecifier.h b/logic/minecraft/GradleSpecifier.h
new file mode 100644
index 00000000..3ee40b86
--- /dev/null
+++ b/logic/minecraft/GradleSpecifier.h
@@ -0,0 +1,83 @@
+#pragma once
+
+#include <QString>
+#include <QStringList>
+#include "logic/DefaultVariable.h"
+
+struct GradleSpecifier
+{
+ GradleSpecifier()
+ {
+ m_valid = false;
+ }
+ GradleSpecifier(QString value)
+ {
+ operator=(value);
+ }
+ GradleSpecifier & operator =(const QString & value)
+ {
+ /*
+ org.gradle.test.classifiers : service : 1.0 : jdk15 @ jar
+ DEBUG 0 "org.gradle.test.classifiers:service:1.0:jdk15@jar"
+ DEBUG 1 "org.gradle.test.classifiers"
+ DEBUG 2 "service"
+ DEBUG 3 "1.0"
+ DEBUG 4 ":jdk15"
+ DEBUG 5 "jdk15"
+ DEBUG 6 "@jar"
+ DEBUG 7 "jar"
+ */
+ QRegExp matcher("([^:@]+):([^:@]+):([^:@]+)" "(:([^:@]+))?" "(@([^:@]+))?");
+ m_valid = matcher.exactMatch(value);
+ auto elements = matcher.capturedTexts();
+ groupId = elements[1];
+ artifactId = elements[2];
+ version = elements[3];
+ classifier = elements[5];
+ if(!elements[7].isEmpty())
+ {
+ extension = elements[7];
+ }
+ return *this;
+ }
+ operator QString() const
+ {
+ if(!m_valid)
+ return "INVALID";
+ QString retval = groupId + ":" + artifactId + ":" + version;
+ if(!classifier.isEmpty())
+ {
+ retval += ":" + classifier;
+ }
+ if(extension.isExplicit())
+ {
+ retval += "@" + extension;
+ }
+ return retval;
+ }
+ QString toPath() const
+ {
+ if(!m_valid)
+ return "INVALID";
+ QString path = groupId;
+ path.replace('.', '/');
+ path += '/' + artifactId + '/' + version + '/' + artifactId + '-' + version;
+ if(!classifier.isEmpty())
+ {
+ path += "-" + classifier;
+ }
+ path += "." + extension;
+ return path;
+ }
+ bool valid()
+ {
+ return m_valid;
+ }
+private:
+ QString groupId;
+ QString artifactId;
+ QString version;
+ QString classifier;
+ DefaultVariable<QString> extension = DefaultVariable<QString>("jar");
+ bool m_valid = false;
+};
diff --git a/logic/minecraft/OneSixLibrary.cpp b/logic/minecraft/OneSixLibrary.cpp
index 7f69d9f8..f9a274bd 100644
--- a/logic/minecraft/OneSixLibrary.cpp
+++ b/logic/minecraft/OneSixLibrary.cpp
@@ -65,7 +65,10 @@ void OneSixLibrary::finalize()
m_decentname = parts[1];
m_decentversion = minVersion = parts[2];
m_storage_path = relative;
- m_download_url = m_base_url + relative;
+ if(m_base_url.isEmpty())
+ m_download_url = QString("https://" + URLConstants::LIBRARY_BASE) + relative;
+ else
+ m_download_url = m_base_url + relative;
if (m_rules.empty())
{
diff --git a/logic/minecraft/RawLibrary.cpp b/logic/minecraft/RawLibrary.cpp
index 7e0ebff0..3351268a 100644
--- a/logic/minecraft/RawLibrary.cpp
+++ b/logic/minecraft/RawLibrary.cpp
@@ -13,20 +13,20 @@ RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &fil
}
out->m_name = libObj.value("name").toString();
- auto readString = [libObj, filename](const QString & key, QString & variable)
+ auto readString = [libObj, filename](const QString & key, QString & variable) -> bool
{
- if (libObj.contains(key))
+ if (!libObj.contains(key))
+ return false;
+ QJsonValue val = libObj.value(key);
+
+ if (!val.isString())
{
- QJsonValue val = libObj.value(key);
- if (!val.isString())
- {
- QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
- }
- else
- {
- variable = val.toString();
- }
+ QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
+ return false;
}
+
+ variable = val.toString();
+ return true;
};
readString("url", out->m_base_url);
diff --git a/logic/minecraft/RawLibrary.h b/logic/minecraft/RawLibrary.h
index f5a28c61..583c34d2 100644
--- a/logic/minecraft/RawLibrary.h
+++ b/logic/minecraft/RawLibrary.h
@@ -28,10 +28,11 @@ public: /* methods */
public: /* data */
QString m_name;
- QString m_base_url = "https://" + URLConstants::LIBRARY_BASE;
+ QString m_base_url;
+
/// type hint - modifies how the library is treated
QString m_hint;
- /// absolute URL. takes precedence over m_download_path, if defined
+ /// DEPRECATED: absolute URL. takes precedence over m_download_path, if defined
QString m_absolute_url;
bool applyExcludes = false;