refactor: bring back methods that need to be reimplemented
This commit is contained in:
parent
3aa809b8c0
commit
81c72c2038
@ -78,6 +78,101 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &containe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// ours
|
||||||
QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root)
|
QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,6 @@ void ModMinecraftJar::executeTask()
|
|||||||
emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath));
|
emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// create temporary modded jar, if needed
|
// create temporary modded jar, if needed
|
||||||
auto components = m_inst->getPackProfile();
|
auto components = m_inst->getPackProfile();
|
||||||
auto profile = components->getProfile();
|
auto profile = components->getProfile();
|
||||||
@ -54,13 +53,12 @@ void ModMinecraftJar::executeTask()
|
|||||||
mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath());
|
mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath());
|
||||||
auto sourceJarPath = jars[0];
|
auto sourceJarPath = jars[0];
|
||||||
if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods))
|
if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods))
|
||||||
{ */
|
{
|
||||||
// TODO: add back support for modded jar
|
|
||||||
emitFailed(tr("Failed to create the custom Minecraft jar file."));
|
emitFailed(tr("Failed to create the custom Minecraft jar file."));
|
||||||
return;
|
return;
|
||||||
/*}
|
}
|
||||||
}
|
}
|
||||||
emitSucceeded();*/
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModMinecraftJar::finalize()
|
void ModMinecraftJar::finalize()
|
||||||
|
@ -378,7 +378,6 @@ void SaveIcon(InstancePtr m_instance)
|
|||||||
|
|
||||||
bool ExportInstanceDialog::doExport()
|
bool ExportInstanceDialog::doExport()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
|
auto name = FS::RemoveInvalidFilenameChars(m_instance->name());
|
||||||
|
|
||||||
const QString output = QFileDialog::getSaveFileName(
|
const QString output = QFileDialog::getSaveFileName(
|
||||||
@ -404,12 +403,15 @@ bool ExportInstanceDialog::doExport()
|
|||||||
|
|
||||||
auto & blocked = proxyModel->blockedPaths();
|
auto & blocked = proxyModel->blockedPaths();
|
||||||
using std::placeholders::_1;
|
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)))
|
if (!JlCompress::compressDir(output, m_instance->instanceRoot(), name, std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1)))
|
||||||
{ */
|
{
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
||||||
return false;
|
return false;
|
||||||
/*}
|
}
|
||||||
return true;*/
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportInstanceDialog::done(int result)
|
void ExportInstanceDialog::done(int result)
|
||||||
|
Loading…
Reference in New Issue
Block a user