diff options
Diffstat (limited to 'api/logic/minecraft')
44 files changed, 575 insertions, 3331 deletions
diff --git a/api/logic/minecraft/Library.cpp b/api/logic/minecraft/Library.cpp index 5a75fe79..7521a049 100644 --- a/api/logic/minecraft/Library.cpp +++ b/api/logic/minecraft/Library.cpp @@ -30,14 +30,15 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na }; if(m_mojangDownloads) { - if(m_mojangDownloads->artifact) + if(!isNative()) { - auto artifact = m_mojangDownloads->artifact; - jar += actualPath(artifact->path); + if(m_mojangDownloads->artifact) + { + auto artifact = m_mojangDownloads->artifact; + jar += actualPath(artifact->path); + } } - if(!isNative()) - return; - if(m_nativeClassifiers.contains(system)) + else if(m_nativeClassifiers.contains(system)) { auto nativeClassifier = m_nativeClassifiers[system]; if(nativeClassifier.contains("${arch}")) @@ -55,7 +56,15 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na } else { - native += actualPath(m_mojangDownloads->getDownloadInfo(nativeClassifier)->path); + auto dlinfo = m_mojangDownloads->getDownloadInfo(nativeClassifier); + if(!dlinfo) + { + qWarning() << "Cannot get native for" << nativeClassifier << "while processing" << m_name; + } + else + { + native += actualPath(dlinfo->path); + } } } } diff --git a/api/logic/minecraft/Library_test.cpp b/api/logic/minecraft/Library_test.cpp index fe61d305..3f4828c9 100644 --- a/api/logic/minecraft/Library_test.cpp +++ b/api/logic/minecraft/Library_test.cpp @@ -234,7 +234,7 @@ slots: auto test = readMojangJson("data/lib-native.json"); QStringList jar, native, native32, native64; test->getApplicableFiles(Os_OSX, jar, native, native32, native64, QString()); - QCOMPARE(jar, getStorage("org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar")); + QCOMPARE(jar, QStringList()); QCOMPARE(native, getStorage("org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar")); QCOMPARE(native32, {}); QCOMPARE(native64, {}); diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index 7b1aef1e..cb080bfe 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -5,7 +5,6 @@ #include <settings/Setting.h> #include "settings/SettingsObject.h" #include "Env.h" -#include "minecraft/MinecraftVersionList.h" #include <MMCStrings.h> #include <pathmatcher/RegexpMatcher.h> #include <pathmatcher/MultiMatcher.h> @@ -21,9 +20,13 @@ #include "minecraft/launch/ModMinecraftJar.h" #include "minecraft/launch/ClaimAccount.h" #include "java/launch/CheckJava.h" +#include <meta/Index.h> +#include <meta/VersionList.h> #include <icons/IIconList.h> +#include <QCoreApplication> + #define IBUS "@im=ibus" // all of this because keeping things compatible with deprecated old settings @@ -104,7 +107,7 @@ QString MinecraftInstance::binRoot() const std::shared_ptr< BaseVersionList > MinecraftInstance::versionList() const { - return ENV.getVersionList("net.minecraft"); + return ENV.metadataIndex()->get("net.minecraft"); } QStringList MinecraftInstance::javaArguments() const diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp index 46235a18..c04669c1 100644 --- a/api/logic/minecraft/MinecraftProfile.cpp +++ b/api/logic/minecraft/MinecraftProfile.cpp @@ -80,7 +80,7 @@ void MinecraftProfile::clear() m_traits.clear(); m_jarMods.clear(); mojangDownloads.clear(); - m_problemSeverity = ProblemSeverity::PROBLEM_NONE; + m_problemSeverity = ProblemSeverity::None; } void MinecraftProfile::clearPatches() @@ -273,9 +273,9 @@ QVariant MinecraftProfile::data(const QModelIndex &index, int role) const auto severity = patch->getProblemSeverity(); switch (severity) { - case PROBLEM_WARNING: + case ProblemSeverity::Warning: return "warning"; - case PROBLEM_ERROR: + case ProblemSeverity::Error: return "error"; default: return QVariant(); @@ -491,20 +491,29 @@ void MinecraftProfile::applyLibrary(LibraryPtr library) { return; } + + QList<LibraryPtr> * list = &m_libraries; + if(library->isNative()) + { + list = &m_nativeLibraries; + } + + auto libraryCopy = Library::limitedCopy(library); + // find the library by name. - const int index = findLibraryByName(m_libraries, library->rawName()); + const int index = findLibraryByName(*list, library->rawName()); // library not found? just add it. if (index < 0) { - m_libraries.append(Library::limitedCopy(library)); + list->append(libraryCopy); return; } - auto existingLibrary = m_libraries.at(index); + + auto existingLibrary = list->at(index); // if we are higher it means we should update if (Version(library->version()) > Version(existingLibrary->version())) { - auto libraryCopy = Library::limitedCopy(library); - m_libraries.replace(index, libraryCopy); + list->replace(index, libraryCopy); } } @@ -581,6 +590,11 @@ const QList<LibraryPtr> & MinecraftProfile::getLibraries() const return m_libraries; } +const QList<LibraryPtr> & MinecraftProfile::getNativeLibraries() const +{ + return m_nativeLibraries; +} + void MinecraftProfile::getLibraryFiles(const QString& architecture, QStringList& jars, QStringList& nativeJars, const QString& overridePath) const { QStringList native32, native64; @@ -590,6 +604,10 @@ void MinecraftProfile::getLibraryFiles(const QString& architecture, QStringList& { lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); } + for (auto lib : getNativeLibraries()) + { + lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); + } if(architecture == "32") { nativeJars.append(native32); @@ -621,6 +639,11 @@ void MinecraftProfile::installJarMods(QStringList selectedFiles) m_strategy->installJarMods(selectedFiles); } +void MinecraftProfile::installVersion(BaseVersionPtr version) +{ + // TODO: implement +} + /* * TODO: get rid of this. Get rid of all order numbers. */ diff --git a/api/logic/minecraft/MinecraftProfile.h b/api/logic/minecraft/MinecraftProfile.h index 392c8f5f..5b1ea539 100644 --- a/api/logic/minecraft/MinecraftProfile.h +++ b/api/logic/minecraft/MinecraftProfile.h @@ -22,8 +22,9 @@ #include <memory> #include "Library.h" -#include "VersionFile.h" +#include "ProfilePatch.h" #include "JarMod.h" +#include "BaseVersion.h" #include "MojangDownloadInfo.h" #include "multimc_logic_export.h" @@ -58,6 +59,9 @@ public: /// install more jar mods void installJarMods(QStringList selectedFiles); + /// install more jar mods + void installVersion(BaseVersionPtr version); + /// DEPRECATED, remove ASAP int getFreeOrderNumber(); @@ -111,6 +115,7 @@ public: /* getters for profile variables */ const QStringList & getTweakers() const; const QList<JarmodPtr> & getJarMods() const; const QList<LibraryPtr> & getLibraries() const; + const QList<LibraryPtr> & getNativeLibraries() const; void getLibraryFiles(const QString & architecture, QStringList & jars, QStringList & nativeJars, const QString & overridePath) const; QString getMainJarUrl() const; bool hasTrait(const QString & trait) const; @@ -165,13 +170,16 @@ private: /* data */ /// the list of libraries QList<LibraryPtr> m_libraries; + /// the list of libraries + QList<LibraryPtr> m_nativeLibraries; + /// traits, collected from all the version files (version files can only add) QSet<QString> m_traits; /// A list of jar mods. version files can add those. QList<JarmodPtr> m_jarMods; - ProblemSeverity m_problemSeverity = PROBLEM_NONE; + ProblemSeverity m_problemSeverity = ProblemSeverity::None; /* FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. diff --git a/api/logic/minecraft/MinecraftVersion.cpp b/api/logic/minecraft/MinecraftVersion.cpp deleted file mode 100644 index 248c7eed..00000000 --- a/api/logic/minecraft/MinecraftVersion.cpp +++ /dev/null @@ -1,230 +0,0 @@ -#include "MinecraftVersion.h" -#include "MinecraftProfile.h" -#include "VersionBuildError.h" -#include "ProfileUtils.h" -#include "settings/SettingsObject.h" - -bool MinecraftVersion::usesLegacyLauncher() -{ - return m_traits.contains("legacyLaunch") || m_traits.contains("aplhaLaunch"); -} - -QString MinecraftVersion::descriptor() -{ - return m_descriptor; -} - -QString MinecraftVersion::name() -{ - return m_name; -} - -QString MinecraftVersion::typeString() const -{ - if(m_type == "snapshot") - { - return QObject::tr("Snapshot"); - } - else if (m_type == "release") - { - return QObject::tr("Regular release"); - } - else if (m_type == "old_alpha") - { - return QObject::tr("Alpha"); - } - else if (m_type == "old_beta") - { - return QObject::tr("Beta"); - } - else - { - return QString(); - } -} - -VersionSource MinecraftVersion::getVersionSource() -{ - return m_versionSource; -} - -bool MinecraftVersion::hasJarMods() -{ - return false; -} - -bool MinecraftVersion::isMinecraftVersion() -{ - return true; -} - -void MinecraftVersion::applyFileTo(MinecraftProfile *profile) -{ - if(m_versionSource == VersionSource::Local && getVersionFile()) - { - getVersionFile()->applyTo(profile); - } - else - { - throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name)); - } -} - -QString MinecraftVersion::getUrl() const -{ - // legacy fallback - if(m_versionFileURL.isEmpty()) - { - return QString("http://") + URLConstants::AWS_DOWNLOAD_VERSIONS + m_descriptor + "/" + m_descriptor + ".json"; - } - // current - return m_versionFileURL; -} - -VersionFilePtr MinecraftVersion::getVersionFile() -{ - QFileInfo versionFile(QString("versions/%1/%1.dat").arg(m_descriptor)); - m_problems.clear(); - m_problemSeverity = PROBLEM_NONE; - if(!versionFile.exists()) - { - if(m_loadedVersionFile) - { - m_loadedVersionFile.reset(); - } - addProblem(PROBLEM_WARNING, QObject::tr("The patch file doesn't exist locally. It's possible it just needs to be downloaded.")); - } - else - { - try - { - if(versionFile.lastModified() != m_loadedVersionFileTimestamp) - { - auto loadedVersionFile = ProfileUtils::parseBinaryJsonFile(versionFile); - loadedVersionFile->name = "Minecraft"; - loadedVersionFile->setCustomizable(true); - m_loadedVersionFileTimestamp = versionFile.lastModified(); - m_loadedVersionFile = loadedVersionFile; - } - } - catch(Exception e) - { - m_loadedVersionFile.reset(); - addProblem(PROBLEM_ERROR, QObject::tr("The patch file couldn't be read:\n%1").arg(e.cause())); - } - } - return m_loadedVersionFile; -} - -bool MinecraftVersion::isCustomizable() -{ - switch(m_versionSource) - { - case VersionSource::Local: - case VersionSource::Remote: - // locally cached file, or a remote file that we can acquire can be customized - return true; - case VersionSource::Builtin: - // builtins do not follow the normal OneSix format. They are not customizable. - default: - // Everything else is undefined and therefore not customizable. - return false; - } - return false; -} - -const QList<PatchProblem> &MinecraftVersion::getProblems() -{ - if(m_versionSource != VersionSource::Builtin && getVersionFile()) - { - return getVersionFile()->getProblems(); - } - return ProfilePatch::getProblems(); -} - -ProblemSeverity MinecraftVersion::getProblemSeverity() -{ - if(m_versionSource != VersionSource::Builtin && getVersionFile()) - { - return getVersionFile()->getProblemSeverity(); - } - return ProfilePatch::getProblemSeverity(); -} - -void MinecraftVersion::applyTo(MinecraftProfile *profile) -{ - // do we have this one cached? - if (m_versionSource == VersionSource::Local) - { - applyFileTo(profile); - return; - } - // if not builtin, do not proceed any further. - if (m_versionSource != VersionSource::Builtin) - { - throw VersionIncomplete(QObject::tr( - "Minecraft version %1 could not be applied: version files are missing.").arg(m_descriptor)); - } - profile->applyMinecraftVersion(m_descriptor); - profile->applyMainClass(m_mainClass); - profile->applyAppletClass(m_appletClass); - profile->applyMinecraftArguments(" ${auth_player_name} ${auth_session}"); // all builtin versions are legacy - profile->applyMinecraftVersionType(m_type); - profile->applyTraits(m_traits); - profile->applyProblemSeverity(m_problemSeverity); -} - -int MinecraftVersion::getOrder() -{ - return order; -} - -void MinecraftVersion::setOrder(int order) -{ - this->order = order; -} - -QList<JarmodPtr> MinecraftVersion::getJarMods() -{ - return QList<JarmodPtr>(); -} - -QString MinecraftVersion::getName() -{ - return "Minecraft"; -} -QString MinecraftVersion::getVersion() -{ - return m_descriptor; -} -QString MinecraftVersion::getID() -{ - return "net.minecraft"; -} -QString MinecraftVersion::getFilename() -{ - return QString(); -} -QDateTime MinecraftVersion::getReleaseDateTime() -{ - return m_releaseTime; -} - - -bool MinecraftVersion::needsUpdate() -{ - return m_versionSource == VersionSource::Remote || hasUpdate(); -} - -bool MinecraftVersion::hasUpdate() -{ - return m_versionSource == VersionSource::Remote || (m_versionSource == VersionSource::Local && upstreamUpdate); -} - -bool MinecraftVersion::isCustom() -{ - // if we add any other source types, this will evaluate to false for them. - return m_versionSource != VersionSource::Builtin - && m_versionSource != VersionSource::Local - && m_versionSource != VersionSource::Remote; -} diff --git a/api/logic/minecraft/MinecraftVersion.h b/api/logic/minecraft/MinecraftVersion.h deleted file mode 100644 index 7ac9bcbb..00000000 --- a/api/logic/minecraft/MinecraftVersion.h +++ /dev/null @@ -1,132 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <QStringList> -#include <QSet> -#include <QDateTime> - -#include "BaseVersion.h" -#include "ProfilePatch.h" -#include "VersionFile.h" - -#include "multimc_logic_export.h" - -class MinecraftProfile; -class MinecraftVersion; -typedef std::shared_ptr<MinecraftVersion> MinecraftVersionPtr; - -class MULTIMC_LOGIC_EXPORT MinecraftVersion : public BaseVersion, public ProfilePatch -{ -friend class MinecraftVersionList; - -public: /* methods */ - bool usesLegacyLauncher(); - virtual QString descriptor() override; - virtual QString name() override; - virtual QString typeString() const override; - virtual bool hasJarMods() override; - virtual bool isMinecraftVersion() override; - virtual void applyTo(MinecraftProfile *profile) override; - virtual int getOrder() override; - virtual void setOrder(int order) override; - virtual QList<JarmodPtr> getJarMods() override; - virtual QString getID() override; - virtual QString getVersion() override; - virtual QString getName() override; - virtual QString getFilename() override; - QDateTime getReleaseDateTime() override; - VersionSource getVersionSource() override; - - bool needsUpdate(); - bool hasUpdate(); - virtual bool isCustom() override; - virtual bool isMoveable() override - { - return false; - } - virtual bool isCustomizable() override; - virtual bool isRemovable() override - { - return false; - } - virtual bool isRevertible() override - { - return false; - } - virtual bool isEditable() override - { - return false; - } - virtual bool isVersionChangeable() override - { - return true; - } - - virtual VersionFilePtr getVersionFile() override; - - // virtual QJsonDocument toJson(bool saveOrder) override; - - QString getUrl() const; - - virtual const QList<PatchProblem> &getProblems() override; - virtual ProblemSeverity getProblemSeverity() override; - -private: /* methods */ - void applyFileTo(MinecraftProfile *profile); - -protected: /* data */ - VersionSource m_versionSource = VersionSource::Builtin; - - /// The URL that this version will be downloaded from. - QString m_versionFileURL; - - /// the human readable version name - QString m_name; - - /// the version ID. - QString m_descriptor; - - /// version traits. added by MultiMC - QSet<QString> m_traits; - - /// The main class this version uses (if any, can be empty). - QString m_mainClass; - - /// The applet class this version uses (if any, can be empty). - QString m_appletClass; - - /// The type of this release - QString m_type; - - /// the time this version was actually released by Mojang - QDateTime m_releaseTime; - - /// the time this version was last updated by Mojang - QDateTime m_updateTime; - - /// MD5 hash of the minecraft jar - QString m_jarChecksum; - - /// order of this file... default = -2 - int order = -2; - - /// an update available from Mojang - MinecraftVersionPtr upstreamUpdate; - - QDateTime m_loadedVersionFileTimestamp; - mutable VersionFilePtr m_loadedVersionFile; -}; diff --git a/api/logic/minecraft/MinecraftVersionList.cpp b/api/logic/minecraft/MinecraftVersionList.cpp deleted file mode 100644 index 2c9a8035..00000000 --- a/api/logic/minecraft/MinecraftVersionList.cpp +++ /dev/null @@ -1,677 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <QtXml> -#include "Json.h" -#include <QtAlgorithms> -#include <QtNetwork> - -#include "Env.h" -#include "Exception.h" - -#include "MinecraftVersionList.h" -#include "net/URLConstants.h" - -#include "ParseUtils.h" -#include "ProfileUtils.h" -#include "VersionFilterData.h" -#include "onesix/OneSixVersionFormat.h" -#include "MojangVersionFormat.h" -#include <FileSystem.h> - -static const char * localVersionCache = "versions/versions.dat"; - -class MCVListLoadTask : public Task -{ - Q_OBJECT - -public: - explicit MCVListLoadTask(MinecraftVersionList *vlist); - virtual ~MCVListLoadTask() override{}; - - virtual void executeTask() override; - -protected -slots: - void list_downloaded(); - -protected: - QNetworkReply *vlistReply; - MinecraftVersionList *m_list; - MinecraftVersion *m_currentStable; -}; - -class MCVListVersionUpdateTask : public Task -{ - Q_OBJECT - -public: - explicit MCVListVersionUpdateTask(MinecraftVersionList *vlist, std::shared_ptr<MinecraftVersion> updatedVersion); - virtual ~MCVListVersionUpdateTask() override{}; - virtual void executeTask() override; - bool canAbort() const override; - -public slots: - bool abort() override; - -protected -slots: - void json_downloaded(); - -protected: - NetJobPtr specificVersionDownloadJob; - QByteArray versionIndexData; - std::shared_ptr<MinecraftVersion> updatedVersion; - MinecraftVersionList *m_list; - bool m_aborted = false; -}; - -class ListLoadError : public Exception -{ -public: - ListLoadError(QString cause) : Exception(cause) {}; - virtual ~ListLoadError() noexcept - { - } -}; - -MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent) -{ - loadBuiltinList(); - loadCachedList(); -} - -Task *MinecraftVersionList::getLoadTask() -{ - return new MCVListLoadTask(this); -} - -bool MinecraftVersionList::isLoaded() -{ |
