diff options
Diffstat (limited to 'logic/minecraft')
-rw-r--r-- | logic/minecraft/GradleSpecifier.h | 88 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersion.cpp | 14 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersion.h | 10 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersionList.cpp | 24 | ||||
-rw-r--r-- | logic/minecraft/OneSixLibrary.cpp | 57 | ||||
-rw-r--r-- | logic/minecraft/RawLibrary.cpp | 25 | ||||
-rw-r--r-- | logic/minecraft/RawLibrary.h | 7 | ||||
-rw-r--r-- | logic/minecraft/VersionFile.cpp | 29 |
8 files changed, 142 insertions, 112 deletions
diff --git a/logic/minecraft/GradleSpecifier.h b/logic/minecraft/GradleSpecifier.h index 3ee40b86..8a02e4d9 100644 --- a/logic/minecraft/GradleSpecifier.h +++ b/logic/minecraft/GradleSpecifier.h @@ -30,13 +30,13 @@ struct GradleSpecifier QRegExp matcher("([^:@]+):([^:@]+):([^:@]+)" "(:([^:@]+))?" "(@([^:@]+))?"); m_valid = matcher.exactMatch(value); auto elements = matcher.capturedTexts(); - groupId = elements[1]; - artifactId = elements[2]; - version = elements[3]; - classifier = elements[5]; + m_groupId = elements[1]; + m_artifactId = elements[2]; + m_version = elements[3]; + m_classifier = elements[5]; if(!elements[7].isEmpty()) { - extension = elements[7]; + m_extension = elements[7]; } return *this; } @@ -44,14 +44,14 @@ struct GradleSpecifier { if(!m_valid) return "INVALID"; - QString retval = groupId + ":" + artifactId + ":" + version; - if(!classifier.isEmpty()) + QString retval = m_groupId + ":" + m_artifactId + ":" + m_version; + if(!m_classifier.isEmpty()) { - retval += ":" + classifier; + retval += ":" + m_classifier; } - if(extension.isExplicit()) + if(m_extension.isExplicit()) { - retval += "@" + extension; + retval += "@" + m_extension; } return retval; } @@ -59,25 +59,71 @@ struct GradleSpecifier { if(!m_valid) return "INVALID"; - QString path = groupId; + QString path = m_groupId; path.replace('.', '/'); - path += '/' + artifactId + '/' + version + '/' + artifactId + '-' + version; - if(!classifier.isEmpty()) + path += '/' + m_artifactId + '/' + m_version + '/' + m_artifactId + '-' + m_version; + if(!m_classifier.isEmpty()) { - path += "-" + classifier; + path += "-" + m_classifier; } - path += "." + extension; + path += "." + m_extension; return path; } - bool valid() + inline bool valid() const { return m_valid; } + inline QString version() const + { + return m_version; + } + inline QString groupId() const + { + return m_groupId; + } + inline QString artifactId() const + { + return m_artifactId; + } + inline void setClassifier(const QString & classifier) + { + m_classifier = classifier; + } + inline QString classifier() const + { + return m_classifier; + } + inline QString extension() const + { + return m_extension; + } + inline QString artifactPrefix() const + { + return m_groupId + ":" + m_artifactId; + } + bool matchName(const GradleSpecifier & other) + { + return other.artifactId() == artifactId() && other.groupId() == groupId(); + } + bool operator==(const GradleSpecifier & other) + { + if(m_groupId != other.m_groupId) + return false; + if(m_artifactId != other.m_artifactId) + return false; + if(m_version != other.m_version) + return false; + if(m_classifier != other.m_classifier) + return false; + if(m_extension != other.m_extension) + return false; + return true; + } private: - QString groupId; - QString artifactId; - QString version; - QString classifier; - DefaultVariable<QString> extension = DefaultVariable<QString>("jar"); + QString m_groupId; + QString m_artifactId; + QString m_version; + QString m_classifier; + DefaultVariable<QString> m_extension = DefaultVariable<QString>("jar"); bool m_valid = false; }; diff --git a/logic/minecraft/MinecraftVersion.cpp b/logic/minecraft/MinecraftVersion.cpp index 488a180a..8368c430 100644 --- a/logic/minecraft/MinecraftVersion.cpp +++ b/logic/minecraft/MinecraftVersion.cpp @@ -2,6 +2,8 @@ #include "InstanceVersion.h" #include "VersionBuildError.h" #include "VersionBuilder.h" +#include "MultiMC.h" +#include "logic/settings/SettingsObject.h" bool MinecraftVersion::usesLegacyLauncher() { @@ -141,3 +143,15 @@ QString MinecraftVersion::getPatchFilename() { return QString(); } + +bool MinecraftVersion::needsUpdate() +{ + auto settings = MMC->settings(); + bool result = hasUpdate() && settings->get("AutoUpdateMinecraftVersions").toBool(); + return result; +} + +bool MinecraftVersion::hasUpdate() +{ + return m_versionSource == Remote || (m_versionSource == Local && upstreamUpdate); +} diff --git a/logic/minecraft/MinecraftVersion.h b/logic/minecraft/MinecraftVersion.h index 82073a97..e06dadb1 100644 --- a/logic/minecraft/MinecraftVersion.h +++ b/logic/minecraft/MinecraftVersion.h @@ -45,14 +45,8 @@ public: /* methods */ virtual QString getPatchVersion() override; virtual QString getPatchName() override; virtual QString getPatchFilename() override; - bool needsUpdate() - { - return m_versionSource == Remote; - } - bool hasUpdate() - { - return m_versionSource == Remote || (m_versionSource == Local && upstreamUpdate); - } + bool needsUpdate(); + bool hasUpdate(); private: /* methods */ void applyFileTo(InstanceVersion *version); diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp index 3aa1ac01..ee228528 100644 --- a/logic/minecraft/MinecraftVersionList.cpp +++ b/logic/minecraft/MinecraftVersionList.cpp @@ -266,7 +266,8 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s QString versionTypeStr = versionObj.value("type").toString(""); if (versionTypeStr.isEmpty()) { - // FIXME: log this somewhere + QLOG_ERROR() << "Ignoring" << versionID + << "because it doesn't have the version type set."; continue; } // OneSix or Legacy. use filter to determine type @@ -284,10 +285,13 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s } else { - // FIXME: log this somewhere + QLOG_ERROR() << "Ignoring" << versionID + << "because it has an invalid version type."; continue; } mcVersion->m_type = versionTypeStr; + QLOG_INFO() << "Loaded version" << versionID << "from" + << ((source == Remote) ? "remote" : "local") << "version list."; tempList.append(mcVersion); } updateListData(tempList); @@ -333,12 +337,6 @@ void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions) { continue; } - // is it actually an update? - if (orig->m_updateTime >= added->m_updateTime) - { - // nope. - continue; - } // alright, it's an update. put it inside the original, for further processing. orig->upstreamUpdate = added; } @@ -451,13 +449,10 @@ void MCVListVersionUpdateTask::json_downloaded() } QList<RawLibraryPtr> filteredLibs; QList<RawLibraryPtr> lwjglLibs; - QSet<QString> lwjglFilter = { - "net.java.jinput:jinput", "net.java.jinput:jinput-platform", - "net.java.jutils:jutils", "org.lwjgl.lwjgl:lwjgl", - "org.lwjgl.lwjgl:lwjgl_util", "org.lwjgl.lwjgl:lwjgl-platform"}; + for (auto lib : file->overwriteLibs) { - if (lwjglFilter.contains(lib->fullname())) + if (g_VersionFilterData.lwjglWhitelist.contains(lib->fullname())) { lwjglLibs.append(lib); } @@ -581,9 +576,11 @@ void MinecraftVersionList::finalizeUpdate(QString version) auto updatedVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist[idx]); + // reject any updates to builtin versions. if (updatedVersion->m_versionSource == Builtin) return; + // if we have an update for the version, replace it, make the update local if (updatedVersion->upstreamUpdate) { auto updatedWith = updatedVersion->upstreamUpdate; @@ -593,6 +590,7 @@ void MinecraftVersionList::finalizeUpdate(QString version) } else { + // otherwise, just set the version as local; updatedVersion->m_versionSource = Local; } diff --git a/logic/minecraft/OneSixLibrary.cpp b/logic/minecraft/OneSixLibrary.cpp index f9a274bd..c562f353 100644 --- a/logic/minecraft/OneSixLibrary.cpp +++ b/logic/minecraft/OneSixLibrary.cpp @@ -30,7 +30,7 @@ OneSixLibrary::OneSixLibrary(RawLibraryPtr base) m_hint = base->m_hint; m_absolute_url = base->m_absolute_url; extract_excludes = base->extract_excludes; - m_native_suffixes = base->m_native_suffixes; + m_native_classifiers = base->m_native_classifiers; m_rules = base->m_rules; finalize(); } @@ -42,34 +42,8 @@ OneSixLibraryPtr OneSixLibrary::fromRawLibrary(RawLibraryPtr lib) void OneSixLibrary::finalize() { - QStringList parts = m_name.split(':'); - QString relative = parts[0]; - relative.replace('.', '/'); - relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2]; - - if (!isNative()) - relative += ".jar"; - else - { - if (m_native_suffixes.contains(currentSystem)) - { - relative += "-" + m_native_suffixes[currentSystem] + ".jar"; - } - else - { - // really, bad. - relative += ".jar"; - } - } - - m_decentname = parts[1]; - m_decentversion = minVersion = parts[2]; - m_storage_path = relative; - if(m_base_url.isEmpty()) - m_download_url = QString("https://" + URLConstants::LIBRARY_BASE) + relative; - else - m_download_url = m_base_url + relative; - + QString relative; + if (m_rules.empty()) { m_is_active = true; @@ -87,13 +61,32 @@ void OneSixLibrary::finalize() } if (isNative()) { - m_is_active = m_is_active && m_native_suffixes.contains(currentSystem); + GradleSpecifier nativeSpec = m_name; + m_is_active = m_is_active && m_native_classifiers.contains(currentSystem); m_decenttype = "Native"; + if(m_native_classifiers.contains(currentSystem)) + { + nativeSpec.setClassifier(m_native_classifiers[currentSystem]); + } + else + { + nativeSpec.setClassifier("INVALID"); + } + relative = nativeSpec.toPath(); } else { + relative = m_name.toPath(); m_decenttype = "Java"; } + + m_decentname = m_name.artifactId(); + m_decentversion = minVersion = m_name.version(); + m_storage_path = relative; + if(m_base_url.isEmpty()) + m_download_url = QString("https://" + URLConstants::LIBRARY_BASE) + relative; + else + m_download_url = m_base_url + relative; } void OneSixLibrary::setName(const QString &name) @@ -106,11 +99,11 @@ void OneSixLibrary::setBaseUrl(const QString &base_url) } void OneSixLibrary::addNative(OpSys os, const QString &suffix) { - m_native_suffixes[os] = suffix; + m_native_classifiers[os] = suffix; } void OneSixLibrary::clearSuffixes() { - m_native_suffixes.clear(); + m_native_classifiers.clear(); } void OneSixLibrary::setRules(QList<std::shared_ptr<Rule>> rules) { diff --git a/logic/minecraft/RawLibrary.cpp b/logic/minecraft/RawLibrary.cpp index 3351268a..76bd7260 100644 --- a/logic/minecraft/RawLibrary.cpp +++ b/logic/minecraft/RawLibrary.cpp @@ -54,7 +54,7 @@ RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &fil OpSys opSys = OpSys_fromString(it.key()); if (opSys != Os_Other) { - out->m_native_suffixes[opSys] = it.value().toString(); + out->m_native_classifiers[opSys] = it.value().toString(); } } } @@ -134,13 +134,13 @@ RawLibraryPtr RawLibrary::fromJsonPlus(const QJsonObject &libObj, const QString bool RawLibrary::isNative() const { - return m_native_suffixes.size() != 0; + return m_native_classifiers.size() != 0; } QJsonObject RawLibrary::toJson() { QJsonObject libRoot; - libRoot.insert("name", m_name); + libRoot.insert("name", (QString)m_name); if (m_absolute_url.size()) libRoot.insert("MMC-absoluteUrl", m_absolute_url); if (m_hint.size()) @@ -154,8 +154,8 @@ QJsonObject RawLibrary::toJson() if (isNative()) { QJsonObject nativeList; - auto iter = m_native_suffixes.begin(); - while (iter != m_native_suffixes.end()) + auto iter = m_native_classifiers.begin(); + while (iter != m_native_classifiers.end()) { nativeList.insert(OpSys_toString(iter.key()), iter.value()); iter++; @@ -188,18 +188,5 @@ QJsonObject RawLibrary::toJson() QString RawLibrary::fullname() { - QStringList parts = m_name.split(':'); - return parts[0] + ":" + parts[1]; -} - -QString RawLibrary::group() -{ - QStringList parts = m_name.split(':'); - return parts[0]; -} - -QString RawLibrary::version() -{ - QStringList parts = m_name.split(':'); - return parts[2]; + return m_name.artifactPrefix(); } diff --git a/logic/minecraft/RawLibrary.h b/logic/minecraft/RawLibrary.h index 583c34d2..6e8f7f10 100644 --- a/logic/minecraft/RawLibrary.h +++ b/logic/minecraft/RawLibrary.h @@ -8,6 +8,7 @@ #include "logic/minecraft/OneSixRule.h" #include "logic/minecraft/OpSys.h" +#include "GradleSpecifier.h" #include "logic/net/URLConstants.h" class RawLibrary; @@ -23,11 +24,9 @@ public: /* methods */ QJsonObject toJson(); QString fullname(); - QString version(); - QString group(); public: /* data */ - QString m_name; + GradleSpecifier m_name; QString m_base_url; /// type hint - modifies how the library is treated @@ -41,7 +40,7 @@ public: /* data */ /// Returns true if the library is native bool isNative() const; /// native suffixes per OS - QMap<OpSys, QString> m_native_suffixes; + QMap<OpSys, QString> m_native_classifiers; bool applyRules = false; QList<std::shared_ptr<Rule>> m_rules; diff --git a/logic/minecraft/VersionFile.cpp b/logic/minecraft/VersionFile.cpp index 93f57116..600c71ae 100644 --- a/logic/minecraft/VersionFile.cpp +++ b/logic/minecraft/VersionFile.cpp @@ -17,13 +17,13 @@ using namespace MMCJson; #define CURRENT_MINIMUM_LAUNCHER_VERSION 14 -int findLibrary(QList<OneSixLibraryPtr> haystack, const QString &needle) +int findLibraryByName(QList<OneSixLibraryPtr> haystack, const GradleSpecifier &needle) { int retval = -1; for (int i = 0; i < haystack.size(); ++i) { - QString chunk = haystack.at(i)->rawName(); - if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(chunk) != -1) + + if(haystack.at(i)->m_name.matchName(needle)) { // only one is allowed. if (retval != -1) @@ -382,7 +382,7 @@ void VersionFile::applyTo(InstanceVersion *version) case RawLibrary::Apply: { // QLOG_INFO() << "Applying lib " << lib->name; - int index = findLibrary(version->libraries, lib->m_name); + int index = findLibraryByName(version->libraries, lib->m_name); if (index >= 0) { auto library = version->libraries[index]; @@ -405,7 +405,7 @@ void VersionFile::applyTo(InstanceVersion *version) if (lib->isNative()) { // library->clearSuffixes(); - library->m_native_suffixes = lib->m_native_suffixes; + library->m_native_classifiers = lib->m_native_classifiers; /* for (auto native : lib->natives) { @@ -429,9 +429,7 @@ void VersionFile::applyTo(InstanceVersion *version) case RawLibrary::Prepend: { // QLOG_INFO() << "Adding lib " << lib->name; - const int startOfVersion = lib->m_name.lastIndexOf(':') + 1; - const int index = findLibrary( - version->libraries, QString(lib->m_name).replace(startOfVersion, INT_MAX, '*')); + const int index = findLibraryByName(version->libraries, lib->m_name); if (index < 0) { if (lib->insertType == RawLibrary::Append) @@ -446,8 +444,8 @@ void VersionFile::applyTo(InstanceVersion *version) else { auto otherLib = version->libraries.at(index); - const Util::Version ourVersion = lib->m_name.mid(startOfVersion, INT_MAX); - const Util::Version otherVersion = otherLib->version(); + const Util::Version ourVersion = lib->m_name.version(); + const Util::Version otherVersion = otherLib->m_name.version(); // if the existing version is a hard dependency we can either use it or // fail, but we can't change it if (otherLib->dependType == OneSixLibrary::Hard) @@ -497,16 +495,17 @@ void VersionFile::applyTo(InstanceVersion *version) } case RawLibrary::Replace: { - QString toReplace; + GradleSpecifier toReplace; if (lib->insertData.isEmpty()) { - const int startOfVersion = lib->m_name.lastIndexOf(':') + 1; - toReplace = QString(lib->m_name).replace(startOfVersion, INT_MAX, '*'); + toReplace = lib->m_name; } else + { toReplace = lib->insertData; + } // QLOG_INFO() << "Replacing lib " << toReplace << " with " << lib->name; - int index = findLibrary(version->libraries, toReplace); + int index = findLibraryByName(version->libraries, toReplace); if (index >= 0) { version->libraries.replace(index, OneSixLibrary::fromRawLibrary(lib)); @@ -521,7 +520,7 @@ void VersionFile::applyTo(InstanceVersion *version) } for (auto lib : removeLibs) { - int index = findLibrary(version->libraries, lib); + int index = findLibraryByName(version->libraries, lib); if (index >= 0) { // QLOG_INFO() << "Removing lib " << lib; |