aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-01-24 23:02:06 +0100
committerSefa Eyeoglu <contact@scrumplex.net>2022-01-31 21:40:59 +0100
commit81c72c2038f35e744e038923105d91add5a0732c (patch)
tree23949bc53ca98cda48567bec9f3df28d54a03651 /launcher
parent3aa809b8c0de48ca241ec567acda31ed1a728540 (diff)
downloadPrismLauncher-81c72c2038f35e744e038923105d91add5a0732c.tar.gz
PrismLauncher-81c72c2038f35e744e038923105d91add5a0732c.tar.bz2
PrismLauncher-81c72c2038f35e744e038923105d91add5a0732c.zip
refactor: bring back methods that need to be reimplemented
Diffstat (limited to 'launcher')
-rw-r--r--launcher/MMCZip.cpp95
-rw-r--r--launcher/minecraft/launch/ModMinecraftJar.cpp8
-rw-r--r--launcher/ui/dialogs/ExportInstanceDialog.cpp10
3 files changed, 104 insertions, 9 deletions
diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp
index 74c9b388..36562b06 100644
--- a/launcher/MMCZip.cpp
+++ b/launcher/MMCZip.cpp
@@ -79,6 +79,101 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &containe
}
// ours
+bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods)
+{
+ QuaZip zipOut(targetJarPath);
+ if (!zipOut.open(QuaZip::mdCreate))
+ {
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to open the minecraft.jar for modding";
+ return false;
+ }
+ // Files already added to the jar.
+ // These files will be skipped.
+ QSet<QString> addedFiles;
+
+ // Modify the jar
+ QListIterator<Mod> i(mods);
+ i.toBack();
+ while (i.hasPrevious())
+ {
+ const Mod &mod = i.previous();
+ // do not merge disabled mods.
+ if (!mod.enabled())
+ continue;
+ if (mod.type() == Mod::MOD_ZIPFILE)
+ {
+ if (!mergeZipFiles(&zipOut, mod.filename(), addedFiles))
+ {
+ zipOut.close();
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
+ return false;
+ }
+ }
+ else if (mod.type() == Mod::MOD_SINGLEFILE)
+ {
+ // FIXME: buggy - does not work with addedFiles
+ auto filename = mod.filename();
+ if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName()))
+ {
+ zipOut.close();
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
+ return false;
+ }
+ addedFiles.insert(filename.fileName());
+ }
+ else if (mod.type() == Mod::MOD_FOLDER)
+ {
+ // FIXME: buggy - does not work with addedFiles
+ auto filename = mod.filename();
+ QString what_to_zip = filename.absoluteFilePath();
+ QDir dir(what_to_zip);
+ dir.cdUp();
+ QString parent_dir = dir.absolutePath();
+ return false;
+ // TODO: implement custom compressSubDir:
+ if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles))
+ {
+ zipOut.close();
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar.";
+ return false;
+ }
+ qDebug() << "Adding folder " << filename.fileName() << " from "
+ << filename.absoluteFilePath();
+ }
+ else
+ {
+ // Make sure we do not continue launching when something is missing or undefined...
+ zipOut.close();
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to add unknown mod type" << mod.filename().fileName() << "to the jar.";
+ return false;
+ }
+ }
+
+ if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key){return !key.contains("META-INF");}))
+ {
+ zipOut.close();
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to insert minecraft.jar contents.";
+ return false;
+ }
+
+ // Recompress the jar
+ zipOut.close();
+ if (zipOut.getZipError() != 0)
+ {
+ QFile::remove(targetJarPath);
+ qCritical() << "Failed to finalize minecraft.jar!";
+ return false;
+ }
+ return true;
+}
+
+// ours
QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root)
{
QuaZipDir rootDir(zip, root);
diff --git a/launcher/minecraft/launch/ModMinecraftJar.cpp b/launcher/minecraft/launch/ModMinecraftJar.cpp
index c8796f01..93de9d59 100644
--- a/launcher/minecraft/launch/ModMinecraftJar.cpp
+++ b/launcher/minecraft/launch/ModMinecraftJar.cpp
@@ -42,7 +42,6 @@ void ModMinecraftJar::executeTask()
emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath));
}
- /*
// create temporary modded jar, if needed
auto components = m_inst->getPackProfile();
auto profile = components->getProfile();
@@ -54,13 +53,12 @@ void ModMinecraftJar::executeTask()
mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath());
auto sourceJarPath = jars[0];
if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods))
- { */
- // TODO: add back support for modded jar
+ {
emitFailed(tr("Failed to create the custom Minecraft jar file."));
return;
- /*}
+ }
}
- emitSucceeded();*/
+ emitSucceeded();
}
void ModMinecraftJar::finalize()
diff --git a/launcher/ui/dialogs/ExportInstanceDialog.cpp b/launcher/ui/dialogs/ExportInstanceDialog.cpp
index 59ae0a76..fb9c6542 100644
--- a/launcher/ui/dialogs/ExportInstanceDialog.cpp
+++ b/launcher/ui/dialogs/ExportInstanceDialog.cpp
@@ -378,7 +378,6 @@ void SaveIcon(InstancePtr m_instance)
bool ExportInstanceDialog::doExport()
{
- /*
auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
const QString output = QFileDialog::getSaveFileName(
@@ -404,12 +403,15 @@ bool ExportInstanceDialog::doExport()
auto & blocked = proxyModel->blockedPaths();
using std::placeholders::_1;
+ QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
+ return false;
+ // TODO Reimplement custom compressDir:
if (!JlCompress::compressDir(output, m_instance->instanceRoot(), name, std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1)))
- { */
+ {
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
return false;
- /*}
- return true;*/
+ }
+ return true;
}
void ExportInstanceDialog::done(int result)