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: GH-952 flesh out {version,custom}.json upgrade step --- logic/minecraft/MinecraftProfile.cpp | 12 ++++++- logic/minecraft/OneSixProfileStrategy.cpp | 56 +++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 18 deletions(-) (limited to 'logic') diff --git a/logic/minecraft/MinecraftProfile.cpp b/logic/minecraft/MinecraftProfile.cpp index e87ece00..acde7dc7 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 12503a80..389b5f06 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)) + { + sourceFile = customJsonPath; + deleteFile = versionJsonPath; + } + else if(QFile::exists(versionJsonPath)) + { + sourceFile = versionJsonPath; + } + if(!sourceFile.isEmpty() && !QFile::exists(mcJson)) { if(!ensureFilePathExists(mcJson)) { - // WHAT DO??? - } - if(!QFile::rename(customJsonPath, mcJson)) - { - // WHAT DO??? + qWarning() << "Couldn't create patches folder for" << m_instance->name(); + return; } - if(QFile::exists(versionJsonPath)) + if(!deleteFile.isEmpty() && QFile::exists(deleteFile)) { - if(!QFile::remove(versionJsonPath)) + if(!QFile::remove(deleteFile)) { - // WHAT DO??? + qWarning() << "Couldn't remove" << deleteFile << "from" << m_instance->name(); + return; } } - } - else if(QFile::exists(versionJsonPath)) - { - if(!ensureFilePathExists(mcJson)) + 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)) { - // WHAT DO??? + newPatchFile.cancelWriting(); + qWarning() << "Couldn't open main patch for writing in" << m_instance->name(); + return; } - if(!QFile::rename(versionJsonPath, mcJson)) + newPatchFile.write(data); + if(!newPatchFile.commit()) { - // WHAT DO??? + 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 -- cgit v1.2.3