From b9e06b5da0bdc3644bac37bfcc45e32d0bcc37a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 31 May 2015 19:24:39 +0200 Subject: [PATCH] GH-1021 make builtin versions not customizable They use attributes not defined in the OneSix format. --- logic/minecraft/MinecraftVersion.cpp | 36 ++++++++++++++++++++++++---- logic/minecraft/MinecraftVersion.h | 5 +--- logic/minecraft/RawLibrary.cpp | 1 + 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/logic/minecraft/MinecraftVersion.cpp b/logic/minecraft/MinecraftVersion.cpp index 982a5ac3..1451c39d 100644 --- a/logic/minecraft/MinecraftVersion.cpp +++ b/logic/minecraft/MinecraftVersion.cpp @@ -53,16 +53,28 @@ bool MinecraftVersion::isMinecraftVersion() return true; } -// 1. assume the local file is good. load, check. If it's good, apply. -// 2. if discrepancies are found, fall out and fail (impossible to apply incomplete version). void MinecraftVersion::applyFileTo(MinecraftProfile *version) { - getVersionFile()->applyTo(version); + if(m_versionSource == Local && getVersionFile()) + { + getVersionFile()->applyTo(version); + } + else + { + throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name)); + } } QJsonDocument MinecraftVersion::toJson(bool saveOrder) { - return getVersionFile()->toJson(saveOrder); + if(m_versionSource == Local && getVersionFile()) + { + return getVersionFile()->toJson(saveOrder); + } + else + { + throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(m_name)); + } } VersionFilePtr MinecraftVersion::getVersionFile() @@ -76,6 +88,22 @@ VersionFilePtr MinecraftVersion::getVersionFile() return loadedVersionFile; } +bool MinecraftVersion::isCustomizable() +{ + switch(m_versionSource) + { + case Local: + case Remote: + // locally cached file, or a remote file that we can acquire can be customized + return true; + case 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; +} void MinecraftVersion::applyTo(MinecraftProfile *version) { diff --git a/logic/minecraft/MinecraftVersion.h b/logic/minecraft/MinecraftVersion.h index af15c1a4..3795cb41 100644 --- a/logic/minecraft/MinecraftVersion.h +++ b/logic/minecraft/MinecraftVersion.h @@ -52,10 +52,7 @@ public: /* methods */ { return false; } - virtual bool isCustomizable() override - { - return true; - } + virtual bool isCustomizable() override; virtual bool isRemovable() override { return false; diff --git a/logic/minecraft/RawLibrary.cpp b/logic/minecraft/RawLibrary.cpp index bae6c66a..c4cd97a1 100644 --- a/logic/minecraft/RawLibrary.cpp +++ b/logic/minecraft/RawLibrary.cpp @@ -224,6 +224,7 @@ bool RawLibrary::filesExist(const QDir &base) const } return true; } + QString RawLibrary::url() const { if (!m_absolute_url.isEmpty())