From 5fabb4f2546fa6b79a4e2c29679f506e587a0070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 27 Mar 2017 03:34:39 +0200 Subject: NOISSUE Rough refactor of ProfilePatch and VersionFile internals. They are now distinct classes with distinct responsibilities. * ProfilePatch is an entry in MinecraftProfile and can hold VersionFile or Meta::Version. * VersionFile is the basic element that holds version information loaded from JSON. * Meta::Version is the loader class for VersionFile(s) from a server. --- api/logic/BaseVersionList.cpp | 2 +- api/logic/BaseVersionList.h | 2 +- api/logic/CMakeLists.txt | 1 + api/logic/ProblemProvider.h | 54 ++++++ api/logic/meta/Version.cpp | 2 +- api/logic/meta/VersionList.cpp | 4 +- api/logic/minecraft/MinecraftProfile.cpp | 6 +- api/logic/minecraft/MinecraftProfile.h | 4 +- api/logic/minecraft/MojangVersionFormat.cpp | 18 +- api/logic/minecraft/ProfilePatch.cpp | 214 +++++++++++++++++++++ api/logic/minecraft/ProfilePatch.h | 104 ++++------ api/logic/minecraft/ProfileStrategy.h | 1 + api/logic/minecraft/ProfileUtils.cpp | 4 +- api/logic/minecraft/VersionBuildError.h | 17 -- api/logic/minecraft/VersionFile.cpp | 35 ++-- api/logic/minecraft/VersionFile.h | 108 +---------- api/logic/minecraft/ftb/FTBProfileStrategy.cpp | 8 +- api/logic/minecraft/onesix/OneSixInstance.cpp | 2 +- .../minecraft/onesix/OneSixProfileStrategy.cpp | 178 +++++------------ api/logic/minecraft/onesix/OneSixVersionFormat.cpp | 19 +- application/VersionProxyModel.cpp | 6 +- application/pages/VersionPage.cpp | 16 +- 22 files changed, 431 insertions(+), 374 deletions(-) create mode 100644 api/logic/ProblemProvider.h create mode 100644 api/logic/minecraft/ProfilePatch.cpp diff --git a/api/logic/BaseVersionList.cpp b/api/logic/BaseVersionList.cpp index 5ad4df3c..dae604a2 100644 --- a/api/logic/BaseVersionList.cpp +++ b/api/logic/BaseVersionList.cpp @@ -93,7 +93,7 @@ QHash BaseVersionList::roleNames() const QHash roles = QAbstractListModel::roleNames(); roles.insert(VersionRole, "version"); roles.insert(VersionIdRole, "versionId"); - roles.insert(ParentGameVersionRole, "parentGameVersion"); + roles.insert(ParentVersionRole, "parentGameVersion"); roles.insert(RecommendedRole, "recommended"); roles.insert(LatestRole, "latest"); roles.insert(TypeRole, "type"); diff --git a/api/logic/BaseVersionList.h b/api/logic/BaseVersionList.h index 8afcae1d..eb3b622a 100644 --- a/api/logic/BaseVersionList.h +++ b/api/logic/BaseVersionList.h @@ -45,7 +45,7 @@ public: VersionPointerRole = Qt::UserRole, VersionRole, VersionIdRole, - ParentGameVersionRole, + ParentVersionRole, RecommendedRole, LatestRole, TypeRole, diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 7f04a41e..da673c13 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -267,6 +267,7 @@ set(MINECRAFT_SOURCES minecraft/VersionBuildError.h minecraft/VersionFile.cpp minecraft/VersionFile.h + minecraft/ProfilePatch.cpp minecraft/ProfilePatch.h minecraft/VersionFilterData.h minecraft/VersionFilterData.cpp diff --git a/api/logic/ProblemProvider.h b/api/logic/ProblemProvider.h new file mode 100644 index 00000000..64a31c59 --- /dev/null +++ b/api/logic/ProblemProvider.h @@ -0,0 +1,54 @@ +#pragma once + +enum class ProblemSeverity +{ + None, + Warning, + Error +}; + +class PatchProblem +{ +public: + PatchProblem(ProblemSeverity severity, const QString & description) + { + m_severity = severity; + m_description = description; + } + const QString & getDescription() const + { + return m_description; + } + const ProblemSeverity getSeverity() const + { + return m_severity; + } +private: + ProblemSeverity m_severity; + QString m_description; +}; + +class ProblemProvider +{ +public: + virtual const QList& getProblems() + { + return m_problems; + } + virtual void addProblem(ProblemSeverity severity, const QString &description) + { + if(severity > m_problemSeverity) + { + m_problemSeverity = severity; + } + m_problems.append(PatchProblem(severity, description)); + } + virtual ProblemSeverity getProblemSeverity() + { + return m_problemSeverity; + } + +private: + QList m_problems; + ProblemSeverity m_problemSeverity = ProblemSeverity::None; +}; diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index af9d4f10..2a8e1780 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -32,7 +32,7 @@ QString Meta::Version::descriptor() QString Meta::Version::name() { if(m_data) - return m_data->getName(); + return m_data->name; return m_uid; } QString Meta::Version::typeString() const diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index c2712155..41ed1352 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -73,7 +73,7 @@ QVariant VersionList::data(const QModelIndex &index, int role) const case VersionRole: case VersionIdRole: return version->version(); - case ParentGameVersionRole: + case ParentVersionRole: { auto parentUid = this->parentUid(); if(parentUid.isEmpty()) @@ -102,7 +102,7 @@ QVariant VersionList::data(const QModelIndex &index, int role) const BaseVersionList::RoleList VersionList::providesRoles() const { - return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, + return {VersionPointerRole, VersionRole, VersionIdRole, ParentVersionRole, TypeRole, UidRole, TimeRole, RequiresRole, SortRole, RecommendedRole, LatestRole, VersionPtrRole}; } diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp index b74141d6..8638f5fa 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(); diff --git a/api/logic/minecraft/MinecraftProfile.h b/api/logic/minecraft/MinecraftProfile.h index a6845e9c..a3b8fb61 100644 --- a/api/logic/minecraft/MinecraftProfile.h +++ b/api/logic/minecraft/MinecraftProfile.h @@ -22,7 +22,7 @@ #include #include "Library.h" -#include "VersionFile.h" +#include "ProfilePatch.h" #include "JarMod.h" #include "BaseVersion.h" #include "MojangDownloadInfo.h" @@ -175,7 +175,7 @@ private: /* data */ /// A list of jar mods. version files can add those. QList 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/MojangVersionFormat.cpp b/api/logic/minecraft/MojangVersionFormat.cpp index 651e2fbc..ea8dcd4d 100644 --- a/api/logic/minecraft/MojangVersionFormat.cpp +++ b/api/logic/minecraft/MojangVersionFormat.cpp @@ -151,7 +151,7 @@ void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFi } else if (!toCompare.isEmpty()) { - out->addProblem(PROBLEM_ERROR, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments)); + out->addProblem(ProblemSeverity::Error, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments)); } } Bits::readString(in, "type", out->type); @@ -166,8 +166,8 @@ void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFi out->mojangAssetIndex = std::make_shared(out->assets); } - out->m_releaseTime = timeFromS3Time(in.value("releaseTime").toString("")); - out->m_updateTime = timeFromS3Time(in.value("time").toString("")); + out->releaseTime = timeFromS3Time(in.value("releaseTime").toString("")); + out->updateTime = timeFromS3Time(in.value("time").toString("")); if (in.contains("minimumLauncherVersion")) { @@ -175,7 +175,7 @@ void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFi if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION) { out->addProblem( - PROBLEM_WARNING, + ProblemSeverity::Warning, QObject::tr("The 'minimumLauncherVersion' value of this version (%1) is higher than supported by MultiMC (%2). It might not work properly!") .arg(out->minimumLauncherVersion) .arg(CURRENT_MINIMUM_LAUNCHER_VERSION)); @@ -212,7 +212,7 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc out->name = "Minecraft"; out->uid = "net.minecraft"; out->version = out->minecraftVersion; - out->filename = filename; + // out->filename = filename; if (root.contains("libraries")) @@ -234,13 +234,13 @@ void MojangVersionFormat::writeVersionProperties(const VersionFile* in, QJsonObj writeString(out, "mainClass", in->mainClass); writeString(out, "minecraftArguments", in->minecraftArguments); writeString(out, "type", in->type); - if(!in->m_releaseTime.isNull()) + if(!in->releaseTime.isNull()) { - writeString(out, "releaseTime", timeToS3Time(in->m_releaseTime)); + writeString(out, "releaseTime", timeToS3Time(in->releaseTime)); } - if(!in->m_updateTime.isNull()) + if(!in->updateTime.isNull()) { - writeString(out, "time", timeToS3Time(in->m_updateTime)); + writeString(out, "time", timeToS3Time(in->updateTime)); } if(in->minimumLauncherVersion != -1) { diff --git a/api/logic/minecraft/ProfilePatch.cpp b/api/logic/minecraft/ProfilePatch.cpp new file mode 100644 index 00000000..0ff5895d --- /dev/null +++ b/api/logic/minecraft/ProfilePatch.cpp @@ -0,0 +1,214 @@ +#include "ProfilePatch.h" + +#include "meta/Version.h" +#include "VersionFile.h" + +ProfilePatch::ProfilePatch(std::shared_ptr version) + :m_metaVersion(version) +{ +} + +ProfilePatch::ProfilePatch(std::shared_ptr file, const QString& filename) + :m_file(file), m_filename(filename) +{ +} + +void ProfilePatch::applyTo(MinecraftProfile* profile) +{ + auto vfile = getVersionFile(); + if(vfile) + { + vfile->applyTo(profile); + } +} + +std::shared_ptr ProfilePatch::getVersionFile() +{ + if(m_metaVersion) + { + if(!m_metaVersion->isLoaded()) + { + m_metaVersion->load(); + } + return m_metaVersion->data(); + } + return m_file; +} + +int ProfilePatch::getOrder() +{ + if(m_orderOverride) + return m_order; + + auto vfile = getVersionFile(); + if(vfile) + { + return vfile->order; + } + return 0; +} +void ProfilePatch::setOrder(int order) +{ + m_orderOverride = true; + m_order = order; +} +QString ProfilePatch::getID() +{ + if(m_metaVersion) + return m_metaVersion->uid(); + return getVersionFile()->uid; +} +QString ProfilePatch::getName() +{ + if(m_metaVersion) + return m_metaVersion->name(); + return getVersionFile()->name; +} +QString ProfilePatch::getVersion() +{ + if(m_metaVersion) + return m_metaVersion->version(); + return getVersionFile()->version; +} +QString ProfilePatch::getFilename() +{ + return m_filename; +} +QDateTime ProfilePatch::getReleaseDateTime() +{ + if(m_metaVersion) + { + return m_metaVersion->time(); + } + return getVersionFile()->releaseTime; +} + +bool ProfilePatch::isCustom() +{ + return !m_isVanilla; +}; + +bool ProfilePatch::isCustomizable() +{ + if(m_metaVersion) + { + if(getVersionFile()) + { + return true; + } + } + return false; +} +bool ProfilePatch::isRemovable() +{ + return m_isRemovable; +} +bool ProfilePatch::isRevertible() +{ + return m_isRevertible; +} +bool ProfilePatch::isMoveable() +{ + return m_isMovable; +} +bool ProfilePatch::isVersionChangeable() +{ + return false; +} + +void ProfilePatch::setVanilla (bool state) +{ + m_isVanilla = state; +} +void ProfilePatch::setRemovable (bool state) +{ + m_isRemovable = state; +} +void ProfilePatch::setRevertible (bool state) +{ + m_isRevertible = state; +} +void ProfilePatch::setMovable (bool state) +{ + m_isMovable = state; +} + +/* +class MetaPatchProvider : public ProfilePatch +{ +public: + MetaPatchProvider(std::shared_ptr data) + :m_version(data) + { + } +public: + QString getFilename() override + { + return QString(); + } + QString getID() override + { + return m_version->uid(); + } + QString getName() override + { + auto vfile = getFile(); + if(vfile) + { + return vfile->name; + } + return m_version->name(); + } + QDateTime getReleaseDateTime() override + { + return m_version->time(); + } + QString getVersion() override + { + return m_version->version(); + } + std::shared_ptr getVersionFile() override + { + return m_version->data(); + } + void setOrder(int) override + { + } + int getOrder() override + { + return 0; + } + bool isVersionChangeable() override + { + return true; + } + bool isRevertible() override + { + return false; + } + bool isRemovable() override + { + return true; + } + bool isCustom() override + { + return false; + } + bool isCustomizable() override + { + return true; + } + bool isMoveable() override + { + return true; + } + +private: + VersionFilePtr getFile() + { + + } +private: + std::shared_ptr m_version; +}; +*/ \ No newline at end of file diff --git a/api/logic/minecraft/ProfilePatch.h b/api/logic/minecraft/ProfilePatch.h index 699a38ae..9e2555af 100644 --- a/api/logic/minecraft/ProfilePatch.h +++ b/api/logic/minecraft/ProfilePatch.h @@ -5,85 +5,63 @@ #include #include #include "JarMod.h" +#include "ProblemProvider.h" class MinecraftProfile; - -enum ProblemSeverity +namespace Meta { - PROBLEM_NONE, - PROBLEM_WARNING, - PROBLEM_ERROR -}; + class Version; +} +class VersionFile; -class PatchProblem +class ProfilePatch : public ProblemProvider { public: - PatchProblem(ProblemSeverity severity, const QString & description) - { - m_severity = severity; - m_description = description; - } - const QString & getDescription() const - { - return m_description; - } - const ProblemSeverity getSeverity() const - { - return m_severity; - } -private: - ProblemSeverity m_severity; - QString m_description; -}; + ProfilePatch(std::shared_ptr version); + ProfilePatch(std::shared_ptr file, const QString &filename = QString()); -class ProfilePatch : public std::enable_shared_from_this -{ -public: virtual ~ProfilePatch(){}; - virtual void applyTo(MinecraftProfile *profile) = 0; - - virtual bool isMinecraftVersion() = 0; + virtual void applyTo(MinecraftProfile *profile); - virtual bool isMoveable() = 0; - virtual bool isCustomizable() = 0; - virtual bool isRevertible() = 0; - virtual bool isRemovable() = 0; - virtual bool isCustom() = 0; - virtual bool isEditable() = 0; - virtual bool isVersionChangeable() = 0; + virtual bool isMoveable(); + virtual bool isCustomizable(); + virtual bool isRevertible(); + virtual bool isRemovable(); + virtual bool isCustom(); + virtual bool isVersionChangeable(); - virtual void setOrder(int order) = 0; - virtual int getOrder() = 0; + virtual void setOrder(int order); + virtual int getOrder(); - virtual QString getID() = 0; - virtual QString getName() = 0; - virtual QString getVersion() = 0; - virtual QDateTime getReleaseDateTime() = 0; + virtual QString getID(); + virtual QString getName(); + virtual QString getVersion(); + virtual QDateTime getReleaseDateTime(); - virtual QString getFilename() = 0; + virtual QString getFilename(); - virtual std::shared_ptr getVersionFile() = 0; + virtual std::shared_ptr getVersionFile(); - virtual const QList& getProblems() - { - return m_problems; - } - virtual void addProblem(ProblemSeverity severity, const QString &description) - { - if(severity > m_problemSeverity) - { - m_problemSeverity = severity; - } - m_problems.append(PatchProblem(severity, description)); - } - virtual ProblemSeverity getProblemSeverity() - { - return m_problemSeverity; - } + void setVanilla (bool state); + void setRemovable (bool state); + void setRevertible (bool state); + void setCustomizable (bool state); + void setMovable (bool state); protected: - QList m_problems; - ProblemSeverity m_problemSeverity = PROBLEM_NONE; + // Properties for UI and version manipulation from UI in general + bool m_isMovable = false; + bool m_isCustomizable = false; + bool m_isRevertible = false; + bool m_isRemovable = false; + bool m_isVanilla = false; + + bool m_orderOverride = false; + int m_order = 0; + + std::shared_ptr m_metaVersion; + std::shared_ptr m_file; + QString m_filename; }; typedef std::shared_ptr ProfilePatchPtr; diff --git a/api/logic/minecraft/ProfileStrategy.h b/api/logic/minecraft/ProfileStrategy.h index b4dfc4b3..26bdf661 100644 --- a/api/logic/minecraft/ProfileStrategy.h +++ b/api/logic/minecraft/ProfileStrategy.h @@ -1,6 +1,7 @@ #pragma once #include "ProfileUtils.h" +#include "ProfilePatch.h" class MinecraftProfile; diff --git a/api/logic/minecraft/ProfileUtils.cpp b/api/logic/minecraft/ProfileUtils.cpp index c7c56dd6..8c5bc052 100644 --- a/api/logic/minecraft/ProfileUtils.cpp +++ b/api/logic/minecraft/ProfileUtils.cpp @@ -103,8 +103,8 @@ static VersionFilePtr createErrorVersionFile(QString fileId, QString filepath, Q { auto outError = std::make_shared(); outError->uid = outError->name = fileId; - outError->filename = filepath; - outError->addProblem(PROBLEM_ERROR, error); + // outError->filename = filepath; + outError->addProblem(ProblemSeverity::Error, error); return outError; } diff --git a/api/logic/minecraft/VersionBuildError.h b/api/logic/minecraft/VersionBuildError.h index fda453e5..f362c405 100644 --- a/api/logic/minecraft/VersionBuildError.h +++ b/api/logic/minecraft/VersionBuildError.h @@ -26,23 +26,6 @@ public: } }; -/** - * some patch was intended for a different version of minecraft - */ -class MinecraftVersionMismatch : public VersionBuildError -{ -public: - MinecraftVersionMismatch(QString fileId, QString mcVersion, QString parentMcVersion) - : VersionBuildError(QObject::tr("The patch %1 is for a different version of Minecraft " - "(%2) than that of the instance (%3).") - .arg(fileId) - .arg(mcVersion) - .arg(parentMcVersion)) {}; - virtual ~MinecraftVersionMismatch() noexcept - { - } -}; - /** * files required for the version are not (yet?) present */ diff --git a/api/logic/minecraft/VersionFile.cpp b/api/logic/minecraft/VersionFile.cpp index 17dc6a49..b261ff2a 100644 --- a/api/logic/minecraft/VersionFile.cpp +++ b/api/logic/minecraft/VersionFile.cpp @@ -12,32 +12,28 @@ #include "VersionBuildError.h" #include -bool VersionFile::isMinecraftVersion() +static bool isMinecraftVersion(const QString &uid) { return uid == "net.minecraft"; } void VersionFile::applyTo(MinecraftProfile *profile) { - auto theirVersion = profile->getMinecraftVersion(); - if (!theirVersion.isNull() && !dependsOnMinecraftVersion.isNull()) + // Only real Minecraft can set those. Don't let anything override them. + if (isMinecraftVersion(uid)) { - if (QRegExp(dependsOnMinecraftVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(theirVersion) == -1) - { - throw MinecraftVersionMismatch(uid, dependsOnMinecraftVersion, theirVersion); - } + profile->applyMinecraftVersion(minecraftVersion); + profile->applyMinecraftVersionType(type); + // HACK: ignore assets from other version files than Minecraft + // workaround for stupid assets issue caused by amazon: + // https://www.theregister.co.uk/2017/02/28/aws_is_awol_as_s3_goes_haywire/ + profile->applyMinecraftAssets(mojangAssetIndex); } - profile->applyMinecraftVersion(minecraftVersion); + profile->applyMainClass(mainClass); profile->applyAppletClass(appletClass); profile->applyMinecraftArguments(minecraftArguments); - if (isMinecraftVersion()) - { - profile->applyMinecraftVersionType(type); - } - profile->applyMinecraftAssets(mojangAssetIndex); profile->applyTweakers(addTweakers); - profile->applyJarMods(jarMods); profile->applyTraits(traits); @@ -53,3 +49,14 @@ void VersionFile::applyTo(MinecraftProfile *profile) iter++; } } + +/* + auto theirVersion = profile->getMinecraftVersion(); + if (!theirVersion.isNull() && !dependsOnMinecraftVersion.isNull()) + { + if (QRegExp(dependsOnMinecraftVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(theirVersion) == -1) + { + throw MinecraftVersionMismatch(uid, dependsOnMinecraftVersion, theirVersion); + } + } +*/ \ No newline at end of file diff --git a/api/logic/minecraft/VersionFile.h b/api/logic/minecraft/VersionFile.h index dad9a057..a71c6228 100644 --- a/api/logic/minecraft/VersionFile.h +++ b/api/logic/minecraft/VersionFile.h @@ -8,7 +8,7 @@ #include #include "minecraft/OpSys.h" #include "minecraft/Rule.h" -#include "ProfilePatch.h" +#include "ProblemProvider.h" #include "Library.h" #include "JarMod.h" @@ -18,111 +18,19 @@ struct MojangDownloadInfo; struct MojangAssetIndexInfo; typedef std::shared_ptr VersionFilePtr; -class VersionFile : public ProfilePatch +class VersionFile : public ProblemProvider { friend class MojangVersionFormat; friend class OneSixVersionFormat; public: /* methods */ - virtual void applyTo(MinecraftProfile *profile) override; - virtual bool isMinecraftVersion() override; - virtual int getOrder() override - { - return order; - } - virtual void setOrder(int order) override - { - this->order = order; - } - virtual QString getID() override - { - return uid; - } - virtual QString getName() override - { - return name; - } - virtual QString getVersion() override - { - return version; - } - virtual QString getFilename() override - { - return filename; - } - virtual QDateTime getReleaseDateTime() override - { - return m_releaseTime; - } - - std::shared_ptr getVersionFile() override - { - return std::dynamic_pointer_cast(shared_from_this()); - } - - virtual bool isCustom() override - { - return !m_isVanilla; - }; - virtual bool isCustomizable() override - { - return m_isCustomizable; - } - virtual bool isRemovable() override - { - return m_isRemovable; - } - virtual bool isRevertible() override - { - return m_isRevertible; - } - virtual bool isMoveable() override - { - return m_isMovable; - } - virtual bool isEditable() override - { - return isCustom(); - } - virtual bool isVersionChangeable() override - { - return false; - } - - void setVanilla (bool state) - { - m_isVanilla = state; - } - void setRemovable (bool state) - { - m_isRemovable = state; - } - void setRevertible (bool state) - { - m_isRevertible = state; - } - void setCustomizable (bool state) - { - m_isCustomizable = state; - } - void setMovable (bool state) - { - m_isMovable = state; - } - + void applyTo(MinecraftProfile *profile); public: /* data */ - // Flags for UI and version file manipulation in general - bool m_isVanilla = false; - bool m_isRemovable = false; - bool m_isRevertible = false; - bool m_isCustomizable = false; - bool m_isMovable = false; - /// MultiMC: order hint for this version file if no explicit order is set int order = 0; /// MultiMC: filename of the file this was loaded from - QString filename; + // QString filename; /// MultiMC: human readable name of this package QString name; @@ -139,13 +47,13 @@ public: /* data */ /// Mojang: used to version the Mojang version format int minimumLauncherVersion = -1; - /// Mojang: version of Minecraft this is + /// Mojang: DEPRECATED version of Minecraft this is QString minecraftVersion; /// Mojang: class to launch Minecraft with QString mainClass; - /// MultiMC: DEPRECATED class to launch legacy Minecraft with (ambed in a custom window) + /// MultiMC: class to launch legacy Minecraft with (embed in a custom window) QString appletClass; /// Mojang: Minecraft launch arguments (may contain placeholders for variable substitution) @@ -155,10 +63,10 @@ public: /* data */ QString type; /// Mojang: the time this version was actually released by Mojang - QDateTime m_releaseTime; + QDateTime releaseTime; /// Mojang: the time this version was last updated by Mojang - QDateTime m_updateTime; + QDateTime updateTime; /// Mojang: DEPRECATED asset group to be used with Minecraft QString assets; diff --git a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp index 45765cd4..c3d9cc6a 100644 --- a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp +++ b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp @@ -29,7 +29,6 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false); file->uid = "net.minecraft"; file->name = QObject::tr("Minecraft (tracked)"); - file->setVanilla(true); if(file->version.isEmpty()) { file->version = mcVersion; @@ -39,7 +38,8 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() addLib->setHint("local"); addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath()); } - minecraftPatch = std::dynamic_pointer_cast(file); + minecraftPatch = std::make_shared(file); + minecraftPatch->setVanilla(true); } else { @@ -65,7 +65,6 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() addLib->setStoragePrefix(nativeInstance->librariesPath().absolutePath()); } file->uid = "org.multimc.ftb.pack"; - file->setVanilla(true); file->name = QObject::tr("%1 (FTB pack)").arg(m_instance->name()); if(file->version.isEmpty()) { @@ -81,7 +80,8 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches() } } } - packPatch = std::dynamic_pointer_cast(file); + packPatch = std::make_shared(file); + packPatch->setVanilla(true); } else { diff --git a/api/logic/minecraft/onesix/OneSixInstance.cpp b/api/logic/minecraft/onesix/OneSixInstance.cpp index b471ff3e..6e4a5bdc 100644 --- a/api/logic/minecraft/onesix/OneSixInstance.cpp +++ b/api/logic/minecraft/onesix/OneSixInstance.cpp @@ -523,7 +523,7 @@ QString OneSixInstance::currentVersionId() const void OneSixInstance::reloadProfile() { m_profile->reload(); - setVersionBroken(m_profile->getProblemSeverity() == ProblemSeverity::PROBLEM_ERROR); + setVersionBroken(m_profile->getProblemSeverity() == ProblemSeverity::Error); emit versionReloaded(); } diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index 3f33dd7f..a9cad832 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -15,6 +15,8 @@ #include #include +#include + OneSixProfileStrategy::OneSixProfileStrategy(OneSixInstance* instance) { m_instance = instance; @@ -81,103 +83,6 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles() } } -class MetaPatchProvider : public ProfilePatch -{ -public: /* con/des */ - MetaPatchProvider(std::shared_ptr data) - :m_version(data) - { - } -public: - QString getFilename() override - { - return QString(); - } - QString getID() override - { - return m_version->uid(); - } - QString getName() override - { - auto vfile = getFile(); - if(vfile) - { - return vfile->getName(); - } - return m_version->name(); - } - QDateTime getReleaseDateTime() override - { - return m_version->time(); - } - QString getVersion() override - { - return m_version->version(); - } - std::shared_ptr getVersionFile() override - { - return m_version->data(); - } - void setOrder(int) override - { - } - int getOrder() override - { - return 0; - } - bool isVersionChangeable() override - { - return true; - } - bool isRevertible() override - { - return false; - } - bool isRemovable() override - { - return true; - } - bool isCustom() override - { - return false; - } - bool isCustomizable() override - { - return true; - } - bool isMoveable() override - { - return true; - } - bool isEditable() override - { - return false; - } - bool isMinecraftVersion() override - { - return getID() == "net.minecraft"; - } - void applyTo(MinecraftProfile * profile) override - { - auto vfile = getFile(); - if(vfile) - { - vfile->applyTo(profile); - } - } -private: - VersionFilePtr getFile() - { - if(!m_version->isLoaded()) - { - m_version->load(); - } - return m_version->data(); - } -private: - std::shared_ptr m_version; -}; - void OneSixProfileStrategy::loadDefaultBuiltinPatches() { { @@ -191,14 +96,15 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() { file->version = m_instance->intendedVersionId(); } - file->setVanilla(false); - file->setRevertible(true); - minecraftPatch = std::dynamic_pointer_cast(file); + minecraftPatch = std::make_shared(file, mcJson); + minecraftPatch->setVanilla(false); + minecraftPatch->setRevertible(true); } else { auto mcversion = ENV.metadataIndex()->get("net.minecraft", m_instance->intendedVersionId()); - minecraftPatch = std::make_shared(mcversion); + minecraftPatch = std::make_shared(mcversion); + minecraftPatch->setVanilla(true); } if (!minecraftPatch) { @@ -214,14 +120,15 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() if(QFile::exists(lwjglJson)) { auto file = ProfileUtils::parseJsonFile(QFileInfo(lwjglJson), false); - file->setVanilla(false); - file->setRevertible(true); - lwjglPatch = std::dynamic_pointer_cast(file); + lwjglPatch = std::make_shared(file, lwjglJson); + lwjglPatch->setVanilla(false); + lwjglPatch->setRevertible(true); } else { auto lwjglversion = ENV.metadataIndex()->get("org.lwjgl", "2.9.1"); - lwjglPatch = std::make_shared(lwjglversion); + lwjglPatch = std::make_shared(lwjglversion); + lwjglPatch->setVanilla(true); } if (!lwjglPatch) { @@ -261,21 +168,17 @@ void OneSixProfileStrategy::loadUserPatches() // sanity check. prevent tampering with files. if (file->uid != id) { - file->addProblem(PROBLEM_WARNING, QObject::tr("load id %1 does not match internal id %2").arg(id, file->uid)); + file->addProblem(ProblemSeverity::Warning, QObject::tr("load id %1 does not match internal id %2").arg(id, file->uid)); seen_extra.insert(file->uid); } - file->setRemovable(true); - file->setMovable(true); - // HACK: ignore assets from other version files than Minecraft - // workaround for stupid assets issue caused by amazon: - // https://www.theregister.co.uk/2017/02/28/aws_is_awol_as_s3_goes_haywire/ - file->assets = QString(); - file->mojangAssetIndex.reset(); - // HACK - profile->appendPatch(file); + auto patchEntry = std::make_shared(file, filename); + patchEntry->setRemovable(true); + patchEntry->setMovable(true); + profile->appendPatch(patchEntry); } // now load the rest by internal preference. - QMultiMap files; + using FileEntry = std::tuple; + QMultiMap files; for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) { // parse the file @@ -292,16 +195,18 @@ void OneSixProfileStrategy::loadUserPatches() // do not load what we already loaded in the first pass if (userOrder.contains(file->uid)) continue; - file->setRemovable(true); - file->setMovable(true); - // HACK: ignore assets from other version files than Minecraft - // workaround for stupid assets issue caused by amazon: - // https://www.theregister.co.uk/2017/02/28/aws_is_awol_as_s3_goes_haywire/ - file->assets = QString(); - file->mojangAssetIndex.reset(); - // HACK - files.insert(file->getOrder(), file); + files.insert(file->order, std::make_tuple(file, info.filePath())); } + auto appendFilePatch = [&](FileEntry tuple) + { + VersionFilePtr file; + QString filename; + std::tie(file, filename) = tuple; + auto patchEntry = std::make_shared(file, filename); + patchEntry->setRemovable(true); + patchEntry->setMovable(true); + profile->appendPatch(patchEntry); + }; QSet seen; for (auto order : files.keys()) { @@ -311,7 +216,7 @@ void OneSixProfileStrategy::loadUserPatches() const auto &values = files.values(order); if(values.size() == 1) { - profile->appendPatch(values[0]); + appendFilePatch(values[0]); continue; } for(auto &file: values) @@ -320,10 +225,13 @@ void OneSixProfileStrategy::loadUserPatches() for(auto &file2: values) { if(file != file2) - list.append(file2->name); + { + list.append(std::get<0>(file2)->name); + } } - file->addProblem(PROBLEM_WARNING, QObject::tr("%1 has the same order as the following components:\n%2").arg(file->name, list.join(", "))); - profile->appendPatch(file); + auto vfileptr = std::get<0>(file); + vfileptr->addProblem(ProblemSeverity::Warning, QObject::tr("%1 has the same order as the following components:\n%2").arg(vfileptr->name, list.join(", "))); + appendFilePatch(file); } } } @@ -503,11 +411,9 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) f->jarMods.append(jarMod); f->name = target_name; f->uid = target_id; - f->setOrder(profile->getFreeOrderNumber()); + f->order = profile->getFreeOrderNumber(); QString patchFileName = FS::PathCombine(patchDir, target_id + ".json"); - f->filename = patchFileName; - f->setMovable(true); - f->setRemovable(true); + // f->filename = patchFileName; QFile file(patchFileName); if (!file.open(QFile::WriteOnly)) @@ -518,7 +424,11 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) } file.write(OneSixVersionFormat::versionFileToJson(f, true).toJson()); file.close(); - profile->appendPatch(f); + + auto patch = std::make_shared(f); + patch->setMovable(true); + patch->setRemovable(true); + profile->appendPatch(patch); } profile->saveCurrentOrder(); profile->reapplyPatches(); diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp index 944e68a4..266bd4bd 100644 --- a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp +++ b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp @@ -51,7 +51,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc { if (root.contains("order")) { - out->setOrder(requireInteger(root.value("order"))); + out->order = requireInteger(root.value("order")); } else { @@ -73,7 +73,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc out->version = root.value("version").toString(); out->dependsOnMinecraftVersion = root.value("mcVersion").toString(); - out->filename = filename; + // out->filename = filename; MojangVersionFormat::readVersionProperties(root, out.get()); @@ -128,7 +128,8 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc bool hasLibs = root.contains("libraries"); if (hasPlusLibs && hasLibs) { - out->addProblem(PROBLEM_WARNING, QObject::tr("Version file has both '+libraries' and 'libraries'. This is no longer supported.")); + out->addProblem(ProblemSeverity::Warning, + QObject::tr("Version file has both '+libraries' and 'libraries'. This is no longer supported.")); readLibs("libraries"); readLibs("+libraries"); } @@ -144,23 +145,23 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc /* removed features that shouldn't be used */ if (root.contains("tweakers")) { - out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element 'tweakers'")); + out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element 'tweakers'")); } if (root.contains("-libraries")) { - out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-libraries'")); + out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '-libraries'")); } if (root.contains("-tweakers")) { - out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-tweakers'")); + out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '-tweakers'")); } if (root.contains("-minecraftArguments")) { - out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-minecraftArguments'")); + out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '-minecraftArguments'")); } if (root.contains("+minecraftArguments")) { - out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '+minecraftArguments'")); + out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '+minecraftArguments'")); } return out; } @@ -170,7 +171,7 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch QJsonObject root; if (saveOrder) { - root.insert("order", patch->getOrder()); + root.insert("order", patch->order); } writeString(root, "name", patch->name); diff --git a/application/VersionProxyModel.cpp b/application/VersionProxyModel.cpp index 50b94d9e..00390b36 100644 --- a/application/VersionProxyModel.cpp +++ b/application/VersionProxyModel.cpp @@ -26,7 +26,7 @@ public: switch(role) { - case BaseVersionList::ParentGameVersionRole: + case BaseVersionList::ParentVersionRole: case BaseVersionList::VersionIdRole: { auto versionString = data.toString(); @@ -146,7 +146,7 @@ QVariant VersionProxyModel::data(const QModelIndex &index, int role) const case Name: return sourceModel()->data(parentIndex, BaseVersionList::VersionRole); case ParentVersion: - return sourceModel()->data(parentIndex, BaseVersionList::ParentGameVersionRole); + return sourceModel()->data(parentIndex, BaseVersionList::ParentVersionRole); case Branch: return sourceModel()->data(parentIndex, BaseVersionList::BranchRole); case Type: @@ -327,7 +327,7 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel *replacingRaw) m_columns.push_back(Name); } /* - if(roles.contains(BaseVersionList::ParentGameVersionRole)) + if(roles.contains(BaseVersionList::ParentVersionRole)) { m_columns.push_back(ParentVersion); } diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index 0608b2bf..5a0b2243 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -152,14 +152,14 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex & auto severity = patch->getProblemSeverity(); switch(severity) { - case PROBLEM_WARNING: + case ProblemSeverity::Warning: ui->frame->setModText(tr("%1 possibly has issues.").arg(patch->getName())); break; - case PROBLEM_ERROR: + case ProblemSeverity::Error: ui->frame->setModText(tr("%1 has issues!").arg(patch->getName())); break; default: - case PROBLEM_NONE: + case ProblemSeverity::None: ui->frame->clear(); return; } @@ -168,11 +168,11 @@ void VersionPage::packageCurrent(const QModelIndex ¤t, const QModelIndex & QString problemOut; for (auto &problem: problems) { - if(problem.getSeverity() == PROBLEM_ERROR) + if(problem.getSeverity() == ProblemSeverity::Error) { problemOut += tr("Error: "); } - else if(problem.getSeverity() == PROBLEM_WARNING) + else if(problem.getSeverity() == ProblemSeverity::Warning) { problemOut += tr("Warning: "); } @@ -381,7 +381,7 @@ void VersionPage::on_forgeBtn_clicked() return; } VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this); - vselect.setExactFilter(BaseVersionList::ParentGameVersionRole, m_inst->currentVersionId()); + vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_inst->currentVersionId()); vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_inst->currentVersionId()); vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!")); if (vselect.exec() && vselect.selectedVersion()) @@ -400,7 +400,7 @@ void VersionPage::on_liteloaderBtn_clicked() return; } VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this); - vselect.setExactFilter(BaseVersionList::ParentGameVersionRole, m_inst->currentVersionId()); + vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_inst->currentVersionId()); vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_inst->currentVersionId()); vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!")); if (vselect.exec() && vselect.selectedVersion()) @@ -457,7 +457,7 @@ void VersionPage::updateButtons(int row) ui->moveDownBtn->setEnabled(patch->isMoveable()); ui->moveUpBtn->setEnabled(patch->isMoveable()); ui->changeVersionBtn->setEnabled(patch->isVersionChangeable()); - ui->editBtn->setEnabled(patch->isEditable()); + ui->editBtn->setEnabled(patch->isCustom()); ui->customizeBtn->setEnabled(patch->isCustomizable()); ui->revertBtn->setEnabled(patch->isRevertible()); } -- cgit v1.2.3