summaryrefslogtreecommitdiffstats
path: root/libmultimc/src/gameupdatetask.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-07-07 23:51:26 +0200
committerPetr Mrázek <peterix@gmail.com>2013-07-07 23:51:26 +0200
commitee5583251d92d47f96b03c3b447c115bab901c17 (patch)
treea95fe8709eb05ab776090479e49bae8d6def6d0e /libmultimc/src/gameupdatetask.cpp
parenta23323a01ee2713209619ad99d8859616aa99cdb (diff)
downloadMultiMC-ee5583251d92d47f96b03c3b447c115bab901c17.tar
MultiMC-ee5583251d92d47f96b03c3b447c115bab901c17.tar.gz
MultiMC-ee5583251d92d47f96b03c3b447c115bab901c17.tar.lz
MultiMC-ee5583251d92d47f96b03c3b447c115bab901c17.tar.xz
MultiMC-ee5583251d92d47f96b03c3b447c115bab901c17.zip
Legacy versions downloaded from the new location are treated as legacy versions!
Diffstat (limited to 'libmultimc/src/gameupdatetask.cpp')
-rw-r--r--libmultimc/src/gameupdatetask.cpp196
1 files changed, 96 insertions, 100 deletions
diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp
index 49f9335f..fee2aa29 100644
--- a/libmultimc/src/gameupdatetask.cpp
+++ b/libmultimc/src/gameupdatetask.cpp
@@ -27,25 +27,20 @@
#include "minecraftversionlist.h"
#include "pathutils.h"
-#include "netutils.h"
GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) :
Task(parent), m_response(response)
{
m_inst = inst;
m_updateState = StateInit;
- m_currentDownload = 0;
}
void GameUpdateTask::executeTask()
{
updateStatus();
- QNetworkAccessManager networkMgr;
- netMgr = &networkMgr;
-
// Get a pointer to the version object that corresponds to the instance's version.
- MinecraftVersion *targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().
+ targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().
findVersion(m_inst->intendedVersion());
if(targetVersion == NULL)
{
@@ -55,16 +50,6 @@ void GameUpdateTask::executeTask()
return;
}
- // Make directories
- QDir binDir(m_inst->binDir());
- if (!binDir.exists() && !binDir.mkpath("."))
- {
- error("Failed to create bin folder.");
- return;
- }
-
-
-
/////////////////////////
// BUILD DOWNLOAD LIST //
/////////////////////////
@@ -72,90 +57,116 @@ void GameUpdateTask::executeTask()
setState(StateDetermineURLs);
-
- // Add the URL for minecraft.jar
-
- // This will be either 'minecraft' or the version number, depending on where
- // we're downloading from.
- QString jarFilename = "minecraft";
-
- // FIXME: this is NOT enough
if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16)
- jarFilename = targetVersion->descriptor();
-
- QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar";
- qDebug() << mcJarURL.toString();
- m_downloadList.append(FileToDownload::Create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar")));
-
-
-
- ////////////////////
- // DOWNLOAD FILES //
- ////////////////////
- setState(StateDownloadFiles);
- for (int i = 0; i < m_downloadList.length(); i++)
{
- m_currentDownload = i;
- if (!downloadFile(m_downloadList[i]))
- return;
+ determineNewVersion();
}
+ else
+ {
+ getLegacyJar();
+ }
+ QEventLoop loop;
+ loop.exec();
+}
+
+void GameUpdateTask::determineNewVersion()
+{
+ QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
+ urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json";
+ auto dljob = DownloadJob::create(QUrl(urlstr));
+ specificVersionDownloadJob.reset(new JobList());
+ specificVersionDownloadJob->add(dljob);
+ connect(specificVersionDownloadJob.data(), SIGNAL(finished()), SLOT(versionFileFinished()));
+ connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
+ connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ download_queue.enqueue(specificVersionDownloadJob);
+}
+
+void GameUpdateTask::versionFileFinished()
+{
+ JobPtr firstJob = specificVersionDownloadJob->getFirstJob();
+ auto DlJob = firstJob.dynamicCast<DownloadJob>();
+ QJsonParseError jsonError;
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(DlJob->m_data, &jsonError);
+ if (jsonError.error != QJsonParseError::NoError)
+ {
+ error(QString( "Error reading version file :") + " " + jsonError.errorString());
+ exit(0);
+ }
+ Q_ASSERT_X(jsonDoc.isObject(), "loadFromVList", "jsonDoc is not an object");
+ if(!jsonDoc.isObject())
+ {
+ error("Error reading version file.");
+ exit(0);
+ }
+ QJsonObject root = jsonDoc.object();
- ///////////////////
- // INSTALL FILES //
- ///////////////////
- setState(StateInstall);
-
- // Nothing to do here yet
-
+ QString args = root.value("processArguments").toString("legacy");
+ if(args == "legacy")
+ {
+ getLegacyJar();
+ return;
+ }
- //////////////
- // FINISHED //
- //////////////
- setState(StateFinished);
- emit gameUpdateComplete(m_response);
+ error("MC 1.6 isn't supported yet...");
+ exit(0);
}
-bool GameUpdateTask::downloadFile( const FileToDownloadPtr file )
+void GameUpdateTask::versionFileFailed()
{
- setSubStatus("Downloading " + file->url().toString());
- QNetworkReply *reply = netMgr->get(QNetworkRequest(file->url()));
-
- this->connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
- SLOT(updateDownloadProgress(qint64,qint64)));
-
- NetUtils::waitForNetRequest(reply);
-
- if (reply->error() == QNetworkReply::NoError)
+ error("Failed to download the version description. Try again.");
+ exit(0);
+}
+
+
+// this is legacy minecraft...
+void GameUpdateTask::getLegacyJar()
+{
+ // Make directories
+ QDir binDir(m_inst->binDir());
+ if (!binDir.exists() && !binDir.mkpath("."))
{
- QString filePath = file->path();
- QFile outFile(filePath);
- if (outFile.exists() && !outFile.remove())
- {
- error("Can't delete old file " + file->path() + ": " + outFile.errorString());
- return false;
- }
-
- if (!outFile.open(QIODevice::WriteOnly))
- {
- error("Can't write to " + file->path() + ": " + outFile.errorString());
- return false;
- }
-
- outFile.write(reply->readAll());
- outFile.close();
+ error("Failed to create bin folder.");
+ return;
}
- else
+
+ // Add the URL for minecraft.jar
+ // This will be either 'minecraft' or the version number, depending on where
+ // we're downloading from.
+ QString jarFilename = "minecraft";
+ if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16)
{
- error("Can't download " + file->url().toString() + ": " + reply->errorString());
- return false;
+ jarFilename = targetVersion->descriptor();
}
- // TODO: Check file integrity after downloading.
+ QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar";
+ qDebug() << mcJarURL.toString();
+ auto dljob = DownloadJob::create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar"));
+
+ legacyDownloadJob.reset(new JobList());
+ legacyDownloadJob->add(dljob);
+ connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(legacyJarFinished()));
+ connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(legacyJarFailed()));
+ connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
- return true;
+ download_queue.enqueue(legacyDownloadJob);
+}
+
+
+void GameUpdateTask::legacyJarFinished()
+{
+ setState(StateFinished);
+ emit gameUpdateComplete(m_response);
+ exit(1);
+}
+
+void GameUpdateTask::legacyJarFailed()
+{
+ emit gameUpdateError("failed to download the minecraft.jar");
+ exit(0);
}
int GameUpdateTask::state() const
@@ -229,22 +240,7 @@ void GameUpdateTask::error(const QString &msg)
void GameUpdateTask::updateDownloadProgress(qint64 current, qint64 total)
{
// The progress on the current file is current / total
- float currentDLProgress = (float) current / (float) total; // Cast ALL the values!
-
- // The overall progress is (current progress + files downloaded) / total files to download
- float overallDLProgress = ((currentDLProgress + m_currentDownload) / (float) m_downloadList.length());
-
- // Multiply by 100 to make it a percentage.
- setProgress((int)(overallDLProgress * 100));
-}
-
-FileToDownloadPtr FileToDownload::Create(const QUrl &url, const QString &path, QObject *parent)
-{
- return FileToDownloadPtr(new FileToDownload (url, path, parent));
+ float currentDLProgress = (float) current / (float) total;
+ setProgress((int)(currentDLProgress * 100)); // convert to percentage
}
-FileToDownload::FileToDownload(const QUrl &url, const QString &path, QObject *parent) :
- QObject(parent), m_dlURL(url), m_dlPath(path)
-{
-
-}