From 9491396292b740072fa90e6e81e81dbd1b159166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 10 Sep 2017 12:41:32 +0200 Subject: [PATCH] NOISSUE put back missing OneSix upgrade logic --- api/logic/minecraft/MinecraftProfile.cpp | 62 ++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp index c883e8e9..e6562230 100644 --- a/api/logic/minecraft/MinecraftProfile.cpp +++ b/api/logic/minecraft/MinecraftProfile.cpp @@ -669,6 +669,67 @@ int MinecraftProfile::getFreeOrderNumber() return largest + 1; } +void MinecraftProfile::upgradeDeprecatedFiles_internal() +{ + auto versionJsonPath = FS::PathCombine(m_instance->instanceRoot(), "version.json"); + auto customJsonPath = FS::PathCombine(m_instance->instanceRoot(), "custom.json"); + auto mcJson = FS::PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); + + QString sourceFile; + QString renameFile; + + // convert old crap. + if(QFile::exists(customJsonPath)) + { + sourceFile = customJsonPath; + renameFile = versionJsonPath; + } + else if(QFile::exists(versionJsonPath)) + { + sourceFile = versionJsonPath; + } + if(!sourceFile.isEmpty() && !QFile::exists(mcJson)) + { + if(!FS::ensureFilePathExists(mcJson)) + { + qWarning() << "Couldn't create patches folder for" << m_instance->name(); + return; + } + if(!renameFile.isEmpty() && QFile::exists(renameFile)) + { + if(!QFile::rename(renameFile, renameFile + ".old")) + { + qWarning() << "Couldn't rename" << renameFile << "to" << renameFile + ".old" << "in" << m_instance->name(); + return; + } + } + auto file = ProfileUtils::parseJsonFile(QFileInfo(sourceFile), false); + ProfileUtils::removeLwjglFromPatch(file); + file->uid = "net.minecraft"; + file->version = file->minecraftVersion; + file->name = "Minecraft"; + auto data = OneSixVersionFormat::versionFileToJson(file, false).toJson(); + QSaveFile newPatchFile(mcJson); + if(!newPatchFile.open(QIODevice::WriteOnly)) + { + newPatchFile.cancelWriting(); + qWarning() << "Couldn't open main patch for writing in" << m_instance->name(); + return; + } + newPatchFile.write(data); + if(!newPatchFile.commit()) + { + qWarning() << "Couldn't save main patch in" << m_instance->name(); + return; + } + if(!QFile::rename(sourceFile, sourceFile + ".old")) + { + qWarning() << "Couldn't rename" << sourceFile << "to" << sourceFile + ".old" << "in" << m_instance->name(); + return; + } + } +} + void MinecraftProfile::loadDefaultBuiltinPatches_internal() { auto addBuiltinPatch = [&](const QString &uid, const QString intendedVersion, int order) @@ -793,6 +854,7 @@ void MinecraftProfile::loadUserPatches_internal() void MinecraftProfile::load_internal() { clearPatches(); + upgradeDeprecatedFiles_internal(); loadDefaultBuiltinPatches_internal(); loadUserPatches_internal(); }