| 41 | #include "minecraft/PackProfile.h" |
| 42 | |
| 43 | void ModMinecraftJar::executeTask() |
| 44 | { |
| 45 | auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance()); |
| 46 | |
| 47 | if(!m_inst->getJarMods().size()) |
| 48 | { |
| 49 | emitSucceeded(); |
| 50 | return; |
| 51 | } |
| 52 | // nuke obsolete stripped jar(s) if needed |
| 53 | if(!FS::ensureFolderPathExists(m_inst->binRoot())) |
| 54 | { |
| 55 | emitFailed(tr("Couldn't create the bin folder for Minecraft.jar")); |
| 56 | } |
| 57 | |
| 58 | auto finalJarPath = QDir(m_inst->binRoot()).absoluteFilePath("minecraft.jar"); |
| 59 | if(!removeJar()) |
| 60 | { |
| 61 | emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath)); |
| 62 | } |
| 63 | |
| 64 | // create temporary modded jar, if needed |
| 65 | auto components = m_inst->getPackProfile(); |
| 66 | auto profile = components->getProfile(); |
| 67 | auto jarMods = m_inst->getJarMods(); |
| 68 | if(jarMods.size()) |
| 69 | { |
| 70 | auto mainJar = profile->getMainJar(); |
| 71 | QStringList jars, temp1, temp2, temp3, temp4; |
| 72 | mainJar->getApplicableFiles(m_inst->runtimeContext(), jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath()); |
| 73 | auto sourceJarPath = jars[0]; |
| 74 | if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods)) |
| 75 | { |
| 76 | emitFailed(tr("Failed to create the custom Minecraft jar file.")); |
| 77 | return; |
| 78 | } |
| 79 | } |
| 80 | emitSucceeded(); |
| 81 | } |
| 82 | |
| 83 | void ModMinecraftJar::finalize() |
| 84 | { |
nothing calls this directly
no test coverage detected