From 17c8f31a09da6bdfc4aa7f67b2ca86b791f2ba96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 4 Nov 2017 22:55:25 +0100 Subject: NOISSUE split out the LaunchProfile out of the ComponentList --- api/logic/CMakeLists.txt | 2 + api/logic/ProblemProvider.h | 9 +- api/logic/minecraft/ComponentList.cpp | 303 ++---------------------- api/logic/minecraft/ComponentList.h | 88 +------ api/logic/minecraft/LaunchProfile.cpp | 297 +++++++++++++++++++++++ api/logic/minecraft/LaunchProfile.h | 99 ++++++++ api/logic/minecraft/MinecraftInstance.cpp | 64 ++--- api/logic/minecraft/MinecraftInstance.h | 10 +- api/logic/minecraft/ProfilePatch.cpp | 10 +- api/logic/minecraft/ProfilePatch.h | 11 +- api/logic/minecraft/VersionFile.cpp | 2 +- api/logic/minecraft/VersionFile.h | 3 +- api/logic/minecraft/launch/ModMinecraftJar.cpp | 3 +- api/logic/minecraft/update/AssetUpdateTask.cpp | 6 +- api/logic/minecraft/update/FMLLibrariesTask.cpp | 5 +- api/logic/minecraft/update/LibrariesTask.cpp | 3 +- 16 files changed, 493 insertions(+), 422 deletions(-) create mode 100644 api/logic/minecraft/LaunchProfile.cpp create mode 100644 api/logic/minecraft/LaunchProfile.h (limited to 'api/logic') diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index e5047d38..42bea98c 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -237,6 +237,8 @@ set(MINECRAFT_SOURCES minecraft/GradleSpecifier.h minecraft/MinecraftInstance.cpp minecraft/MinecraftInstance.h + minecraft/LaunchProfile.cpp + minecraft/LaunchProfile.h minecraft/ComponentList.cpp minecraft/ComponentList.h minecraft/MinecraftUpdate.h diff --git a/api/logic/ProblemProvider.h b/api/logic/ProblemProvider.h index 7dedccd7..4040f4fa 100644 --- a/api/logic/ProblemProvider.h +++ b/api/logic/ProblemProvider.h @@ -16,18 +16,19 @@ struct PatchProblem class ProblemProvider { public: - virtual const QList getProblems() = 0; - virtual ProblemSeverity getProblemSeverity() = 0; + virtual ~ProblemProvider() {}; + virtual const QList getProblems() const = 0; + virtual ProblemSeverity getProblemSeverity() const = 0; }; class ProblemContainer : public ProblemProvider { public: - const QList getProblems() override + const QList getProblems() const override { return m_problems; } - ProblemSeverity getProblemSeverity() override + ProblemSeverity getProblemSeverity() const override { return m_problemSeverity; } diff --git a/api/logic/minecraft/ComponentList.cpp b/api/logic/minecraft/ComponentList.cpp index 8ce1fded..34d3bc14 100644 --- a/api/logic/minecraft/ComponentList.cpp +++ b/api/logic/minecraft/ComponentList.cpp @@ -35,7 +35,6 @@ ComponentList::ComponentList(MinecraftInstance * instance) : QAbstractListModel() { m_instance = instance; - clear(); } ComponentList::~ComponentList() @@ -50,22 +49,6 @@ void ComponentList::reload() endResetModel(); } -void ComponentList::clear() -{ - m_minecraftVersion.clear(); - m_minecraftVersionType.clear(); - m_minecraftAssets.reset(); - m_minecraftArguments.clear(); - m_tweakers.clear(); - m_mainClass.clear(); - m_appletClass.clear(); - m_libraries.clear(); - m_traits.clear(); - m_jarMods.clear(); - m_mainJar.reset(); - m_problemSeverity = ProblemSeverity::None; -} - void ComponentList::clearPatches() { beginResetModel(); @@ -365,290 +348,22 @@ bool ComponentList::reapplyPatches() { try { - clear(); + m_profile.reset(new LaunchProfile); for(auto file: m_patches) { qDebug() << "Applying" << file->getID() << (file->getProblemSeverity() == ProblemSeverity::Error ? "ERROR" : "GOOD"); - file->applyTo(this); + file->applyTo(m_profile.get()); } } catch (Exception & error) { - clear(); + m_profile.reset(); qWarning() << "Couldn't apply profile patches because: " << error.cause(); return false; } return true; } -static void applyString(const QString & from, QString & to) -{ - if(from.isEmpty()) - return; - to = from; -} - -void ComponentList::applyMinecraftVersion(const QString& id) -{ - applyString(id, this->m_minecraftVersion); -} - -void ComponentList::applyAppletClass(const QString& appletClass) -{ - applyString(appletClass, this->m_appletClass); -} - -void ComponentList::applyMainClass(const QString& mainClass) -{ - applyString(mainClass, this->m_mainClass); -} - -void ComponentList::applyMinecraftArguments(const QString& minecraftArguments) -{ - applyString(minecraftArguments, this->m_minecraftArguments); -} - -void ComponentList::applyMinecraftVersionType(const QString& type) -{ - applyString(type, this->m_minecraftVersionType); -} - -void ComponentList::applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets) -{ - if(assets) - { - m_minecraftAssets = assets; - } -} - -void ComponentList::applyTraits(const QSet& traits) -{ - this->m_traits.unite(traits); -} - -void ComponentList::applyTweakers(const QStringList& tweakers) -{ - // if the applied tweakers override an existing one, skip it. this effectively moves it later in the sequence - QStringList newTweakers; - for(auto & tweaker: m_tweakers) - { - if (tweakers.contains(tweaker)) - { - continue; - } - newTweakers.append(tweaker); - } - // then just append the new tweakers (or moved original ones) - newTweakers += tweakers; - m_tweakers = newTweakers; -} - -void ComponentList::applyJarMods(const QList& jarMods) -{ - this->m_jarMods.append(jarMods); -} - -static int findLibraryByName(QList *haystack, const GradleSpecifier &needle) -{ - int retval = -1; - for (int i = 0; i < haystack->size(); ++i) - { - if (haystack->at(i)->rawName().matchName(needle)) - { - // only one is allowed. - if (retval != -1) - return -1; - retval = i; - } - } - return retval; -} - -void ComponentList::applyMods(const QList& mods) -{ - QList * list = &m_mods; - for(auto & mod: mods) - { - auto modCopy = Library::limitedCopy(mod); - - // find the mod by name. - const int index = findLibraryByName(list, mod->rawName()); - // mod not found? just add it. - if (index < 0) - { - list->append(modCopy); - return; - } - - auto existingLibrary = list->at(index); - // if we are higher it means we should update - if (Version(mod->version()) > Version(existingLibrary->version())) - { - list->replace(index, modCopy); - } - } -} - -void ComponentList::applyLibrary(LibraryPtr library) -{ - if(!library->isActive()) - { - return; - } - - QList * list = &m_libraries; - if(library->isNative()) - { - list = &m_nativeLibraries; - } - - auto libraryCopy = Library::limitedCopy(library); - - // find the library by name. - const int index = findLibraryByName(list, library->rawName()); - // library not found? just add it. - if (index < 0) - { - list->append(libraryCopy); - return; - } - - auto existingLibrary = list->at(index); - // if we are higher it means we should update - if (Version(library->version()) > Version(existingLibrary->version())) - { - list->replace(index, libraryCopy); - } -} - -const LibraryPtr ComponentList::getMainJar() const -{ - return m_mainJar; -} - -void ComponentList::applyMainJar(LibraryPtr jar) -{ - if(jar) - { - m_mainJar = jar; - } -} - -void ComponentList::applyProblemSeverity(ProblemSeverity severity) -{ - if (m_problemSeverity < severity) - { - m_problemSeverity = severity; - } -} - - -QString ComponentList::getMinecraftVersion() const -{ - return m_minecraftVersion; -} - -QString ComponentList::getAppletClass() const -{ - return m_appletClass; -} - -QString ComponentList::getMainClass() const -{ - return m_mainClass; -} - -const QSet &ComponentList::getTraits() const -{ - return m_traits; -} - -const QStringList & ComponentList::getTweakers() const -{ - return m_tweakers; -} - -bool ComponentList::hasTrait(const QString& trait) const -{ - return m_traits.contains(trait); -} - -ProblemSeverity ComponentList::getProblemSeverity() const -{ - return m_problemSeverity; -} - -QString ComponentList::getMinecraftVersionType() const -{ - return m_minecraftVersionType; -} - -std::shared_ptr ComponentList::getMinecraftAssets() const -{ - if(!m_minecraftAssets) - { - return std::make_shared("legacy"); - } - return m_minecraftAssets; -} - -QString ComponentList::getMinecraftArguments() const -{ - return m_minecraftArguments; -} - -const QList & ComponentList::getJarMods() const -{ - return m_jarMods; -} - -const QList & ComponentList::getLibraries() const -{ - return m_libraries; -} - -const QList & ComponentList::getNativeLibraries() const -{ - return m_nativeLibraries; -} - -void ComponentList::getLibraryFiles(const QString& architecture, QStringList& jars, QStringList& nativeJars, const QString& overridePath, const QString& tempPath) const -{ - QStringList native32, native64; - jars.clear(); - nativeJars.clear(); - for (auto lib : getLibraries()) - { - lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); - } - // NOTE: order is important here, add main jar last to the lists - if(m_mainJar) - { - // FIXME: HACK!! jar modding is weird and unsystematic! - if(m_jarMods.size()) - { - QDir tempDir(tempPath); - jars.append(tempDir.absoluteFilePath("minecraft.jar")); - } - else - { - m_mainJar->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); - } - else if(architecture == "64") - { - nativeJars.append(native64); - } -} - void ComponentList::installJarMods(QStringList selectedFiles) { installJarMods_internal(selectedFiles); @@ -1122,4 +837,14 @@ bool ComponentList::installCustomJar_internal(QString filepath) saveCurrentOrder(); reapplyPatches(); return true; -} \ No newline at end of file +} + +std::shared_ptr ComponentList::getProfile() const +{ + return m_profile; +} + +void ComponentList::clearProfile() +{ + m_profile.reset(); +} diff --git a/api/logic/minecraft/ComponentList.h b/api/logic/minecraft/ComponentList.h index a566d8f5..0811a829 100644 --- a/api/logic/minecraft/ComponentList.h +++ b/api/logic/minecraft/ComponentList.h @@ -22,11 +22,11 @@ #include #include "Library.h" +#include "LaunchProfile.h" #include "ProfilePatch.h" #include "ProfileUtils.h" #include "BaseVersion.h" #include "MojangDownloadInfo.h" - #include "multimc_logic_export.h" class MinecraftInstance; @@ -80,45 +80,11 @@ public: /// reload all profile patches from storage, clear the profile and apply the patches void reload(); - /// clear the profile - void clear(); - /// apply the patches. Catches all the errors and returns true/false for success/failure bool reapplyPatches(); -public: /* application of profile variables from patches */ - void applyMinecraftVersion(const QString& id); - void applyMainClass(const QString& mainClass); - void applyAppletClass(const QString& appletClass); - void applyMinecraftArguments(const QString& minecraftArguments); - void applyMinecraftVersionType(const QString& type); - void applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets); - void applyTraits(const QSet &traits); - void applyTweakers(const QStringList &tweakers); - void applyJarMods(const QList &jarMods); - void applyMods(const QList &jarMods); - void applyLibrary(LibraryPtr library); - void applyMainJar(LibraryPtr jar); - void applyProblemSeverity(ProblemSeverity severity); - -public: /* getters for profile variables */ - QString getMinecraftVersion() const; - QString getMainClass() const; - QString getAppletClass() const; - QString getMinecraftVersionType() const; - MojangAssetIndexInfo::Ptr getMinecraftAssets() const; - QString getMinecraftArguments() const; - const QSet & getTraits() const; - const QStringList & getTweakers() const; - const QList & getJarMods() const; - const QList & getLibraries() const; - const QList & getNativeLibraries() const; - const LibraryPtr getMainJar() const; - void getLibraryFiles(const QString & architecture, QStringList & jars, QStringList & nativeJars, const QString & overridePath, - const QString & tempPath) const; - bool hasTrait(const QString & trait) const; - ProblemSeverity getProblemSeverity() const; - + std::shared_ptr getProfile() const; + void clearProfile(); public: /// get the profile patch by id ProfilePatchPtr versionPatch(const QString &id); @@ -149,55 +115,11 @@ private: void upgradeDeprecatedFiles_internal(); private: /* data */ - /// the version of Minecraft - jar to use - QString m_minecraftVersion; - - /// Release type - "release" or "snapshot" - QString m_minecraftVersionType; - - /// Assets type - "legacy" or a version ID - MojangAssetIndexInfo::Ptr m_minecraftAssets; - - /** - * arguments that should be used for launching minecraft - * - * ex: "--username ${auth_player_name} --session ${auth_session} - * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" - */ - QString m_minecraftArguments; - - /// A list of all tweaker classes - QStringList m_tweakers; - - /// The main class to load first - QString m_mainClass; - - /// The applet class, for some very old minecraft releases - QString m_appletClass; - - /// the list of libraries - QList m_libraries; - - /// the main jar - LibraryPtr m_mainJar; - - /// the list of libraries - QList m_nativeLibraries; - - /// traits, collected from all the version files (version files can only add) - QSet m_traits; - - /// A list of jar mods. version files can add those. - QList m_jarMods; - - /// the list of mods - QList m_mods; - - ProblemSeverity m_problemSeverity = ProblemSeverity::None; - /// list of attached profile patches QList m_patches; // the instance this belongs to MinecraftInstance *m_instance; + + std::shared_ptr m_profile; }; diff --git a/api/logic/minecraft/LaunchProfile.cpp b/api/logic/minecraft/LaunchProfile.cpp new file mode 100644 index 00000000..436a39d9 --- /dev/null +++ b/api/logic/minecraft/LaunchProfile.cpp @@ -0,0 +1,297 @@ +#include "LaunchProfile.h" +#include + +void LaunchProfile::clear() +{ + m_minecraftVersion.clear(); + m_minecraftVersionType.clear(); + m_minecraftAssets.reset(); + m_minecraftArguments.clear(); + m_tweakers.clear(); + m_mainClass.clear(); + m_appletClass.clear(); + m_libraries.clear(); + m_traits.clear(); + m_jarMods.clear(); + m_mainJar.reset(); + m_problemSeverity = ProblemSeverity::None; +} + +static void applyString(const QString & from, QString & to) +{ + if(from.isEmpty()) + return; + to = from; +} + +void LaunchProfile::applyMinecraftVersion(const QString& id) +{ + applyString(id, this->m_minecraftVersion); +} + +void LaunchProfile::applyAppletClass(const QString& appletClass) +{ + applyString(appletClass, this->m_appletClass); +} + +void LaunchProfile::applyMainClass(const QString& mainClass) +{ + applyString(mainClass, this->m_mainClass); +} + +void LaunchProfile::applyMinecraftArguments(const QString& minecraftArguments) +{ + applyString(minecraftArguments, this->m_minecraftArguments); +} + +void LaunchProfile::applyMinecraftVersionType(const QString& type) +{ + applyString(type, this->m_minecraftVersionType); +} + +void LaunchProfile::applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets) +{ + if(assets) + { + m_minecraftAssets = assets; + } +} + +void LaunchProfile::applyTraits(const QSet& traits) +{ + this->m_traits.unite(traits); +} + +void LaunchProfile::applyTweakers(const QStringList& tweakers) +{ + // if the applied tweakers override an existing one, skip it. this effectively moves it later in the sequence + QStringList newTweakers; + for(auto & tweaker: m_tweakers) + { + if (tweakers.contains(tweaker)) + { + continue; + } + newTweakers.append(tweaker); + } + // then just append the new tweakers (or moved original ones) + newTweakers += tweakers; + m_tweakers = newTweakers; +} + +void LaunchProfile::applyJarMods(const QList& jarMods) +{ + this->m_jarMods.append(jarMods); +} + +static int findLibraryByName(QList *haystack, const GradleSpecifier &needle) +{ + int retval = -1; + for (int i = 0; i < haystack->size(); ++i) + { + if (haystack->at(i)->rawName().matchName(needle)) + { + // only one is allowed. + if (retval != -1) + return -1; + retval = i; + } + } + return retval; +} + +void LaunchProfile::applyMods(const QList& mods) +{ + QList * list = &m_mods; + for(auto & mod: mods) + { + auto modCopy = Library::limitedCopy(mod); + + // find the mod by name. + const int index = findLibraryByName(list, mod->rawName()); + // mod not found? just add it. + if (index < 0) + { + list->append(modCopy); + return; + } + + auto existingLibrary = list->at(index); + // if we are higher it means we should update + if (Version(mod->version()) > Version(existingLibrary->version())) + { + list->replace(index, modCopy); + } + } +} + +void LaunchProfile::applyLibrary(LibraryPtr library) +{ + if(!library->isActive()) + { + return; + } + + QList * list = &m_libraries; + if(library->isNative()) + { + list = &m_nativeLibraries; + } + + auto libraryCopy = Library::limitedCopy(library); + + // find the library by name. + const int index = findLibraryByName(list, library->rawName()); + // library not found? just add it. + if (index < 0) + { + list->append(libraryCopy); + return; + } + + auto existingLibrary = list->at(index); + // if we are higher it means we should update + if (Version(library->version()) > Version(existingLibrary->version())) + { + list->replace(index, libraryCopy); + } +} + +const LibraryPtr LaunchProfile::getMainJar() const +{ + return m_mainJar; +} + +void LaunchProfile::applyMainJar(LibraryPtr jar) +{ + if(jar) + { + m_mainJar = jar; + } +} + +void LaunchProfile::applyProblemSeverity(ProblemSeverity severity) +{ + if (m_problemSeverity < severity) + { + m_problemSeverity = severity; + } +} + +const QList LaunchProfile::getProblems() const +{ + // FIXME: implement something that actually makes sense here + return {}; +} + +QString LaunchProfile::getMinecraftVersion() const +{ + return m_minecraftVersion; +} + +QString LaunchProfile::getAppletClass() const +{ + return m_appletClass; +} + +QString LaunchProfile::getMainClass() const +{ + return m_mainClass; +} + +const QSet &LaunchProfile::getTraits() const +{ + return m_traits; +} + +const QStringList & LaunchProfile::getTweakers() const +{ + return m_tweakers; +} + +bool LaunchProfile::hasTrait(const QString& trait) const +{ + return m_traits.contains(trait); +} + +ProblemSeverity LaunchProfile::getProblemSeverity() const +{ + return m_problemSeverity; +} + +QString LaunchProfile::getMinecraftVersionType() const +{ + return m_minecraftVersionType; +} + +std::shared_ptr LaunchProfile::getMinecraftAssets() const +{ + if(!m_minecraftAssets) + { + return std::make_shared("legacy"); + } + return m_minecraftAssets; +} + +QString LaunchProfile::getMinecraftArguments() const +{ + return m_minecraftArguments; +} + +const QList & LaunchProfile::getJarMods() const +{ + return m_jarMods; +} + +const QList & LaunchProfile::getLibraries() const +{ + return m_libraries; +} + +const QList & LaunchProfile::getNativeLibraries() const +{ + return m_nativeLibraries; +} + +void LaunchProfile::getLibraryFiles( + const QString& architecture, + QStringList& jars, + QStringList& nativeJars, + const QString& overridePath, + const QString& tempPath +) const +{ + QStringList native32, native64; + jars.clear(); + nativeJars.clear(); + for (auto lib : getLibraries()) + { + lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath); + } + // NOTE: order is important here, add main jar last to the lists + if(m_mainJar) + { + // FIXME: HACK!! jar modding is weird and unsystematic! + if(m_jarMods.size()) + { + QDir tempDir(tempPath); + jars.append(tempDir.absoluteFilePath("minecraft.jar")); + } + else + { + m_mainJar->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); + } + else if(architecture == "64") + { + nativeJars.append(native64); + } +} diff --git a/api/logic/minecraft/LaunchProfile.h b/api/logic/minecraft/LaunchProfile.h new file mode 100644 index 00000000..e7f5f4af --- /dev/null +++ b/api/logic/minecraft/LaunchProfile.h @@ -0,0 +1,99 @@ +#pragma once +#include +#include "Library.h" +#include + +class LaunchProfile: public ProblemProvider +{ +public: + virtual ~LaunchProfile() {}; + +public: /* application of profile variables from patches */ + void applyMinecraftVersion(const QString& id); + void applyMainClass(const QString& mainClass); + void applyAppletClass(const QString& appletClass); + void applyMinecraftArguments(const QString& minecraftArguments); + void applyMinecraftVersionType(const QString& type); + void applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets); + void applyTraits(const QSet &traits); + void applyTweakers(const QStringList &tweakers); + void applyJarMods(const QList &jarMods); + void applyMods(const QList &jarMods); + void applyLibrary(LibraryPtr library); + void applyMainJar(LibraryPtr jar); + void applyProblemSeverity(ProblemSeverity severity); + /// clear the profile + void clear(); + +public: /* getters for profile variables */ + QString getMinecraftVersion() const; + QString getMainClass() const; + QString getAppletClass() const; + QString getMinecraftVersionType() const; + MojangAssetIndexInfo::Ptr getMinecraftAssets() const; + QString getMinecraftArguments() const; + const QSet & getTraits() const; + const QStringList & getTweakers() const; + const QList & getJarMods() const; + const QList & getLibraries() const; + const QList & getNativeLibraries() const; + const LibraryPtr getMainJar() const; + void getLibraryFiles( + const QString & architecture, + QStringList & jars, + QStringList & nativeJars, + const QString & overridePath, + const QString & tempPath + ) const; + bool hasTrait(const QString & trait) const; + ProblemSeverity getProblemSeverity() const override; + const QList getProblems() const override; + +private: + /// the version of Minecraft - jar to use + QString m_minecraftVersion; + + /// Release type - "release" or "snapshot" + QString m_minecraftVersionType; + + /// Assets type - "legacy" or a version ID + MojangAssetIndexInfo::Ptr m_minecraftAssets; + + /** + * arguments that should be used for launching minecraft + * + * ex: "--username ${auth_player_name} --session ${auth_session} + * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" + */ + QString m_minecraftArguments; + + /// A list of all tweaker classes + QStringList m_tweakers; + + /// The main class to load first + QString m_mainClass; + + /// The applet class, for some very old minecraft releases + QString m_appletClass; + + /// the list of libraries + QList m_libraries; + + /// the main jar + LibraryPtr m_mainJar; + + /// the list of libraries + QList m_nativeLibraries; + + /// traits, collected from all the version files (version files can only add) + QSet m_traits; + + /// A list of jar mods. version files can add those. + QList m_jarMods; + + /// the list of mods + QList m_mods; + + ProblemSeverity m_problemSeverity = ProblemSeverity::None; + +}; diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index e01d2616..76e70e5b 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -133,38 +133,39 @@ bool MinecraftInstance::reload() void MinecraftInstance::createProfile() { - m_profile.reset(new ComponentList(this)); + m_components.reset(new ComponentList(this)); } void MinecraftInstance::reloadProfile() { - m_profile->reload(); - setVersionBroken(m_profile->getProblemSeverity() == ProblemSeverity::Error); + m_components->reload(); emit versionReloaded(); } void MinecraftInstance::clearProfile() { - m_profile->clear(); + m_components->clearProfile(); emit versionReloaded(); } std::shared_ptr MinecraftInstance::getComponentList() const { - return m_profile; + return m_components; } QSet MinecraftInstance::traits() const { - auto version = getComponentList(); - if (!version) + auto components = getComponentList(); + if (!components) { return {"version-incomplete"}; } - else + auto profile = components->getProfile(); + if (!profile) { - return version->getTraits(); + return {"version-incomplete"}; } + return profile->getTraits(); } QString MinecraftInstance::minecraftRoot() const @@ -254,20 +255,23 @@ QStringList MinecraftInstance::getClassPath() const { QStringList jars, nativeJars; auto javaArchitecture = settings()->get("JavaArchitecture").toString(); - m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); + auto profile = m_components->getProfile(); + profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); return jars; } QString MinecraftInstance::getMainClass() const { - return m_profile->getMainClass(); + auto profile = m_components->getProfile(); + return profile->getMainClass(); } QStringList MinecraftInstance::getNativeJars() const { QStringList jars, nativeJars; auto javaArchitecture = settings()->get("JavaArchitecture").toString(); - m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); + auto profile = m_components->getProfile(); + profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); return nativeJars; } @@ -298,11 +302,11 @@ QStringList MinecraftInstance::javaArguments() const args << "-Xdock:icon=icon.png"; args << QString("-Xdock:name=\"%1\"").arg(windowTitle()); #endif - auto traits = m_profile->getTraits(); + auto traits_ = traits(); // HACK: fix issues on macOS with 1.13 snapshots // NOTE: Oracle Java option. if there are alternate jvm implementations, this would be the place to customize this for them #ifdef Q_OS_MAC - if(traits.contains("FirstThreadOnMacOS")) + if(traits_.contains("FirstThreadOnMacOS")) { args << QString("-XstartOnFirstThread"); } @@ -395,8 +399,9 @@ static QString replaceTokensIn(QString text, QMap with) QStringList MinecraftInstance::processMinecraftArgs(AuthSessionPtr session) const { - QString args_pattern = m_profile->getMinecraftArguments(); - for (auto tweaker : m_profile->getTweakers()) + auto profile = m_components->getProfile(); + QString args_pattern = profile->getMinecraftArguments(); + for (auto tweaker : profile->getTweakers()) { args_pattern += " --tweakClass " + tweaker; } @@ -416,9 +421,9 @@ QStringList MinecraftInstance::processMinecraftArgs(AuthSessionPtr session) cons // blatant self-promotion. token_mapping["profile_name"] = token_mapping["version_name"] = "MultiMC5"; - if(m_profile->isVanilla()) + if(m_components->isVanilla()) { - token_mapping["version_type"] = m_profile->getMinecraftVersionType(); + token_mapping["version_type"] = profile->getMinecraftVersionType(); } else { @@ -428,7 +433,7 @@ QStringList MinecraftInstance::processMinecraftArgs(AuthSessionPtr session) cons QString absRootDir = QDir(minecraftRoot()).absolutePath(); token_mapping["game_directory"] = absRootDir; QString absAssetsDir = QDir("assets/").absolutePath(); - auto assets = m_profile->getMinecraftAssets(); + auto assets = profile->getMinecraftAssets(); // FIXME: this is wrong and should be run as an async task token_mapping["game_assets"] = AssetsUtils::reconstructAssets(assets->id).absolutePath(); @@ -448,15 +453,18 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session) { QString launchScript; - if (!m_profile) - return nullptr; + if (!m_components) + return QString(); + auto profile = m_components->getProfile(); + if(!profile) + return QString(); auto mainClass = getMainClass(); if (!mainClass.isEmpty()) { launchScript += "mainClass " + mainClass + "\n"; } - auto appletClass = m_profile->getAppletClass(); + auto appletClass = profile->getAppletClass(); if (!appletClass.isEmpty()) { launchScript += "appletClass " + appletClass + "\n"; @@ -492,7 +500,7 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session) { QStringList jars, nativeJars; auto javaArchitecture = settings()->get("JavaArchitecture").toString(); - m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); + profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); for(auto file: jars) { launchScript += "cp " + file + "\n"; @@ -504,7 +512,7 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session) launchScript += "natives " + getNativePath() + "\n"; } - for (auto trait : m_profile->getTraits()) + for (auto trait : profile->getTraits()) { launchScript += "traits " + trait + "\n"; } @@ -519,6 +527,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session) out << "Main Class:" << " " + getMainClass() << ""; out << "Native path:" << " " + getNativePath() << ""; + auto profile = m_components->getProfile(); auto alltraits = traits(); if(alltraits.size()) @@ -536,7 +545,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session) out << "Libraries:"; QStringList jars, nativeJars; auto javaArchitecture = settings()->get("JavaArchitecture").toString(); - m_profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); + profile->getLibraryFiles(javaArchitecture, jars, nativeJars, getLocalLibraryPath(), binRoot()); auto printLibFile = [&](const QString & path) { QFileInfo info(path); @@ -594,7 +603,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session) out << ""; } - auto & jarMods = m_profile->getJarMods(); + auto & jarMods = profile->getJarMods(); if(jarMods.size()) { out << "Jar Mods:"; @@ -989,8 +998,9 @@ std::shared_ptr MinecraftInstance::worldList() const QList< Mod > MinecraftInstance::getJarMods() const { + auto profile = m_components->getProfile(); QList mods; - for (auto jarmod : m_profile->getJarMods()) + for (auto jarmod : profile->getJarMods()) { QStringList jar, temp1, temp2, temp3; jarmod->getApplicableFiles(currentSystem, jar, temp1, temp2, temp3, jarmodsPath().absolutePath()); diff --git a/api/logic/minecraft/MinecraftInstance.h b/api/logic/minecraft/MinecraftInstance.h index 417098da..cea7c60a 100644 --- a/api/logic/minecraft/MinecraftInstance.h +++ b/api/logic/minecraft/MinecraftInstance.h @@ -19,7 +19,9 @@ public: virtual ~MinecraftInstance() {}; virtual void init() override; + // FIXME: remove QString typeName() const override; + // FIXME: remove QSet traits() const override; bool canEdit() const override @@ -91,15 +93,21 @@ public: QString getStatusbarDescription() override; + // FIXME: remove virtual QStringList getClassPath() const; + // FIXME: remove virtual QStringList getNativeJars() const; + // FIXME: remove virtual QString getMainClass() const; + // FIXME: remove virtual QStringList processMinecraftArgs(AuthSessionPtr account) const; virtual JavaVersion getJavaVersion() const; + // FIXME: remove QString getComponentVersion(const QString &uid) const; + // FIXME: remove bool setComponentVersion(const QString &uid, const QString &version); signals: @@ -114,7 +122,7 @@ private: QString prettifyTimeDuration(int64_t duration); protected: // data - std::shared_ptr m_profile; + std::shared_ptr m_components; mutable std::shared_ptr m_loader_mod_list; mutable std::shared_ptr m_core_mod_list; mutable std::shared_ptr m_resource_pack_list; diff --git a/api/logic/minecraft/ProfilePatch.cpp b/api/logic/minecraft/ProfilePatch.cpp index b8b5c240..b7a5a37a 100644 --- a/api/logic/minecraft/ProfilePatch.cpp +++ b/api/logic/minecraft/ProfilePatch.cpp @@ -22,7 +22,7 @@ std::shared_ptr ProfilePatch::getMeta() return m_metaVersion; } -void ProfilePatch::applyTo(ComponentList* profile) +void ProfilePatch::applyTo(LaunchProfile* profile) { auto vfile = getVersionFile(); if(vfile) @@ -35,7 +35,7 @@ void ProfilePatch::applyTo(ComponentList* profile) } } -std::shared_ptr ProfilePatch::getVersionFile() +std::shared_ptr ProfilePatch::getVersionFile() const { if(m_metaVersion) { @@ -51,7 +51,7 @@ std::shared_ptr ProfilePatch::getVersionFile() } } -std::shared_ptr ProfilePatch::getVersionList() +std::shared_ptr ProfilePatch::getVersionList() const { if(m_metaVersion) { @@ -167,7 +167,7 @@ void ProfilePatch::setMovable (bool state) m_isMovable = state; } -ProblemSeverity ProfilePatch::getProblemSeverity() +ProblemSeverity ProfilePatch::getProblemSeverity() const { auto file = getVersionFile(); if(file) @@ -177,7 +177,7 @@ ProblemSeverity ProfilePatch::getProblemSeverity() return ProblemSeverity::Error; } -const QList ProfilePatch::getProblems() +const QList ProfilePatch::getProblems() const { auto file = getVersionFile(); if(file) diff --git a/api/logic/minecraft/ProfilePatch.h b/api/logic/minecraft/ProfilePatch.h index af5e89a4..80825342 100644 --- a/api/logic/minecraft/ProfilePatch.h +++ b/api/logic/minecraft/ProfilePatch.h @@ -7,6 +7,7 @@ #include "ProblemProvider.h" class ComponentList; +class LaunchProfile; namespace Meta { class Version; @@ -21,7 +22,7 @@ public: ProfilePatch(std::shared_ptr file, const QString &filename = QString()); virtual ~ProfilePatch(){}; - virtual void applyTo(ComponentList *profile); + virtual void applyTo(LaunchProfile *profile); virtual bool isMoveable(); virtual bool isCustomizable(); @@ -41,16 +42,16 @@ public: virtual QString getFilename(); - virtual std::shared_ptr getVersionFile(); - virtual std::shared_ptr getVersionList(); + virtual std::shared_ptr getVersionFile() const; + virtual std::shared_ptr getVersionList() const; void setVanilla (bool state); void setRemovable (bool state); void setRevertible (bool state); void setMovable (bool state); - const QList getProblems() override; - ProblemSeverity getProblemSeverity() override; + const QList getProblems() const override; + ProblemSeverity getProblemSeverity() const override; protected: // Properties for UI and version manipulation from UI in general diff --git a/api/logic/minecraft/VersionFile.cpp b/api/logic/minecraft/VersionFile.cpp index 65675873..9f485c55 100644 --- a/api/logic/minecraft/VersionFile.cpp +++ b/api/logic/minecraft/VersionFile.cpp @@ -15,7 +15,7 @@ static bool isMinecraftVersion(const QString &uid) return uid == "net.minecraft"; } -void VersionFile::applyTo(ComponentList *profile) +void VersionFile::applyTo(LaunchProfile *profile) { // Only real Minecraft can set those. Don't let anything override them. if (isMinecraftVersion(uid)) diff --git a/api/logic/minecraft/VersionFile.h b/api/logic/minecraft/VersionFile.h index 001b696c..60acaad6 100644 --- a/api/logic/minecraft/VersionFile.h +++ b/api/logic/minecraft/VersionFile.h @@ -13,6 +13,7 @@ class ComponentList; class VersionFile; +class LaunchProfile; struct MojangDownloadInfo; struct MojangAssetIndexInfo; @@ -22,7 +23,7 @@ class VersionFile : public ProblemContainer friend class MojangVersionFormat; friend class OneSixVersionFormat; public: /* methods */ - void applyTo(ComponentList *profile); + void applyTo(LaunchProfile* profile); public: /* data */ /// MultiMC: order hint for this version file if no explicit order is set diff --git a/api/logic/minecraft/launch/ModMinecraftJar.cpp b/api/logic/minecraft/launch/ModMinecraftJar.cpp index 14b00447..6407ade0 100644 --- a/api/logic/minecraft/launch/ModMinecraftJar.cpp +++ b/api/logic/minecraft/launch/ModMinecraftJar.cpp @@ -42,7 +42,8 @@ void ModMinecraftJar::executeTask() } // create temporary modded jar, if needed - auto profile = m_inst->getComponentList(); + auto components = m_inst->getComponentList(); + auto profile = components->getProfile(); auto jarMods = m_inst->getJarMods(); if(jarMods.size()) { diff --git a/api/logic/minecraft/update/AssetUpdateTask.cpp b/api/logic/minecraft/update/AssetUpdateTask.cpp index 6919e0a6..2ad2b5b2 100644 --- a/api/logic/minecraft/update/AssetUpdateTask.cpp +++ b/api/logic/minecraft/update/AssetUpdateTask.cpp @@ -12,7 +12,8 @@ AssetUpdateTask::AssetUpdateTask(MinecraftInstance * inst) void AssetUpdateTask::executeTask() { setStatus(tr("Updating assets index...")); - auto profile = m_inst->getComponentList(); + auto components = m_inst->getComponentList(); + auto profile = components->getProfile(); auto assets = profile->getMinecraftAssets(); QUrl indexUrl = assets->url; QString localPath = assets->id + ".json"; @@ -48,7 +49,8 @@ void AssetUpdateTask::assetIndexFinished() AssetsIndex index; qDebug() << m_inst->name() << ": Finished asset index download"; - auto profile = m_inst->getComponentList(); + auto components = m_inst->getComponentList(); + auto profile = components->getProfile(); auto assets = profile->getMinecraftAssets(); QString asset_fname = "assets/indexes/" + assets->id + ".json"; diff --git a/api/logic/minecraft/update/FMLLibrariesTask.cpp b/api/logic/minecraft/update/FMLLibrariesTask.cpp index e64b7a82..56ecee43 100644 --- a/api/logic/minecraft/update/FMLLibrariesTask.cpp +++ b/api/logic/minecraft/update/FMLLibrariesTask.cpp @@ -13,7 +13,8 @@ void FMLLibrariesTask::executeTask() { // Get the mod list MinecraftInstance *inst = (MinecraftInstance *)m_inst; - std::shared_ptr profile = inst->getComponentList(); + auto components = inst->getComponentList(); + auto profile = components->getProfile(); bool forge_present = false; if (!profile->hasTrait("legacyFML")) @@ -34,7 +35,7 @@ void FMLLibrariesTask::executeTask() // determine if we need some libs for FML or forge setStatus(tr("Checking for FML libraries...")); - forge_present = (profile->versionPatch("net.minecraftforge") != nullptr); + forge_present = (components->versionPatch("net.minecraftforge") != nullptr); // we don't... if (!forge_present) { diff --git a/api/logic/minecraft/update/LibrariesTask.cpp b/api/logic/minecraft/update/LibrariesTask.cpp index bbbd5f02..80d45d97 100644 --- a/api/logic/minecraft/update/LibrariesTask.cpp +++ b/api/logic/minecraft/update/LibrariesTask.cpp @@ -21,7 +21,8 @@ void LibrariesTask::executeTask() } // Build a list of URLs that will need to be downloaded. - std::shared_ptr profile = inst->getComponentList(); + auto components = inst->getComponentList(); + auto profile = components->getProfile(); auto job = new NetJob(tr("Libraries for instance %1").arg(inst->name())); downloadJob.reset(job); -- cgit v1.2.3