diff options
Diffstat (limited to 'logic/minecraft/OneSixProfileStrategy.cpp')
-rw-r--r-- | logic/minecraft/OneSixProfileStrategy.cpp | 56 |
1 files changed, 39 insertions, 17 deletions
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<ProfilePatch>(file); } else |