summaryrefslogtreecommitdiffstats
path: root/logic/LegacyUpdate.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-10-06 01:13:40 +0200
committerPetr Mrázek <peterix@gmail.com>2013-10-06 01:13:40 +0200
commitf83119ce7ec3d11a903901b8eff762d2b0a9f635 (patch)
tree5c30d7b9fff0f9417e7f2cd79d8ad9ea56d7f056 /logic/LegacyUpdate.cpp
parenteba9b3d759dbf6e402e91ab897059f1d274aef90 (diff)
downloadMultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar.gz
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar.lz
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar.xz
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.zip
Added file logger
Diffstat (limited to 'logic/LegacyUpdate.cpp')
-rw-r--r--logic/LegacyUpdate.cpp213
1 files changed, 112 insertions, 101 deletions
diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp
index d8e622dd..5f5a2e52 100644
--- a/logic/LegacyUpdate.cpp
+++ b/logic/LegacyUpdate.cpp
@@ -9,9 +9,11 @@
#include <quazip.h>
#include <quazipfile.h>
#include <JlCompress.h>
+#include <logger/QsLog.h>
-
-LegacyUpdate::LegacyUpdate ( BaseInstance* inst, QObject* parent ) : BaseUpdate ( inst, parent ) {}
+LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : BaseUpdate(inst, parent)
+{
+}
void LegacyUpdate::executeTask()
{
@@ -20,35 +22,35 @@ void LegacyUpdate::executeTask()
void LegacyUpdate::lwjglStart()
{
- LegacyInstance * inst = (LegacyInstance *) m_inst;
+ LegacyInstance *inst = (LegacyInstance *)m_inst;
+
+ lwjglVersion = inst->lwjglVersion();
+ lwjglTargetPath = PathCombine("lwjgl", lwjglVersion);
+ lwjglNativesPath = PathCombine(lwjglTargetPath, "natives");
- lwjglVersion = inst->lwjglVersion();
- lwjglTargetPath = PathCombine("lwjgl", lwjglVersion );
- lwjglNativesPath = PathCombine( lwjglTargetPath, "natives");
-
// if the 'done' file exists, we don't have to download this again
QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
- if(doneFile.exists())
+ if (doneFile.exists())
{
jarStart();
return;
}
-
+
auto list = MMC->lwjgllist();
- if(!list->isLoaded())
+ if (!list->isLoaded())
{
emitFailed("Too soon! Let the LWJGL list load :)");
return;
}
-
+
setStatus("Downloading new LWJGL.");
auto version = list->getVersion(lwjglVersion);
- if(!version)
+ if (!version)
{
emitFailed("Game update failed: the selected LWJGL version is invalid.");
return;
}
-
+
QString url = version->url();
QUrl realUrl(url);
QString hostname = realUrl.host();
@@ -56,39 +58,42 @@ void LegacyUpdate::lwjglStart()
QNetworkRequest req(realUrl);
req.setRawHeader("Host", hostname.toLatin1());
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)), SIGNAL(progress(qint64,qint64)));
- connect(worker.data(), SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*)));
- //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError)));
+ QNetworkReply *rep = worker->get(req);
+
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
+ connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
+ connect(worker.get(), SIGNAL(finished(QNetworkReply *)),
+ SLOT(lwjglFinished(QNetworkReply *)));
+ // connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
+ // SLOT(downloadError(QNetworkReply::NetworkError)));
}
-void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
+void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
{
- if(m_reply != reply)
+ if (m_reply.get() != reply)
{
return;
}
- if(reply->error() != QNetworkReply::NoError)
+ if (reply->error() != QNetworkReply::NoError)
{
- emitFailed( "Failed to download: "+
- reply->errorString()+
- "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV");
+ emitFailed("Failed to download: " + reply->errorString() +
+ "\nSometimes you have to wait a bit if you download many LWJGL versions in "
+ "a row. YMMV");
return;
}
auto worker = MMC->qnam();
- //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)
+ // 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
+ // 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
+ // here you can check for the 302 or whatever other header i need
QVariant newLoc = reply->header(QNetworkRequest::LocationHeader);
- if(newLoc.isValid())
+ if (newLoc.isValid())
{
QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString();
QUrl realUrl(redirectedTo);
@@ -96,9 +101,10 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
QNetworkRequest req(redirectedTo);
req.setRawHeader("Host", hostname.toLatin1());
req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)");
- QNetworkReply * rep = worker->get(req);
- connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
- m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
+ QNetworkReply *rep = worker->get(req);
+ connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
+ SIGNAL(progress(qint64, qint64)));
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
return;
}
QFile saveMe("lwjgl.zip");
@@ -114,26 +120,26 @@ void LegacyUpdate::extractLwjgl()
// make sure the directories are there
bool success = ensureFolderPathExists(lwjglNativesPath);
-
- if(!success)
+
+ if (!success)
{
emitFailed("Failed to extract the lwjgl libs - error when creating required folders.");
return;
}
-
+
QuaZip zip("lwjgl.zip");
- if(!zip.open(QuaZip::mdUnzip))
+ if (!zip.open(QuaZip::mdUnzip))
{
emitFailed("Failed to extract the lwjgl libs - not a valid archive.");
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())
+ const QString jarNames[] = {"jinput.jar", "lwjgl_util.jar", "lwjgl.jar"};
+ for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
{
- if(!file.open(QIODevice::ReadOnly))
+ if (!file.open(QIODevice::ReadOnly))
{
zip.close();
emitFailed("Failed to extract the lwjgl libs - error while reading archive.");
@@ -141,7 +147,7 @@ void LegacyUpdate::extractLwjgl()
}
QuaZipFileInfo info;
QString name = file.getActualFileName();
- if(name.endsWith('/'))
+ if (name.endsWith('/'))
{
file.close();
continue;
@@ -156,25 +162,25 @@ void LegacyUpdate::extractLwjgl()
}
}
// Not found? look for the natives
- if(destFileName.isEmpty())
+ if (destFileName.isEmpty())
{
#ifdef Q_OS_WIN32
QString nativesDir = "windows";
#else
- #ifdef Q_OS_MAC
+#ifdef Q_OS_MAC
QString nativesDir = "macosx";
- #else
+#else
QString nativesDir = "linux";
- #endif
+#endif
#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);
+ if (lastSlash != -1)
+ name = name.mid(lastSlash + 1);
+ else if (lastBackSlash != -1)
+ name = name.mid(lastBackSlash + 1);
destFileName = PathCombine(lwjglNativesPath, name);
}
}
@@ -190,7 +196,7 @@ void LegacyUpdate::extractLwjgl()
file.close(); // do not forget to close!
}
zip.close();
- m_reply.clear();
+ m_reply.reset();
QFile doneFile(PathCombine(lwjglTargetPath, "done"));
doneFile.open(QIODevice::WriteOnly);
doneFile.write("done.");
@@ -204,13 +210,13 @@ void LegacyUpdate::lwjglFailed()
void LegacyUpdate::jarStart()
{
- LegacyInstance * inst = (LegacyInstance *) m_inst;
- if(!inst->shouldUpdate() || inst->shouldUseCustomBaseJar())
+ LegacyInstance *inst = (LegacyInstance *)m_inst;
+ if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar())
{
ModTheJar();
return;
}
-
+
setStatus("Checking for jar updates...");
// Make directories
QDir binDir(inst->binDir());
@@ -226,13 +232,13 @@ void LegacyUpdate::jarStart()
QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
QString intended_version_id = inst->intendedVersionId();
urlstr += intended_version_id + "/" + intended_version_id + ".jar";
-
+
auto dljob = new DownloadJob("Minecraft.jar for version " + intended_version_id);
dljob->addFileDownload(QUrl(urlstr), inst->defaultBaseJar());
legacyDownloadJob.reset(dljob);
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
connect(dljob, SIGNAL(failed()), SLOT(jarFailed()));
- connect(dljob, SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
+ connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
legacyDownloadJob->start();
}
@@ -248,34 +254,36 @@ void LegacyUpdate::jarFailed()
emitFailed("Failed to download the minecraft jar. Try again later.");
}
-bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >& contained, MetainfAction metainf )
+bool LegacyUpdate::MergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
+ MetainfAction metainf)
{
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())
+ QuaZipFile zipOutFile(into);
+ for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile())
{
QString filename = modZip.getCurrentFileName();
- if(filename.contains("META-INF") && metainf == LegacyUpdate::IgnoreMetainf)
+ if (filename.contains("META-INF") && metainf == LegacyUpdate::IgnoreMetainf)
{
- qDebug() << "Skipping META-INF " << filename << " from " << from.fileName();
+ QLOG_INFO() << "Skipping META-INF " << filename << " from " << from.fileName();
continue;
}
- if(contained.contains(filename))
+ if (contained.contains(filename))
{
- qDebug() << "Skipping already contained file " << filename << " from " << from.fileName();
+ QLOG_INFO() << "Skipping already contained file " << filename << " from "
+ << from.fileName();
continue;
}
contained.insert(filename);
- qDebug() << "Adding file " << filename << " from " << from.fileName();
-
- if(!fileInsideMod.open(QIODevice::ReadOnly))
+ QLOG_INFO() << "Adding file " << filename << " from " << from.fileName();
+
+ if (!fileInsideMod.open(QIODevice::ReadOnly))
{
- qDebug() << "Failed to open " << filename << " from " << from.fileName();
+ QLOG_ERROR() << "Failed to open " << filename << " from " << from.fileName();
return false;
}
/*
@@ -286,17 +294,17 @@ bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >&
/*
info_out.externalAttr = old_info.externalAttr;
*/
- if(!zipOutFile.open(QIODevice::WriteOnly, info_out))
+ if (!zipOutFile.open(QIODevice::WriteOnly, info_out))
{
- qDebug() << "Failed to open " << filename << " in the jar";
+ QLOG_ERROR() << "Failed to open " << filename << " in the jar";
fileInsideMod.close();
return false;
}
- if(!JlCompress::copyData(fileInsideMod, zipOutFile))
+ if (!JlCompress::copyData(fileInsideMod, zipOutFile))
{
zipOutFile.close();
fileInsideMod.close();
- qDebug() << "Failed to copy data of " << filename << " into the jar";
+ QLOG_ERROR() << "Failed to copy data of " << filename << " into the jar";
return false;
}
zipOutFile.close();
@@ -307,34 +315,34 @@ bool LegacyUpdate::MergeZipFiles( QuaZip* into, QFileInfo from, QSet< QString >&
void LegacyUpdate::ModTheJar()
{
- LegacyInstance * inst = (LegacyInstance *) m_inst;
-
- if(!inst->shouldRebuild())
+ LegacyInstance *inst = (LegacyInstance *)m_inst;
+
+ if (!inst->shouldRebuild())
{
emitSucceeded();
return;
}
-
+
// Get the mod list
auto modList = inst->jarModList();
-
- QFileInfo runnableJar (inst->runnableJar());
- QFileInfo baseJar (inst->baseJar());
+
+ 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)
+ 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())
+ 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()))
{
@@ -342,24 +350,24 @@ void LegacyUpdate::ModTheJar()
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;
}
-
- //TaskStep(); // STEP 1
+
+ // TaskStep(); // STEP 1
setStatus("Installing mods - Opening minecraft.jar");
QuaZip zipOut(runnableJar.filePath());
- if(!zipOut.open(QuaZip::mdCreate))
+ if (!zipOut.open(QuaZip::mdCreate))
{
QFile::remove(runnableJar.filePath());
emitFailed("Failed to open the minecraft.jar for modding");
@@ -376,7 +384,7 @@ void LegacyUpdate::ModTheJar()
auto &mod = modList->operator[](i);
if (mod.type() == Mod::MOD_ZIPFILE)
{
- if(!MergeZipFiles(&zipOut, mod.filename(), addedFiles, LegacyUpdate::KeepMetainf))
+ if (!MergeZipFiles(&zipOut, mod.filename(), addedFiles, LegacyUpdate::KeepMetainf))
{
zipOut.close();
QFile::remove(runnableJar.filePath());
@@ -387,7 +395,8 @@ void LegacyUpdate::ModTheJar()
else if (mod.type() == Mod::MOD_SINGLEFILE)
{
auto filename = mod.filename();
- if(!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName()))
+ if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(),
+ filename.fileName()))
{
zipOut.close();
QFile::remove(runnableJar.filePath());
@@ -395,7 +404,8 @@ void LegacyUpdate::ModTheJar()
return;
}
addedFiles.insert(filename.fileName());
- qDebug() << "Adding file " << filename.fileName() << " from " << filename.absoluteFilePath();
+ QLOG_INFO() << "Adding file " << filename.fileName() << " from "
+ << filename.absoluteFilePath();
}
else if (mod.type() == Mod::MOD_FOLDER)
{
@@ -404,35 +414,36 @@ void LegacyUpdate::ModTheJar()
QDir dir(what_to_zip);
dir.cdUp();
QString parent_dir = dir.absolutePath();
- if(!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, true, addedFiles))
+ 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();
+ QLOG_INFO() << "Adding folder " << filename.fileName() << " from "
+ << filename.absoluteFilePath();
}
}
-
- if(!MergeZipFiles(&zipOut, baseJar, addedFiles, LegacyUpdate::IgnoreMetainf))
+
+ if (!MergeZipFiles(&zipOut, baseJar, addedFiles, LegacyUpdate::IgnoreMetainf))
{
zipOut.close();
QFile::remove(runnableJar.filePath());
emitFailed("Failed to insert minecraft.jar contents.");
return;
}
-
+
// Recompress the jar
zipOut.close();
- if(zipOut.getZipError()!=0)
+ if (zipOut.getZipError() != 0)
{
QFile::remove(runnableJar.filePath());
emitFailed("Failed to finalize minecraft.jar!");
return;
- }
+ }
inst->setShouldRebuild(false);
- //inst->UpdateVersion(true);
+ // inst->UpdateVersion(true);
emitSucceeded();
return;
} \ No newline at end of file