From 416e08f7417abd767e250e185a5be8bd1110dae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 15 May 2015 01:10:08 +0200 Subject: [PATCH] GH-952 flesh out {version,custom}.json upgrade step --- logic/minecraft/MinecraftProfile.cpp | 12 ++++- logic/minecraft/OneSixProfileStrategy.cpp | 62 +++++++++++++++-------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/logic/minecraft/MinecraftProfile.cpp b/logic/minecraft/MinecraftProfile.cpp index e87ece006..acde7dc7b 100644 --- a/logic/minecraft/MinecraftProfile.cpp +++ b/logic/minecraft/MinecraftProfile.cpp @@ -274,7 +274,17 @@ QVariant MinecraftProfile::data(const QModelIndex &index, int role) const case 0: return VersionPatches.at(row)->getPatchName(); case 1: - return VersionPatches.at(row)->getPatchVersion(); + { + auto patch = VersionPatches.at(row); + if(patch->isCustom()) + { + return QString("%1 (Custom)").arg(patch->getPatchVersion()); + } + else + { + return patch->getPatchVersion(); + } + } default: return QVariant(); } diff --git a/logic/minecraft/OneSixProfileStrategy.cpp b/logic/minecraft/OneSixProfileStrategy.cpp index 12503a80d..389b5f065 100644 --- a/logic/minecraft/OneSixProfileStrategy.cpp +++ b/logic/minecraft/OneSixProfileStrategy.cpp @@ -21,34 +21,57 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles() auto customJsonPath = PathCombine(m_instance->instanceRoot(), "custom.json"); auto mcJson = PathCombine(m_instance->instanceRoot(), "patches" , "net.minecraft.json"); + QString sourceFile; + QString deleteFile; + // convert old crap. if(QFile::exists(customJsonPath)) { - if(!ensureFilePathExists(mcJson)) - { - // WHAT DO??? - } - if(!QFile::rename(customJsonPath, mcJson)) - { - // WHAT DO??? - } - if(QFile::exists(versionJsonPath)) - { - if(!QFile::remove(versionJsonPath)) - { - // WHAT DO??? - } - } + sourceFile = customJsonPath; + deleteFile = versionJsonPath; } else if(QFile::exists(versionJsonPath)) + { + sourceFile = versionJsonPath; + } + if(!sourceFile.isEmpty() && !QFile::exists(mcJson)) { if(!ensureFilePathExists(mcJson)) { - // WHAT DO??? + qWarning() << "Couldn't create patches folder for" << m_instance->name(); + return; } - if(!QFile::rename(versionJsonPath, mcJson)) + if(!deleteFile.isEmpty() && QFile::exists(deleteFile)) { - // WHAT DO??? + if(!QFile::remove(deleteFile)) + { + qWarning() << "Couldn't remove" << deleteFile << "from" << m_instance->name(); + return; + } + } + auto file = ProfileUtils::parseJsonFile(QFileInfo(sourceFile), false); + ProfileUtils::removeLwjglFromPatch(file); + file->fileId = "net.minecraft"; + file->version = file->id; + file->name = "Minecraft"; + auto data = file->toJson(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::remove(sourceFile)) + { + qWarning() << "Couldn't remove" << sourceFile << "from" << m_instance->name(); + return; } } } @@ -62,12 +85,11 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() if(QFile::exists(mcJson)) { auto file = ProfileUtils::parseJsonFile(QFileInfo(mcJson), false); - file->fileId = "net.minecraft"; - file->name = "Minecraft"; if(file->version.isEmpty()) { file->version = m_instance->intendedVersionId(); } + file->setVanilla(false); minecraftPatch = std::dynamic_pointer_cast(file); } else