From 85ae710d407eb31527183d5f8bec0399eb209f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 11 Nov 2017 01:38:31 +0100 Subject: GH-2026 implement changes necessary to support 1.13 snapshots --- api/logic/minecraft/legacy/LegacyUpgradeTask.cpp | 101 ++++++++++++----------- 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'api/logic/minecraft/legacy/LegacyUpgradeTask.cpp') diff --git a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp index fab48005..6cda3e4d 100644 --- a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp +++ b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp @@ -67,69 +67,70 @@ void LegacyUpgradeTask::copyFinished() auto instanceSettings = std::make_shared(FS::PathCombine(m_stagingPath, "instance.cfg")); instanceSettings->registerSetting("InstanceType", "Legacy"); instanceSettings->set("InstanceType", "OneSix"); - std::shared_ptr inst(new MinecraftInstance(m_globalSettings, instanceSettings, m_stagingPath)); - inst->setName(m_newName); - inst->init(); - - QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId()); - if(preferredVersionNumber.isNull()) + // NOTE: this scope ensures the instance is fully saved before we emitSucceeded { - // try to decide version based on the jar(s?) - preferredVersionNumber = classparser::GetMinecraftJarVersion(legacyInst->baseJar()); + MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath); + inst.setName(m_newName); + inst.init(); + + QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId()); if(preferredVersionNumber.isNull()) { - preferredVersionNumber = classparser::GetMinecraftJarVersion(legacyInst->runnableJar()); + // try to decide version based on the jar(s?) + preferredVersionNumber = classparser::GetMinecraftJarVersion(legacyInst->baseJar()); if(preferredVersionNumber.isNull()) { - emitFailed(tr("Could not decide Minecraft version.")); - return; + preferredVersionNumber = classparser::GetMinecraftJarVersion(legacyInst->runnableJar()); + if(preferredVersionNumber.isNull()) + { + emitFailed(tr("Could not decide Minecraft version.")); + return; + } } } - } - inst->setComponentVersion("net.minecraft", preferredVersionNumber); + auto components = inst.getComponentList(); + components->buildingFromScratch(); + components->setComponentVersion("net.minecraft", preferredVersionNumber, true); - // BUG: reloadProfile should not be necessary, but setComponentVersion voids the profile created by init()! - inst->reloadProfile(); - auto profile = inst->getComponentList(); - - if(legacyInst->shouldUseCustomBaseJar()) - { - QString jarPath = legacyInst->customBaseJar(); - qDebug() << "Base jar is custom! : " << jarPath; - // FIXME: handle case when the jar is unreadable? - // TODO: check the hash, if it's the same as the upstream jar, do not do this - profile->installCustomJar(jarPath); - } + if(legacyInst->shouldUseCustomBaseJar()) + { + QString jarPath = legacyInst->customBaseJar(); + qDebug() << "Base jar is custom! : " << jarPath; + // FIXME: handle case when the jar is unreadable? + // TODO: check the hash, if it's the same as the upstream jar, do not do this + components->installCustomJar(jarPath); + } - auto jarMods = legacyInst->getJarMods(); - for(auto & jarMod: jarMods) - { - QString modPath = jarMod.filename().absoluteFilePath(); - qDebug() << "jarMod: " << modPath; - profile->installJarMods({modPath}); - } + auto jarMods = legacyInst->getJarMods(); + for(auto & jarMod: jarMods) + { + QString modPath = jarMod.filename().absoluteFilePath(); + qDebug() << "jarMod: " << modPath; + components->installJarMods({modPath}); + } - // remove all the extra garbage we no longer need - auto removeAll = [&](const QString &root, const QStringList &things) - { - for(auto &thing : things) + // remove all the extra garbage we no longer need + auto removeAll = [&](const QString &root, const QStringList &things) { - auto removePath = FS::PathCombine(root, thing); - QFileInfo stat(removePath); - if(stat.isDir()) + for(auto &thing : things) { - FS::deletePath(removePath); + auto removePath = FS::PathCombine(root, thing); + QFileInfo stat(removePath); + if(stat.isDir()) + { + FS::deletePath(removePath); + } + else + { + QFile::remove(removePath); + } } - else - { - QFile::remove(removePath); - } - } - }; - QStringList rootRemovables = {"modlist", "version", "instMods"}; - QStringList mcRemovables = {"bin", "MultiMCLauncher.jar", "icon.png"}; - removeAll(inst->instanceRoot(), rootRemovables); - removeAll(inst->minecraftRoot(), mcRemovables); + }; + QStringList rootRemovables = {"modlist", "version", "instMods"}; + QStringList mcRemovables = {"bin", "MultiMCLauncher.jar", "icon.png"}; + removeAll(inst.instanceRoot(), rootRemovables); + removeAll(inst.minecraftRoot(), mcRemovables); + } emitSucceeded(); } -- cgit v1.2.3