2013-08-07 05:08:18 +05:30
|
|
|
#include "LegacyUpdate.h"
|
|
|
|
#include "lists/LwjglVersionList.h"
|
2013-08-12 04:09:19 +05:30
|
|
|
#include "lists/MinecraftVersionList.h"
|
2013-08-07 05:08:18 +05:30
|
|
|
#include "BaseInstance.h"
|
|
|
|
#include "LegacyInstance.h"
|
|
|
|
#include "net/NetWorker.h"
|
2013-08-24 06:39:46 +05:30
|
|
|
#include "ModList.h"
|
2013-08-07 05:08:18 +05:30
|
|
|
#include <pathutils.h>
|
|
|
|
#include <quazip.h>
|
|
|
|
#include <quazipfile.h>
|
2013-08-24 06:39:46 +05:30
|
|
|
#include <JlCompress.h>
|
2013-08-07 05:08:18 +05:30
|
|
|
|
|
|
|
|
|
|
|
LegacyUpdate::LegacyUpdate ( BaseInstance* inst, QObject* parent ) : BaseUpdate ( inst, parent ) {}
|
|
|
|
|
|
|
|
void LegacyUpdate::executeTask()
|
|
|
|
{
|
|
|
|
lwjglStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::lwjglStart()
|
|
|
|
{
|
|
|
|
LegacyInstance * inst = (LegacyInstance *) m_inst;
|
2013-08-09 03:56:35 +05:30
|
|
|
|
|
|
|
lwjglVersion = inst->lwjglVersion();
|
|
|
|
lwjglTargetPath = PathCombine("lwjgl", lwjglVersion );
|
2013-08-24 06:39:46 +05:30
|
|
|
lwjglNativesPath = PathCombine( lwjglTargetPath, "natives");
|
2013-08-09 03:56:35 +05:30
|
|
|
|
|
|
|
// if the 'done' file exists, we don't have to download this again
|
|
|
|
QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
|
|
|
|
if(doneFile.exists())
|
|
|
|
{
|
2013-08-12 04:09:19 +05:30
|
|
|
jarStart();
|
2013-08-09 03:56:35 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
auto &list = LWJGLVersionList::get();
|
|
|
|
if(!list.isLoaded())
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Too soon! Let the LWJGL list load :)");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-08-09 03:56:35 +05:30
|
|
|
|
2013-08-12 04:09:19 +05:30
|
|
|
setStatus("Downloading new LWJGL.");
|
2013-08-09 03:56:35 +05:30
|
|
|
auto version = list.getVersion(lwjglVersion);
|
2013-08-07 05:08:18 +05:30
|
|
|
if(!version)
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Game update failed: the selected LWJGL version is invalid.");
|
|
|
|
return;
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
2013-08-09 03:56:35 +05:30
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
QString url = version->url();
|
2013-08-07 05:19:19 +05:30
|
|
|
QUrl realUrl(url);
|
|
|
|
QString hostname = realUrl.host();
|
2013-08-07 05:08:18 +05:30
|
|
|
auto &worker = NetWorker::spawn();
|
2013-08-07 05:19:19 +05:30
|
|
|
QNetworkRequest req(realUrl);
|
|
|
|
req.setRawHeader("Host", hostname.toLatin1());
|
2013-08-07 05:08:18 +05:30
|
|
|
req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)");
|
|
|
|
QNetworkReply * rep = worker.get ( req );
|
|
|
|
|
|
|
|
m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
|
|
|
|
connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
|
|
|
connect(&worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*)));
|
|
|
|
//connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
|
|
|
|
{
|
|
|
|
if(m_reply != reply)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(reply->error() != QNetworkReply::NoError)
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed( "Failed to download: "+
|
|
|
|
reply->errorString()+
|
|
|
|
"\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto &worker = NetWorker::spawn();
|
|
|
|
//Here i check if there is a cookie for me in the reply and extract it
|
|
|
|
QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie>>(reply->header(QNetworkRequest::SetCookieHeader));
|
|
|
|
if(cookies.count() != 0)
|
|
|
|
{
|
|
|
|
//you must tell which cookie goes with which url
|
|
|
|
worker.cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//here you can check for the 302 or whatever other header i need
|
|
|
|
QVariant newLoc = reply->header(QNetworkRequest::LocationHeader);
|
|
|
|
if(newLoc.isValid())
|
|
|
|
{
|
|
|
|
auto &worker = NetWorker::spawn();
|
|
|
|
QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString();
|
2013-08-07 05:19:19 +05:30
|
|
|
QUrl realUrl(redirectedTo);
|
|
|
|
QString hostname = realUrl.host();
|
2013-08-07 05:08:18 +05:30
|
|
|
QNetworkRequest req(redirectedTo);
|
2013-08-07 05:19:19 +05:30
|
|
|
req.setRawHeader("Host", hostname.toLatin1());
|
2013-08-07 05:08:18 +05:30
|
|
|
req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)");
|
|
|
|
QNetworkReply * rep = worker.get(req);
|
|
|
|
connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
|
|
|
m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QFile saveMe("lwjgl.zip");
|
|
|
|
saveMe.open(QIODevice::WriteOnly);
|
|
|
|
saveMe.write(m_reply->readAll());
|
|
|
|
saveMe.close();
|
|
|
|
setStatus("Installing new LWJGL...");
|
|
|
|
extractLwjgl();
|
2013-08-12 04:09:19 +05:30
|
|
|
jarStart();
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
void LegacyUpdate::extractLwjgl()
|
|
|
|
{
|
|
|
|
// make sure the directories are there
|
2013-08-09 03:56:35 +05:30
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
bool success = ensureFolderPathExists(lwjglNativesPath);
|
2013-08-07 05:08:18 +05:30
|
|
|
|
|
|
|
if(!success)
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Failed to extract the lwjgl libs - error when creating required folders.");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QuaZip zip("lwjgl.zip");
|
|
|
|
if(!zip.open(QuaZip::mdUnzip))
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Failed to extract the lwjgl libs - not a valid archive.");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and now we are going to access files inside it
|
|
|
|
QuaZipFile file(&zip);
|
|
|
|
const QString jarNames[] = { "jinput.jar", "lwjgl_util.jar", "lwjgl.jar" };
|
|
|
|
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile())
|
|
|
|
{
|
|
|
|
if(!file.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
zip.close();
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Failed to extract the lwjgl libs - error while reading archive.");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
QuaZipFileInfo info;
|
|
|
|
QString name = file.getActualFileName();
|
|
|
|
if(name.endsWith('/'))
|
|
|
|
{
|
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString destFileName;
|
|
|
|
// Look for the jars
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (name.endsWith(jarNames[i]))
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
destFileName = PathCombine(lwjglTargetPath, jarNames[i]);
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
// Not found? look for the natives
|
|
|
|
if(destFileName.isEmpty())
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
QString nativesDir = "windows";
|
|
|
|
#else
|
2013-08-26 06:23:29 +05:30
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QString nativesDir = "macosx";
|
|
|
|
#else
|
2013-08-07 05:08:18 +05:30
|
|
|
QString nativesDir = "linux";
|
2013-08-26 06:23:29 +05:30
|
|
|
#endif
|
2013-08-07 05:08:18 +05:30
|
|
|
#endif
|
|
|
|
if (name.contains(nativesDir))
|
|
|
|
{
|
|
|
|
int lastSlash = name.lastIndexOf('/');
|
|
|
|
int lastBackSlash = name.lastIndexOf('/');
|
|
|
|
if(lastSlash != -1)
|
|
|
|
name = name.mid(lastSlash+1);
|
|
|
|
else if(lastBackSlash != -1)
|
|
|
|
name = name.mid(lastBackSlash+1);
|
2013-08-09 03:56:35 +05:30
|
|
|
destFileName = PathCombine(lwjglNativesPath, name);
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now if destFileName is still empty, go to the next file.
|
|
|
|
if (!destFileName.isEmpty())
|
|
|
|
{
|
|
|
|
setStatus("Installing new LWJGL - Extracting " + name);
|
|
|
|
QFile output(destFileName);
|
|
|
|
output.open(QIODevice::WriteOnly);
|
|
|
|
output.write(file.readAll()); // FIXME: wste of memory!?
|
|
|
|
output.close();
|
|
|
|
}
|
|
|
|
file.close(); // do not forget to close!
|
|
|
|
}
|
|
|
|
zip.close();
|
|
|
|
m_reply.clear();
|
2013-08-09 03:56:35 +05:30
|
|
|
QFile doneFile(PathCombine(lwjglTargetPath, "done"));
|
|
|
|
doneFile.open(QIODevice::WriteOnly);
|
|
|
|
doneFile.write("done.");
|
|
|
|
doneFile.close();
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::lwjglFailed()
|
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Bad stuff happened while trying to get the lwjgl libs...");
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2013-08-12 04:09:19 +05:30
|
|
|
void LegacyUpdate::jarStart()
|
|
|
|
{
|
|
|
|
LegacyInstance * inst = (LegacyInstance *) m_inst;
|
2013-08-24 06:39:46 +05:30
|
|
|
if(!inst->shouldUpdate() || inst->shouldUseCustomBaseJar())
|
2013-08-12 04:09:19 +05:30
|
|
|
{
|
2013-08-24 06:39:46 +05:30
|
|
|
ModTheJar();
|
2013-08-12 04:09:19 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
setStatus("Checking for jar updates...");
|
2013-08-12 04:09:19 +05:30
|
|
|
// Make directories
|
|
|
|
QDir binDir(inst->binDir());
|
|
|
|
if (!binDir.exists() && !binDir.mkpath("."))
|
|
|
|
{
|
|
|
|
emitFailed("Failed to create bin folder.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a list of URLs that will need to be downloaded.
|
|
|
|
setStatus("Downloading new minecraft.jar");
|
|
|
|
|
|
|
|
QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
|
2013-08-24 06:39:46 +05:30
|
|
|
QString intended_version_id = inst->intendedVersionId();
|
|
|
|
urlstr += intended_version_id + "/" + intended_version_id + ".jar";
|
|
|
|
|
|
|
|
auto dljob = DownloadJob::create(QUrl(urlstr), inst->defaultBaseJar());
|
2013-08-12 04:09:19 +05:30
|
|
|
|
|
|
|
legacyDownloadJob.reset(new JobList());
|
|
|
|
legacyDownloadJob->add(dljob);
|
|
|
|
connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished()));
|
|
|
|
connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed()));
|
|
|
|
connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
|
|
|
download_queue.enqueue(legacyDownloadJob);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::jarFinished()
|
|
|
|
{
|
|
|
|
// process the jar
|
2013-08-24 06:39:46 +05:30
|
|
|
ModTheJar();
|
2013-08-12 04:09:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::jarFailed()
|
|
|
|
{
|
|
|
|
// bad, bad
|
|
|
|
emitFailed("Failed to download the minecraft jar. Try again later.");
|
|
|
|
}
|
2013-08-14 11:43:41 +05:30
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& contained )
|
|
|
|
{
|
|
|
|
setStatus("Installing mods - Adding " + from.fileName());
|
|
|
|
|
|
|
|
QuaZip modZip(from.filePath());
|
|
|
|
modZip.open(QuaZip::mdUnzip);
|
|
|
|
|
|
|
|
QuaZipFile fileInsideMod(&modZip);
|
|
|
|
QuaZipFile zipOutFile( into );
|
|
|
|
for(bool more=modZip.goToFirstFile(); more; more=modZip.goToNextFile())
|
|
|
|
{
|
|
|
|
QString filename = modZip.getCurrentFileName();
|
|
|
|
if(filename.contains("META-INF"))
|
|
|
|
continue;
|
|
|
|
if(contained.contains(filename))
|
|
|
|
continue;
|
|
|
|
contained.insert(filename);
|
|
|
|
qDebug() << "Adding file " << filename << " from " << from.fileName();
|
|
|
|
|
|
|
|
if(!fileInsideMod.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-25 05:02:42 +05:30
|
|
|
/*
|
|
|
|
QuaZipFileInfo old_info;
|
|
|
|
fileInsideMod.getFileInfo(&old_info);
|
|
|
|
*/
|
|
|
|
QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
|
|
|
|
/*
|
|
|
|
info_out.externalAttr = old_info.externalAttr;
|
|
|
|
*/
|
|
|
|
if(!zipOutFile.open(QIODevice::WriteOnly, info_out))
|
2013-08-24 06:39:46 +05:30
|
|
|
{
|
|
|
|
fileInsideMod.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!JlCompress::copyData(fileInsideMod, zipOutFile))
|
|
|
|
{
|
|
|
|
zipOutFile.close();
|
|
|
|
fileInsideMod.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
zipOutFile.close();
|
|
|
|
fileInsideMod.close();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-14 11:43:41 +05:30
|
|
|
void LegacyUpdate::ModTheJar()
|
|
|
|
{
|
|
|
|
LegacyInstance * inst = (LegacyInstance *) m_inst;
|
2013-08-24 06:39:46 +05:30
|
|
|
|
|
|
|
if(!inst->shouldRebuild())
|
|
|
|
{
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-14 11:43:41 +05:30
|
|
|
// Get the mod list
|
2013-08-24 06:39:46 +05:30
|
|
|
auto modList = inst->jarModList();
|
2013-08-14 11:43:41 +05:30
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
QFileInfo runnableJar (inst->runnableJar());
|
|
|
|
QFileInfo baseJar (inst->baseJar());
|
|
|
|
bool base_is_custom = inst->shouldUseCustomBaseJar();
|
2013-08-14 11:43:41 +05:30
|
|
|
|
|
|
|
// Nothing to do if there are no jar mods to install, no backup and just the mc jar
|
2013-08-24 06:39:46 +05:30
|
|
|
if(base_is_custom)
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-24 06:39:46 +05:30
|
|
|
// 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("Installing mods - backing up minecraft.jar...");
|
|
|
|
if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath()))
|
|
|
|
{
|
|
|
|
emitFailed("Failed to back up minecraft.jar");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 11:43:41 +05:30
|
|
|
}
|
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
if (!baseJar.exists())
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-24 06:39:46 +05:30
|
|
|
emitFailed("The base jar " + baseJar.filePath() + " does not exist");
|
2013-08-14 11:43:41 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
if (runnableJar.exists() && !QFile::remove(runnableJar.filePath()))
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
|
|
|
emitFailed("Failed to delete old minecraft.jar");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
//TaskStep(); // STEP 1
|
2013-08-14 11:43:41 +05:30
|
|
|
setStatus("Installing mods - Opening minecraft.jar");
|
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
QuaZip zipOut(runnableJar.filePath());
|
|
|
|
if(!zipOut.open(QuaZip::mdCreate))
|
|
|
|
{
|
|
|
|
QFile::remove(runnableJar.filePath());
|
|
|
|
emitFailed("Failed to open the minecraft.jar for modding");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 11:43:41 +05:30
|
|
|
// Files already added to the jar.
|
|
|
|
// These files will be skipped.
|
|
|
|
QSet<QString> addedFiles;
|
|
|
|
|
|
|
|
// Modify the jar
|
|
|
|
setStatus("Installing mods - Adding mod files...");
|
2013-08-24 06:39:46 +05:30
|
|
|
for (int i = modList->size() - 1; i >= 0; i--)
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-24 06:39:46 +05:30
|
|
|
auto &mod = modList->operator[](i);
|
|
|
|
if (mod.type() == Mod::MOD_ZIPFILE)
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-24 06:39:46 +05:30
|
|
|
if(!MergeZipFiles(&zipOut, mod.filename(), addedFiles))
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-24 06:39:46 +05:30
|
|
|
zipOut.close();
|
|
|
|
QFile::remove(runnableJar.filePath());
|
|
|
|
emitFailed("Failed to add " + mod.filename().fileName() + " to the jar.");
|
|
|
|
return;
|
2013-08-14 11:43:41 +05:30
|
|
|
}
|
|
|
|
}
|
2013-08-24 06:39:46 +05:30
|
|
|
else if (mod.type() == Mod::MOD_SINGLEFILE)
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-25 05:02:42 +05:30
|
|
|
auto filename = mod.filename();
|
|
|
|
if(!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName()))
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-25 05:02:42 +05:30
|
|
|
zipOut.close();
|
|
|
|
QFile::remove(runnableJar.filePath());
|
|
|
|
emitFailed("Failed to add " + filename.fileName() + " to the jar");
|
|
|
|
return;
|
2013-08-14 11:43:41 +05:30
|
|
|
}
|
2013-08-25 05:02:42 +05:30
|
|
|
addedFiles.insert(filename.fileName());
|
|
|
|
qDebug() << "Adding file " << filename.fileName() << " from " << filename.absoluteFilePath();
|
2013-08-14 11:43:41 +05:30
|
|
|
}
|
2013-08-24 06:39:46 +05:30
|
|
|
else if (mod.type() == Mod::MOD_FOLDER)
|
2013-08-14 11:43:41 +05:30
|
|
|
{
|
2013-08-25 05:02:42 +05:30
|
|
|
auto filename = mod.filename();
|
|
|
|
QString what_to_zip = filename.absoluteFilePath();
|
|
|
|
QDir dir(what_to_zip);
|
|
|
|
dir.cdUp();
|
|
|
|
QString parent_dir = dir.absolutePath();
|
|
|
|
if(!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles))
|
|
|
|
{
|
|
|
|
zipOut.close();
|
|
|
|
QFile::remove(runnableJar.filePath());
|
|
|
|
emitFailed("Failed to add " + filename.fileName() + " to the jar");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qDebug() << "Adding folder " << filename.fileName() << " from " << filename.absoluteFilePath();
|
2013-08-14 11:43:41 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 06:39:46 +05:30
|
|
|
if(!MergeZipFiles(&zipOut, baseJar, addedFiles))
|
|
|
|
{
|
|
|
|
zipOut.close();
|
|
|
|
QFile::remove(runnableJar.filePath());
|
|
|
|
emitFailed("Failed to insert minecraft.jar contents.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-14 11:43:41 +05:30
|
|
|
// Recompress the jar
|
2013-08-24 06:39:46 +05:30
|
|
|
zipOut.close();
|
|
|
|
if(zipOut.getZipError()!=0)
|
|
|
|
{
|
|
|
|
QFile::remove(runnableJar.filePath());
|
|
|
|
emitFailed("Failed to finalize minecraft.jar!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inst->setShouldRebuild(false);
|
|
|
|
//inst->UpdateVersion(true);
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
2013-08-14 11:43:41 +05:30
|
|
|
}
|