summaryrefslogtreecommitdiffstats
path: root/logic/minecraft
diff options
context:
space:
mode:
Diffstat (limited to 'logic/minecraft')
-rw-r--r--logic/minecraft/LegacyInstance.cpp86
-rw-r--r--logic/minecraft/LegacyInstance.h7
-rw-r--r--logic/minecraft/LegacyUpdate.cpp74
-rw-r--r--logic/minecraft/LegacyUpdate.h2
-rw-r--r--logic/minecraft/OneSixInstance.cpp62
-rw-r--r--logic/minecraft/OneSixInstance.h5
-rw-r--r--logic/minecraft/OneSixUpdate.cpp40
7 files changed, 154 insertions, 122 deletions
diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp
index 3fe51a4a..8431c35b 100644
--- a/logic/minecraft/LegacyInstance.cpp
+++ b/logic/minecraft/LegacyInstance.cpp
@@ -26,6 +26,7 @@
#include "icons/IconList.h"
#include "BaseLauncher.h"
#include "minecraft/ModList.h"
+#include <MMCZip.h>
LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: MinecraftInstance(globalSettings, settings, rootDir)
@@ -87,7 +88,7 @@ bool LegacyInstance::shouldUseCustomBaseJar() const
}
-std::shared_ptr<Task> LegacyInstance::doUpdate()
+std::shared_ptr<Task> LegacyInstance::createUpdateTask()
{
// make sure the jar mods list is initialized by asking for it.
auto list = jarModList();
@@ -95,7 +96,7 @@ std::shared_ptr<Task> LegacyInstance::doUpdate()
return std::shared_ptr<Task>(new LegacyUpdate(this, this));
}
-std::shared_ptr<BaseLauncher> LegacyInstance::prepareForLaunch(AuthSessionPtr account)
+std::shared_ptr<BaseLauncher> LegacyInstance::createLaunchTask(AuthSessionPtr account)
{
QString launchScript;
QIcon icon = ENV.icons()->getIcon(iconKey());
@@ -129,6 +130,87 @@ std::shared_ptr<BaseLauncher> LegacyInstance::prepareForLaunch(AuthSessionPtr ac
return process;
}
+std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
+{
+ class JarModTask : public Task
+ {
+ public:
+ explicit JarModTask(std::shared_ptr<LegacyInstance> inst) : m_inst(inst), Task(nullptr)
+ {
+ }
+ virtual void executeTask()
+ {
+ if (!m_inst->shouldRebuild())
+ {
+ emitSucceeded();
+ return;
+ }
+
+ // Get the mod list
+ auto modList = m_inst->getJarMods();
+
+ QFileInfo runnableJar(m_inst->runnableJar());
+ QFileInfo baseJar(m_inst->baseJar());
+ bool base_is_custom = m_inst->shouldUseCustomBaseJar();
+
+ // Nothing to do if there are no jar mods to install, no backup and just the mc jar
+ if (base_is_custom)
+ {
+ // yes, this can happen if the instance only has the runnable jar and not the base jar
+ // it *could* be assumed that such an instance is vanilla, but that wouldn't be safe
+ // because that's not something mmc4 guarantees
+ if (runnableJar.isFile() && !baseJar.exists() && modList.empty())
+ {
+ m_inst->setShouldRebuild(false);
+ emitSucceeded();
+ return;
+ }
+
+ setStatus(tr("Installing mods: Backing up minecraft.jar ..."));
+ if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath()))
+ {
+ emitFailed("It seems both the active and base jar are gone. A fresh base jar will "
+ "be used on next run.");
+ m_inst->setShouldRebuild(true);
+ m_inst->setShouldUpdate(true);
+ m_inst->setShouldUseCustomBaseJar(false);
+ return;
+ }
+ }
+
+ if (!baseJar.exists())
+ {
+ emitFailed("The base jar " + baseJar.filePath() + " does not exist");
+ return;
+ }
+
+ if (runnableJar.exists() && !QFile::remove(runnableJar.filePath()))
+ {
+ emitFailed("Failed to delete old minecraft.jar");
+ return;
+ }
+
+ setStatus(tr("Installing mods: Opening minecraft.jar ..."));
+
+ QString outputJarPath = runnableJar.filePath();
+ QString inputJarPath = baseJar.filePath();
+
+ if(!MMCZip::createModdedJar(inputJarPath, outputJarPath, modList))
+ {
+ emitFailed(tr("Failed to create the custom Minecraft jar file."));
+ return;
+ }
+ m_inst->setShouldRebuild(false);
+ // inst->UpdateVersion(true);
+ emitSucceeded();
+ return;
+
+ }
+ std::shared_ptr<LegacyInstance> m_inst;
+ };
+ return std::make_shared<JarModTask>(std::dynamic_pointer_cast<LegacyInstance>(shared_from_this()));
+}
+
void LegacyInstance::cleanupAfterRun()
{
// FIXME: delete the launcher and icons and whatnot.
diff --git a/logic/minecraft/LegacyInstance.h b/logic/minecraft/LegacyInstance.h
index a8363e58..51871876 100644
--- a/logic/minecraft/LegacyInstance.h
+++ b/logic/minecraft/LegacyInstance.h
@@ -109,9 +109,12 @@ public:
virtual bool shouldUpdate() const override;
virtual void setShouldUpdate(bool val) override;
- virtual std::shared_ptr<Task> doUpdate() override;
+ virtual std::shared_ptr<Task> createUpdateTask() override;
+
+ virtual std::shared_ptr<BaseLauncher> createLaunchTask(AuthSessionPtr account) override;
+
+ virtual std::shared_ptr<Task> createJarModdingTask() override;
- virtual std::shared_ptr<BaseLauncher> prepareForLaunch(AuthSessionPtr account) override;
virtual void cleanupAfterRun() override;
virtual QString getStatusbarDescription() override;
diff --git a/logic/minecraft/LegacyUpdate.cpp b/logic/minecraft/LegacyUpdate.cpp
index 78f2f5b7..7ea20ad8 100644
--- a/logic/minecraft/LegacyUpdate.cpp
+++ b/logic/minecraft/LegacyUpdate.cpp
@@ -349,7 +349,7 @@ void LegacyUpdate::jarStart()
LegacyInstance *inst = (LegacyInstance *)m_inst;
if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar())
{
- ModTheJar();
+ emitSucceeded();
return;
}
@@ -384,7 +384,7 @@ void LegacyUpdate::jarStart()
void LegacyUpdate::jarFinished()
{
// process the jar
- ModTheJar();
+ emitSucceeded();
}
void LegacyUpdate::jarFailed(QString reason)
@@ -392,73 +392,3 @@ void LegacyUpdate::jarFailed(QString reason)
// bad, bad
emitFailed(tr("Failed to download the minecraft jar: %1.").arg(reason));
}
-
-void LegacyUpdate::ModTheJar()
-{
- LegacyInstance *inst = (LegacyInstance *)m_inst;
-
- if (!inst->shouldRebuild())
- {
- emitSucceeded();
- return;
- }
-
- // Get the mod list
- auto modList = inst->getJarMods();
-
- QFileInfo runnableJar(inst->runnableJar());
- QFileInfo baseJar(inst->baseJar());
- bool base_is_custom = inst->shouldUseCustomBaseJar();
-
- // Nothing to do if there are no jar mods to install, no backup and just the mc jar
- if (base_is_custom)
- {
- // yes, this can happen if the instance only has the runnable jar and not the base jar
- // it *could* be assumed that such an instance is vanilla, but that wouldn't be safe
- // because that's not something mmc4 guarantees
- if (runnableJar.isFile() && !baseJar.exists() && modList.empty())
- {
- inst->setShouldRebuild(false);
- emitSucceeded();
- return;
- }
-
- setStatus(tr("Installing mods: Backing up minecraft.jar ..."));
- if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath()))
- {
- emitFailed("It seems both the active and base jar are gone. A fresh base jar will "
- "be used on next run.");
- inst->setShouldRebuild(true);
- inst->setShouldUpdate(true);
- inst->setShouldUseCustomBaseJar(false);
- return;
- }
- }
-
- if (!baseJar.exists())
- {
- emitFailed("The base jar " + baseJar.filePath() + " does not exist");
- return;
- }
-
- if (runnableJar.exists() && !QFile::remove(runnableJar.filePath()))
- {
- emitFailed("Failed to delete old minecraft.jar");
- return;
- }
-
- setStatus(tr("Installing mods: Opening minecraft.jar ..."));
-
- QString outputJarPath = runnableJar.filePath();
- QString inputJarPath = baseJar.filePath();
-
- if(!MMCZip::createModdedJar(inputJarPath, outputJarPath, modList))
- {
- emitFailed(tr("Failed to create the custom Minecraft jar file."));
- return;
- }
- inst->setShouldRebuild(false);
- // inst->UpdateVersion(true);
- emitSucceeded();
- return;
-}
diff --git a/logic/minecraft/LegacyUpdate.h b/logic/minecraft/LegacyUpdate.h
index fc389ae1..c52bf934 100644
--- a/logic/minecraft/LegacyUpdate.h
+++ b/logic/minecraft/LegacyUpdate.h
@@ -51,8 +51,6 @@ slots:
void extractLwjgl();
- void ModTheJar();
-
private:
std::shared_ptr<QNetworkReply> m_reply;
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/");
diff --git a/logic/minecraft/OneSixInstance.h b/logic/minecraft/OneSixInstance.h
index 3825ba6a..46545462 100644
--- a/logic/minecraft/OneSixInstance.h
+++ b/logic/minecraft/OneSixInstance.h
@@ -48,8 +48,9 @@ public:
QString libDir() const;
virtual QString instanceConfigFolder() const override;
- virtual std::shared_ptr<Task> doUpdate() override;
- virtual std::shared_ptr<BaseLauncher> prepareForLaunch(AuthSessionPtr account) override;
+ virtual std::shared_ptr<Task> createUpdateTask() override;
+ virtual std::shared_ptr<BaseLauncher> createLaunchTask(AuthSessionPtr account) override;
+ virtual std::shared_ptr<Task> createJarModdingTask() override;
virtual void cleanupAfterRun() override;
diff --git a/logic/minecraft/OneSixUpdate.cpp b/logic/minecraft/OneSixUpdate.cpp
index 8463ead6..34bd7de9 100644
--- a/logic/minecraft/OneSixUpdate.cpp
+++ b/logic/minecraft/OneSixUpdate.cpp
@@ -296,46 +296,6 @@ void OneSixUpdate::jarlibFinished()
OneSixInstance *inst = (OneSixInstance *)m_inst;
std::shared_ptr<MinecraftProfile> version = 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 = 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;
- }
- }
if (version->traits.contains("legacyFML"))
{
fmllibsStart();