diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-07-10 00:06:05 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-07-10 00:06:05 +0200 |
commit | 5dd48e89f5a7facf8355641d0caf8deaec2a03ec (patch) | |
tree | b23f1d3bdb09afe8f642e07df30f5a68f2b42a5e /logic/minecraft/OneSixInstance.cpp | |
parent | 5133b0f34f1e6fc046787e7369b403a381a2f60c (diff) | |
download | MultiMC-5dd48e89f5a7facf8355641d0caf8deaec2a03ec.tar MultiMC-5dd48e89f5a7facf8355641d0caf8deaec2a03ec.tar.gz MultiMC-5dd48e89f5a7facf8355641d0caf8deaec2a03ec.tar.lz MultiMC-5dd48e89f5a7facf8355641d0caf8deaec2a03ec.tar.xz MultiMC-5dd48e89f5a7facf8355641d0caf8deaec2a03ec.zip |
GH-1034 do jar modding separate from update
Diffstat (limited to 'logic/minecraft/OneSixInstance.cpp')
-rw-r--r-- | logic/minecraft/OneSixInstance.cpp | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/logic/minecraft/OneSixInstance.cpp b/logic/minecraft/OneSixInstance.cpp index 63bc071f..4af56b54 100644 --- a/logic/minecraft/OneSixInstance.cpp +++ b/logic/minecraft/OneSixInstance.cpp @@ -56,7 +56,7 @@ QSet<QString> OneSixInstance::traits() return version->traits; } -std::shared_ptr<Task> OneSixInstance::doUpdate() +std::shared_ptr<Task> OneSixInstance::createUpdateTask() { return std::shared_ptr<Task>(new OneSixUpdate(this)); } @@ -123,7 +123,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) return parts; } -std::shared_ptr<BaseLauncher> OneSixInstance::prepareForLaunch(AuthSessionPtr session) +std::shared_ptr<BaseLauncher> OneSixInstance::createLaunchTask(AuthSessionPtr session) { QString launchScript; QIcon icon = ENV.icons()->getIcon(iconKey()); @@ -237,6 +237,64 @@ std::shared_ptr<BaseLauncher> OneSixInstance::prepareForLaunch(AuthSessionPtr se return process; } +std::shared_ptr<Task> OneSixInstance::createJarModdingTask() +{ + class JarModTask : public Task + { + public: + explicit JarModTask(std::shared_ptr<OneSixInstance> inst) : m_inst(inst), Task(nullptr) + { + } + virtual void executeTask() + { + std::shared_ptr<MinecraftProfile> version = m_inst->getMinecraftProfile(); + // nuke obsolete stripped jar(s) if needed + QString version_id = version->id; + QString strippedPath = version_id + "/" + version_id + "-stripped.jar"; + QFile strippedJar(strippedPath); + if(strippedJar.exists()) + { + strippedJar.remove(); + } + auto tempJarPath = QDir(m_inst->instanceRoot()).absoluteFilePath("temp.jar"); + QFile tempJar(tempJarPath); + if(tempJar.exists()) + { + tempJar.remove(); + } + auto finalJarPath = QDir(m_inst->instanceRoot()).absoluteFilePath("minecraft.jar"); + QFile finalJar(finalJarPath); + if(finalJar.exists()) + { + if(!finalJar.remove()) + { + emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath)); + return; + } + } + + // create temporary modded jar, if needed + auto jarMods = m_inst->getJarMods(); + if(jarMods.size()) + { + auto sourceJarPath = m_inst->versionsPath().absoluteFilePath(version->id + "/" + version->id + ".jar"); + QString localPath = version_id + "/" + version_id + ".jar"; + auto metacache = ENV.metacache(); + auto entry = metacache->resolveEntry("versions", localPath); + QString fullJarPath = entry->getFullPath(); + if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods)) + { + emitFailed(tr("Failed to create the custom Minecraft jar file.")); + return; + } + } + emitSucceeded(); + } + std::shared_ptr<OneSixInstance> m_inst; + }; + return std::make_shared<JarModTask>(std::dynamic_pointer_cast<OneSixInstance>(shared_from_this())); +} + void OneSixInstance::cleanupAfterRun() { QString target_dir = PathCombine(instanceRoot(), "natives/"); |