From a23323a01ee2713209619ad99d8859616aa99cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 7 Jul 2013 18:12:09 +0200 Subject: Small tweaks to the assets - delete extra files --- libmultimc/src/gameupdatetask.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libmultimc/src/gameupdatetask.cpp') diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index c718ce71..49f9335f 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -47,7 +47,13 @@ void GameUpdateTask::executeTask() // Get a pointer to the version object that corresponds to the instance's version. MinecraftVersion *targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList(). findVersion(m_inst->intendedVersion()); - Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version"); + if(targetVersion == NULL) + { + //Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version"); + setState(StateFinished); + emit gameUpdateComplete(m_response); + return; + } // Make directories QDir binDir(m_inst->binDir()); -- cgit v1.2.3 From ee5583251d92d47f96b03c3b447c115bab901c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 7 Jul 2013 23:51:26 +0200 Subject: Legacy versions downloaded from the new location are treated as legacy versions! --- libmultimc/src/gameupdatetask.cpp | 196 +++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 100 deletions(-) (limited to 'libmultimc/src/gameupdatetask.cpp') 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(); + 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) -{ - -} -- cgit v1.2.3 From dd86061f0ff6d19482e9a43af99156a55e60cf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 9 Jul 2013 00:52:03 +0200 Subject: Piddle-farting with 1.6 instances. Now with more json! --- libmultimc/src/gameupdatetask.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'libmultimc/src/gameupdatetask.cpp') diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index fee2aa29..54e47410 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -95,7 +95,6 @@ void GameUpdateTask::versionFileFinished() exit(0); } - Q_ASSERT_X(jsonDoc.isObject(), "loadFromVList", "jsonDoc is not an object"); if(!jsonDoc.isObject()) { error("Error reading version file."); @@ -103,6 +102,10 @@ void GameUpdateTask::versionFileFinished() } QJsonObject root = jsonDoc.object(); + /* + * FIXME: this distinction is pretty weak. The only other option + * is to have a list of all the legacy versions. + */ QString args = root.value("processArguments").toString("legacy"); if(args == "legacy") { @@ -110,8 +113,26 @@ void GameUpdateTask::versionFileFinished() return; } + // save the version file in $instanceId/version.json and versions/$version/$version.json + QString version_id = targetVersion->descriptor(); + QString mc_dir = m_inst->minecraftDir(); + QString inst_dir = m_inst->rootDir(); + QString version1 = PathCombine(inst_dir, "/version.json"); + QString version2 = QString("versions/") + version_id + "/" + version_id + ".json"; + DownloadJob::ensurePathExists(version1); + DownloadJob::ensurePathExists(version2); + QFile vfile1 (version1); + QFile vfile2 (version2); + vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly ); + vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly ); + vfile1.write(DlJob->m_data); + vfile2.write(DlJob->m_data); + vfile1.close(); + vfile2.close(); + + // download the right jar, save it in versions/$version/$version.jar + // determine and download all the libraries, save them in libraries/whatever... - error("MC 1.6 isn't supported yet..."); exit(0); } -- cgit v1.2.3 From c96ac2460522b9567a10831bcd1d8a6bc9f36d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 9 Jul 2013 22:46:33 +0200 Subject: Replace one line. Get downloading of 1.6 jars working. Yay. --- libmultimc/src/gameupdatetask.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libmultimc/src/gameupdatetask.cpp') diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index 54e47410..a8abb0b6 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -131,8 +131,32 @@ void GameUpdateTask::versionFileFinished() vfile2.close(); // download the right jar, save it in versions/$version/$version.jar - // determine and download all the libraries, save them in libraries/whatever... + QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); + urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar"; + QString targetstr ("versions/"); + targetstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar"; + auto dljob = DownloadJob::create(QUrl(urlstr), targetstr); + jarlibDownloadJob.reset(new JobList()); + jarlibDownloadJob->add(dljob); + connect(jarlibDownloadJob.data(), SIGNAL(finished()), SLOT(jarlibFinished())); + connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); + connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + // determine and download all the libraries, save them in libraries/whatever... + download_queue.enqueue(jarlibDownloadJob); +} + +void GameUpdateTask::jarlibFinished() +{ + exit(1); + // YAYAYAYAYYAYAAUAYAYYAYYY!!!! + // WEE DID IT! + // YESSSSS! +} + +void GameUpdateTask::jarlibFailed() +{ + error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE"); exit(0); } -- cgit v1.2.3 From 33b9b25da7d3d29f949c9418295de257d437c9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 14 Jul 2013 18:33:31 +0200 Subject: More work on the downloader and 1.6 instance creation --- libmultimc/src/gameupdatetask.cpp | 51 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'libmultimc/src/gameupdatetask.cpp') diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index a8abb0b6..b6c1f936 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -112,6 +112,52 @@ void GameUpdateTask::versionFileFinished() getLegacyJar(); return; } + /* + // Iterate through the list. + QJsonObject groupList = root.value("libraries").toObject(); + + for (QJsonObject::iterator iter = groupList.begin(); + iter != groupList.end(); iter++) + { + QString groupName = iter.key(); + + // If not an object, complain and skip to the next one. + if (!iter.value().isObject()) + { + qWarning(QString("Group '%1' in the group list should " + "be an object.").arg(groupName).toUtf8()); + continue; + } + + QJsonObject groupObj = iter.value().toObject(); + + // Create the group object. + InstanceGroup *group = new InstanceGroup(groupName, this); + groups.push_back(group); + + // If 'hidden' isn't a bool value, just assume it's false. + if (groupObj.value("hidden").isBool() && groupObj.value("hidden").toBool()) + { + group->setHidden(groupObj.value("hidden").toBool()); + } + + if (!groupObj.value("instances").isArray()) + { + qWarning(QString("Group '%1' in the group list is invalid. " + "It should contain an array " + "called 'instances'.").arg(groupName).toUtf8()); + continue; + } + + // Iterate through the list of instances in the group. + QJsonArray instancesArray = groupObj.value("instances").toArray(); + + for (QJsonArray::iterator iter2 = instancesArray.begin(); + iter2 != instancesArray.end(); iter2++) + { + groupMap[(*iter2).toString()] = groupName; + } + }*/ // save the version file in $instanceId/version.json and versions/$version/$version.json QString version_id = targetVersion->descriptor(); @@ -148,10 +194,9 @@ void GameUpdateTask::versionFileFinished() void GameUpdateTask::jarlibFinished() { + m_inst->setCurrentVersion(targetVersion->descriptor()); + m_inst->setShouldUpdate(false); exit(1); - // YAYAYAYAYYAYAAUAYAYYAYYY!!!! - // WEE DID IT! - // YESSSSS! } void GameUpdateTask::jarlibFailed() -- cgit v1.2.3 From 18853ca3fa185f5fe5288a1d0c8ed6cf8c678007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 22 Jul 2013 02:01:56 +0200 Subject: Parsing the version files, part I --- libmultimc/src/gameupdatetask.cpp | 71 +++++---------------------------------- 1 file changed, 8 insertions(+), 63 deletions(-) (limited to 'libmultimc/src/gameupdatetask.cpp') diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index b6c1f936..61880118 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -25,9 +25,12 @@ #include #include "minecraftversionlist.h" +#include "fullversionfactory.h" +#include #include "pathutils.h" + GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) : Task(parent), m_response(response) { @@ -86,78 +89,20 @@ void GameUpdateTask::versionFileFinished() { JobPtr firstJob = specificVersionDownloadJob->getFirstJob(); auto DlJob = firstJob.dynamicCast(); - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(DlJob->m_data, &jsonError); + FullVersionFactory parser; + auto version = parser.parse(DlJob->m_data); - if (jsonError.error != QJsonParseError::NoError) + if(!version) { - error(QString( "Error reading version file :") + " " + jsonError.errorString()); + error(parser.error_string); exit(0); } - if(!jsonDoc.isObject()) - { - error("Error reading version file."); - exit(0); - } - QJsonObject root = jsonDoc.object(); - - /* - * FIXME: this distinction is pretty weak. The only other option - * is to have a list of all the legacy versions. - */ - QString args = root.value("processArguments").toString("legacy"); - if(args == "legacy") + if(version->isLegacy) { getLegacyJar(); return; } - /* - // Iterate through the list. - QJsonObject groupList = root.value("libraries").toObject(); - - for (QJsonObject::iterator iter = groupList.begin(); - iter != groupList.end(); iter++) - { - QString groupName = iter.key(); - - // If not an object, complain and skip to the next one. - if (!iter.value().isObject()) - { - qWarning(QString("Group '%1' in the group list should " - "be an object.").arg(groupName).toUtf8()); - continue; - } - - QJsonObject groupObj = iter.value().toObject(); - - // Create the group object. - InstanceGroup *group = new InstanceGroup(groupName, this); - groups.push_back(group); - - // If 'hidden' isn't a bool value, just assume it's false. - if (groupObj.value("hidden").isBool() && groupObj.value("hidden").toBool()) - { - group->setHidden(groupObj.value("hidden").toBool()); - } - - if (!groupObj.value("instances").isArray()) - { - qWarning(QString("Group '%1' in the group list is invalid. " - "It should contain an array " - "called 'instances'.").arg(groupName).toUtf8()); - continue; - } - - // Iterate through the list of instances in the group. - QJsonArray instancesArray = groupObj.value("instances").toArray(); - - for (QJsonArray::iterator iter2 = instancesArray.begin(); - iter2 != instancesArray.end(); iter2++) - { - groupMap[(*iter2).toString()] = groupName; - } - }*/ // save the version file in $instanceId/version.json and versions/$version/$version.json QString version_id = targetVersion->descriptor(); -- cgit v1.2.3 From a7a84d4dbb58565f108cb0886da6cb786e34d10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 27 Jul 2013 11:41:45 +0200 Subject: Parsing the version files, part III --- libmultimc/src/gameupdatetask.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libmultimc/src/gameupdatetask.cpp') diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index 61880118..bae85c17 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -141,6 +141,7 @@ void GameUpdateTask::jarlibFinished() { m_inst->setCurrentVersion(targetVersion->descriptor()); m_inst->setShouldUpdate(false); + m_inst->setIsForNewLauncher(true); exit(1); } @@ -195,6 +196,7 @@ void GameUpdateTask::legacyJarFinished() { setState(StateFinished); emit gameUpdateComplete(m_response); + m_inst->setIsForNewLauncher(true); exit(1); } -- cgit v1.2.3