summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-12-29 00:37:14 +0100
committerPetr Mrázek <peterix@gmail.com>2017-12-29 00:37:14 +0100
commit719f3e863a2bdbaeaba37e837e0f6b75de124e6c (patch)
treebff005dd7e36b08d355bfec58742d44265fc0dd6 /api/logic/minecraft
parent50ca6cbb4daaa4acd300defc6b7ecc7ccb46cebf (diff)
downloadMultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar.gz
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar.lz
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.tar.xz
MultiMC-719f3e863a2bdbaeaba37e837e0f6b75de124e6c.zip
NOISSUE add versioning to component metadata format and use it
Diffstat (limited to 'api/logic/minecraft')
-rw-r--r--api/logic/minecraft/ComponentList.cpp34
-rw-r--r--api/logic/minecraft/OneSixVersionFormat.cpp25
-rw-r--r--api/logic/minecraft/VersionFile.h2
3 files changed, 30 insertions, 31 deletions
diff --git a/api/logic/minecraft/ComponentList.cpp b/api/logic/minecraft/ComponentList.cpp
index dbf6ee08..3fb04255 100644
--- a/api/logic/minecraft/ComponentList.cpp
+++ b/api/logic/minecraft/ComponentList.cpp
@@ -450,42 +450,30 @@ bool ComponentList::migratePreComponentConfig()
intendedVersion = emptyVersion;
}
auto file = ProfileUtils::parseJsonFile(QFileInfo(jsonFilePath), false);
- bool fileChanged = false;
- // if uid is missing or incorrect, fix it
- if(file->uid != uid)
- {
- file->uid = uid;
- fileChanged = true;
- }
+ // fix uid
+ file->uid = uid;
// if version is missing, add it from the outside.
if(file->version.isEmpty())
{
file->version = intendedVersion;
- fileChanged = true;
}
// if this is a dependency (LWJGL), mark it also as volatile
if(asDependency)
{
file->m_volatile = true;
- fileChanged = true;
}
// insert requirements if needed
if(!req.uid.isEmpty())
{
file->requires.insert(req);
- fileChanged = true;
}
// insert conflicts if needed
if(!conflict.uid.isEmpty())
{
file->conflicts.insert(conflict);
- fileChanged = true;
- }
- if(fileChanged)
- {
- // FIXME: @QUALITY do not ignore return value
- ProfileUtils::saveJsonFile(OneSixVersionFormat::versionFileToJson(file), jsonFilePath);
}
+ // FIXME: @QUALITY do not ignore return value
+ ProfileUtils::saveJsonFile(OneSixVersionFormat::versionFileToJson(file), jsonFilePath);
component = new Component(this, uid, file);
component->m_version = intendedVersion;
}
@@ -538,17 +526,9 @@ bool ComponentList::migratePreComponentConfig()
QFile::remove(info.absoluteFilePath());
continue;
}
- bool fileChanged = false;
- if(file->uid != uid)
- {
- file->uid = uid;
- fileChanged = true;
- }
- if(fileChanged)
- {
- // FIXME: @QUALITY do not ignore return value
- ProfileUtils::saveJsonFile(OneSixVersionFormat::versionFileToJson(file), info.absoluteFilePath());
- }
+ file->uid = uid;
+ // FIXME: @QUALITY do not ignore return value
+ ProfileUtils::saveJsonFile(OneSixVersionFormat::versionFileToJson(file), info.absoluteFilePath());
auto component = new Component(this, file->uid, file);
auto version = d->getOldConfigVersion(file->uid);
diff --git a/api/logic/minecraft/OneSixVersionFormat.cpp b/api/logic/minecraft/OneSixVersionFormat.cpp
index d91eae58..f7ab25b3 100644
--- a/api/logic/minecraft/OneSixVersionFormat.cpp
+++ b/api/logic/minecraft/OneSixVersionFormat.cpp
@@ -52,6 +52,15 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
QJsonObject root = doc.object();
+ Meta::MetadataVersion formatVersion = Meta::parseFormatVersion(root, false);
+ switch(formatVersion)
+ {
+ case Meta::MetadataVersion::InitialRelease:
+ break;
+ case Meta::MetadataVersion::Invalid:
+ throw JSONValidationError(filename + " does not contain a recognizable version of the metadata format.");
+ }
+
if (requireOrder)
{
if (root.contains("order"))
@@ -77,8 +86,6 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
}
out->version = root.value("version").toString();
- out->dependsOnMinecraftVersion = root.value("mcVersion").toString();
- // out->filename = filename;
MojangVersionFormat::readVersionProperties(root, out.get());
@@ -196,6 +203,17 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
{
Meta::parseRequires(root, &out->requires);
}
+ QString dependsOnMinecraftVersion = root.value("mcVersion").toString();
+ if(!dependsOnMinecraftVersion.isEmpty())
+ {
+ Meta::Require mcReq;
+ mcReq.uid = "net.minecraft";
+ mcReq.equalsVersion = dependsOnMinecraftVersion;
+ if (out->requires.count(mcReq) == 0)
+ {
+ out->requires.insert(mcReq);
+ }
+ }
if (root.contains("conflicts"))
{
Meta::parseRequires(root, &out->conflicts);
@@ -237,7 +255,8 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
writeString(root, "uid", patch->uid);
writeString(root, "version", patch->version);
- writeString(root, "mcVersion", patch->dependsOnMinecraftVersion);
+
+ Meta::serializeFormatVersion(root, Meta::MetadataVersion::InitialRelease);
MojangVersionFormat::writeVersionProperties(patch.get(), root);
diff --git a/api/logic/minecraft/VersionFile.h b/api/logic/minecraft/VersionFile.h
index c032f7ea..5aea7a7a 100644
--- a/api/logic/minecraft/VersionFile.h
+++ b/api/logic/minecraft/VersionFile.h
@@ -18,7 +18,7 @@ class LaunchProfile;
struct MojangDownloadInfo;
struct MojangAssetIndexInfo;
-typedef std::shared_ptr<VersionFile> VersionFilePtr;
+using VersionFilePtr = std::shared_ptr<VersionFile>;
class VersionFile : public ProblemContainer
{
friend class MojangVersionFormat;