aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-02-08 17:56:14 +0100
committerPetr Mrázek <peterix@gmail.com>2015-04-12 20:57:17 +0200
commit4730f54df7edf4775dfddf45f77c60edd86c32d9 (patch)
tree22fe05326976cbdadf150c1cfe0710f375e34edf
parent7a71ecd8af0454e405b25080a4b266fc99306269 (diff)
downloadPrismLauncher-4730f54df7edf4775dfddf45f77c60edd86c32d9.tar.gz
PrismLauncher-4730f54df7edf4775dfddf45f77c60edd86c32d9.tar.bz2
PrismLauncher-4730f54df7edf4775dfddf45f77c60edd86c32d9.zip
SCRATCH separate the generic updater logic from the application
-rw-r--r--CMakeLists.txt8
-rw-r--r--MultiMC.cpp2
-rw-r--r--MultiMC.h2
-rw-r--r--gui/MainWindow.cpp15
-rw-r--r--gui/MainWindow.h7
-rw-r--r--logic/BaseProcess.cpp6
-rw-r--r--logic/BaseProcess.h9
-rw-r--r--logic/forge/ForgeMirrors.cpp2
-rw-r--r--logic/forge/ForgeXzDownload.cpp2
-rw-r--r--logic/minecraft/MinecraftProcess.cpp4
-rw-r--r--logic/net/ByteArrayDownload.cpp2
-rw-r--r--logic/net/CacheDownload.cpp2
-rw-r--r--logic/net/MD5EtagDownload.cpp2
-rw-r--r--logic/net/NetAction.h3
-rw-r--r--logic/net/NetJob.cpp4
-rw-r--r--logic/net/NetJob.h1
-rw-r--r--logic/screenshots/ImgurAlbumCreation.cpp2
-rw-r--r--logic/screenshots/ImgurUpload.cpp2
-rw-r--r--logic/updater/DownloadTask.cpp179
-rw-r--r--logic/updater/DownloadTask.h85
-rw-r--r--logic/updater/DownloadUpdateTask.cpp549
-rw-r--r--logic/updater/DownloadUpdateTask.h220
-rw-r--r--logic/updater/GoUpdate.cpp315
-rw-r--r--logic/updater/GoUpdate.h135
-rw-r--r--logic/updater/UpdateChecker.cpp25
-rw-r--r--logic/updater/UpdateChecker.h12
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/data/tst_DownloadTask-test_writeInstallScript.xml (renamed from tests/data/tst_DownloadUpdateTask-test_writeInstallScript.xml)0
-rw-r--r--tests/tst_DownloadTask.cpp256
-rw-r--r--tests/tst_DownloadUpdateTask.cpp273
-rw-r--r--tests/tst_UpdateChecker.cpp34
31 files changed, 1056 insertions, 1104 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4281d5a..f06a7902 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -458,10 +458,14 @@ SET(MULTIMC_SOURCES
logic/auth/flows/ValidateTask.cpp
# Update system
+ logic/updater/GoUpdate.h
+ logic/updater/GoUpdate.cpp
logic/updater/UpdateChecker.h
logic/updater/UpdateChecker.cpp
- logic/updater/DownloadUpdateTask.h
- logic/updater/DownloadUpdateTask.cpp
+ logic/updater/DownloadTask.h
+ logic/updater/DownloadTask.cpp
+
+ # Notifications - short warning messages
logic/notifications/NotificationChecker.h
logic/notifications/NotificationChecker.cpp
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 8375dc1b..2ce668f2 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -192,7 +192,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
initTranslations();
// initialize the updater
- m_updateChecker.reset(new UpdateChecker(BuildConfig.CHANLIST_URL, BuildConfig.VERSION_BUILD));
+ m_updateChecker.reset(new UpdateChecker(BuildConfig.CHANLIST_URL, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
m_translationChecker.reset(new TranslationDownloader());
diff --git a/MultiMC.h b/MultiMC.h
index 33aebab0..b78bbbd2 100644
--- a/MultiMC.h
+++ b/MultiMC.h
@@ -155,7 +155,7 @@ private:
private:
friend class UpdateCheckerTest;
- friend class DownloadUpdateTaskTest;
+ friend class DownloadTaskTest;
QDateTime startTime;
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 1b76e6af..0b0af7f4 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -369,7 +369,7 @@ namespace Ui {
#include "logic/auth/flows/AuthenticateTask.h"
#include "logic/auth/flows/RefreshTask.h"
-#include "logic/updater/DownloadUpdateTask.h"
+#include "logic/updater/DownloadTask.h"
#include "logic/news/NewsChecker.h"
@@ -913,7 +913,7 @@ void MainWindow::updateNewsLabel()
}
}
-void MainWindow::updateAvailable(QString repo, QString versionName, int versionId)
+void MainWindow::updateAvailable(GoUpdate::Status status)
{
UpdateDialog dlg;
UpdateAction action = (UpdateAction)dlg.exec();
@@ -923,10 +923,10 @@ void MainWindow::updateAvailable(QString repo, QString versionName, int versionI
qDebug() << "Update will be installed later.";
break;
case UPDATE_NOW:
- downloadUpdates(repo, versionId);
+ downloadUpdates(status);
break;
case UPDATE_ONEXIT:
- downloadUpdates(repo, versionId, true);
+ downloadUpdates(status, true);
break;
}
}
@@ -977,7 +977,7 @@ void MainWindow::notificationsChanged()
MMC->settings()->set("ShownNotifications", intListToString(shownNotifications));
}
-void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit)
+void MainWindow::downloadUpdates(GoUpdate::Status status, bool installOnExit)
{
qDebug() << "Downloading updates.";
// TODO: If the user chooses to update on exit, we should download updates in the
@@ -985,7 +985,9 @@ void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit
// Doing so is a bit complicated, because we'd have to make sure it finished downloading
// before actually exiting MultiMC.
ProgressDialog updateDlg(this);
- DownloadUpdateTask updateTask(MMC->root(), repo, versionId, &updateDlg);
+ status.rootPath = MMC->rootPath;
+
+ GoUpdate::DownloadTask updateTask(status, &updateDlg);
// If the task succeeds, install the updates.
if (updateDlg.exec(&updateTask))
{
@@ -1827,6 +1829,7 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session,
console = new ConsoleWindow(proc);
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
+ proc->setHeader("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n");
proc->arm();
if (profiler)
diff --git a/gui/MainWindow.h b/gui/MainWindow.h
index cccd9f9c..13edce81 100644
--- a/gui/MainWindow.h
+++ b/gui/MainWindow.h
@@ -22,6 +22,7 @@
#include "logic/BaseInstance.h"
#include "logic/auth/MojangAccount.h"
#include "logic/net/NetJob.h"
+#include "logic/updater/GoUpdate.h"
class NewsChecker;
class NotificationChecker;
@@ -157,7 +158,7 @@ slots:
void startTask(Task *task);
- void updateAvailable(QString repo, QString versionName, int versionId);
+ void updateAvailable(GoUpdate::Status status);
void updateNotAvailable();
@@ -172,9 +173,9 @@ slots:
void updateNewsLabel();
/*!
- * Runs the DownloadUpdateTask and installs updates.
+ * Runs the DownloadTask and installs updates.
*/
- void downloadUpdates(QString repo, int versionId, bool installOnExit = false);
+ void downloadUpdates(GoUpdate::Status status, bool installOnExit = false);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
diff --git a/logic/BaseProcess.cpp b/logic/BaseProcess.cpp
index eb1bbfdc..b0509d46 100644
--- a/logic/BaseProcess.cpp
+++ b/logic/BaseProcess.cpp
@@ -139,6 +139,12 @@ void BaseProcess::setWorkdir(QString path)
m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath());
}
+void BaseProcess::printHeader()
+{
+ emit log(m_header);
+}
+
+
void BaseProcess::logOutput(const QStringList &lines, MessageLevel::Enum defaultLevel,
bool guessLevel, bool censor)
{
diff --git a/logic/BaseProcess.h b/logic/BaseProcess.h
index ff8b9ed3..75bf0217 100644
--- a/logic/BaseProcess.h
+++ b/logic/BaseProcess.h
@@ -54,6 +54,12 @@ public: /* methods */
return m_instance;
}
+ /// Set the text printed on top of the log
+ void setHeader(QString header)
+ {
+ m_header = header;
+ }
+
void setWorkdir(QString path);
void killProcess();
@@ -79,6 +85,8 @@ protected: /* methods */
bool waitForPrePost();
QString substituteVariables(const QString &cmd) const;
+ void printHeader();
+
virtual QMap<QString, QString> getVariables() const = 0;
virtual QString censorPrivateInfo(QString in) = 0;
virtual MessageLevel::Enum guessLevel(const QString &message, MessageLevel::Enum defaultLevel) = 0;
@@ -130,4 +138,5 @@ protected:
QString m_out_leftover;
QProcess m_prepostlaunchprocess;
bool killed = false;
+ QString m_header;
};
diff --git a/logic/forge/ForgeMirrors.cpp b/logic/forge/ForgeMirrors.cpp
index 06abb88f..e922fcc3 100644
--- a/logic/forge/ForgeMirrors.cpp
+++ b/logic/forge/ForgeMirrors.cpp
@@ -21,7 +21,7 @@ void ForgeMirrors::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
diff --git a/logic/forge/ForgeXzDownload.cpp b/logic/forge/ForgeXzDownload.cpp
index ac2c4b1f..65b20959 100644
--- a/logic/forge/ForgeXzDownload.cpp
+++ b/logic/forge/ForgeXzDownload.cpp
@@ -70,7 +70,7 @@ void ForgeXzDownload::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
diff --git a/logic/minecraft/MinecraftProcess.cpp b/logic/minecraft/MinecraftProcess.cpp
index e8682a50..75287856 100644
--- a/logic/minecraft/MinecraftProcess.cpp
+++ b/logic/minecraft/MinecraftProcess.cpp
@@ -14,8 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "BuildConfig.h"
-
#include "logic/minecraft/MinecraftProcess.h"
#include "logic/BaseInstance.h"
@@ -158,7 +156,7 @@ QStringList MinecraftProcess::javaArguments() const
void MinecraftProcess::arm()
{
- emit log("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n");
+ printHeader();
emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n");
if (!preLaunch())
diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp
index 9f71f911..7a41ee28 100644
--- a/logic/net/ByteArrayDownload.cpp
+++ b/logic/net/ByteArrayDownload.cpp
@@ -31,7 +31,7 @@ void ByteArrayDownload::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp
index 6ddfc55f..0bbe75c3 100644
--- a/logic/net/CacheDownload.cpp
+++ b/logic/net/CacheDownload.cpp
@@ -77,7 +77,7 @@ void CacheDownload::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
diff --git a/logic/net/MD5EtagDownload.cpp b/logic/net/MD5EtagDownload.cpp
index 6e1d0cfc..03752ea8 100644
--- a/logic/net/MD5EtagDownload.cpp
+++ b/logic/net/MD5EtagDownload.cpp
@@ -86,7 +86,7 @@ void MD5EtagDownload::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
diff --git a/logic/net/NetAction.h b/logic/net/NetAction.h
index 81cb1bdb..b306bdfe 100644
--- a/logic/net/NetAction.h
+++ b/logic/net/NetAction.h
@@ -19,6 +19,7 @@
#include <QUrl>
#include <memory>
#include <QNetworkReply>
+#include <logic/QObjectPtr.h>
enum JobStatus
{
@@ -58,7 +59,7 @@ public:
public:
/// the network reply
- std::shared_ptr<QNetworkReply> m_reply;
+ QObjectPtr<QNetworkReply> m_reply;
/// the content of the content-type header
QString m_content_type;
diff --git a/logic/net/NetJob.cpp b/logic/net/NetJob.cpp
index e10afbc8..5a50b876 100644
--- a/logic/net/NetJob.cpp
+++ b/logic/net/NetJob.cpp
@@ -29,7 +29,7 @@ void NetJob::partSucceeded(int index)
m_doing.remove(index);
m_done.insert(index);
- disconnect(downloads[index].get(), 0, this, 0);
+ downloads[index].get()->disconnect(this);
startMoreParts();
}
@@ -46,7 +46,7 @@ void NetJob::partFailed(int index)
slot.failures++;
m_todo.enqueue(index);
}
- disconnect(downloads[index].get(), 0, this, 0);
+ downloads[index].get()->disconnect(this);
startMoreParts();
}
diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h
index 0d8b7fbd..708afa79 100644
--- a/logic/net/NetJob.h
+++ b/logic/net/NetJob.h
@@ -108,6 +108,7 @@ private:
qint64 current_progress = 0;
qint64 total_progress = 1;
int failures = 0;
+ bool connected = false;
};
QString m_job_name;
QList<NetActionPtr> downloads;
diff --git a/logic/screenshots/ImgurAlbumCreation.cpp b/logic/screenshots/ImgurAlbumCreation.cpp
index 45db75cf..f7cc2971 100644
--- a/logic/screenshots/ImgurAlbumCreation.cpp
+++ b/logic/screenshots/ImgurAlbumCreation.cpp
@@ -36,7 +36,7 @@ void ImgurAlbumCreation::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->post(request, data);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, &QNetworkReply::uploadProgress, this, &ImgurAlbumCreation::downloadProgress);
connect(rep, &QNetworkReply::finished, this, &ImgurAlbumCreation::downloadFinished);
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
diff --git a/logic/screenshots/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp
index 1d490436..4ae37dfa 100644
--- a/logic/screenshots/ImgurUpload.cpp
+++ b/logic/screenshots/ImgurUpload.cpp
@@ -51,7 +51,7 @@ void ImgurUpload::start()
auto worker = ENV.qnam();
QNetworkReply *rep = worker->post(request, multipart);
- m_reply = std::shared_ptr<QNetworkReply>(rep);
+ m_reply.reset(rep);
connect(rep, &QNetworkReply::uploadProgress, this, &ImgurUpload::downloadProgress);
connect(rep, &QNetworkReply::finished, this, &ImgurUpload::downloadFinished);
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
diff --git a/logic/updater/DownloadTask.cpp b/logic/updater/DownloadTask.cpp
new file mode 100644
index 00000000..badbc0d0
--- /dev/null
+++ b/logic/updater/DownloadTask.cpp
@@ -0,0 +1,179 @@
+/* Copyright 2013-2014 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "DownloadTask.h"
+
+#include "logic/updater/UpdateChecker.h"
+#include "GoUpdate.h"
+#include "logic/net/NetJob.h"
+#include "pathutils.h"
+
+#include <QFile>
+#include <QTemporaryDir>
+#include <QCryptographicHash>
+
+namespace GoUpdate
+{
+
+DownloadTask::DownloadTask(Status status, QObject *parent)
+ : Task(parent)
+{
+ m_status = status;
+
+ m_updateFilesDir.setAutoRemove(false);
+}
+
+void DownloadTask::setUseLocalUpdater(bool useLocal)
+{
+ m_keepLocalUpdater = useLocal;
+}
+
+void DownloadTask::executeTask()
+{
+ loadVersionInfo();
+}
+
+void DownloadTask::loadVersionInfo()
+{
+ setStatus(tr("Loading version information..."));
+
+ m_currentVersionFileListDownload.reset();
+ m_newVersionFileListDownload.reset();
+
+ NetJob *netJob = new NetJob("Version Info");
+
+ // Find the index URL.
+ QUrl newIndexUrl = QUrl(m_status.newRepoUrl).resolved(QString::number(m_status.newVersionId) + ".json");
+ qDebug() << m_status.newRepoUrl << " turns into " << newIndexUrl;
+
+ netJob->addNetAction(m_newVersionFileListDownload = ByteArrayDownload::make(newIndexUrl));
+
+ // If we have a current version URL, get that one too.
+ if (!m_status.currentRepoUrl.isEmpty())
+ {
+ QUrl cIndexUrl = QUrl(m_status.currentRepoUrl).resolved(QString::number(m_status.currentVersionId) + ".json");
+ netJob->addNetAction(m_currentVersionFileListDownload = ByteArrayDownload::make(cIndexUrl));
+ qDebug() << m_status.currentRepoUrl << " turns into " << cIndexUrl;
+ }
+
+ // connect signals and start the job
+ connect(netJob, &NetJob::succeeded, this, &DownloadTask::processDownloadedVersionInfo);
+ connect(netJob, &NetJob::failed, this, &DownloadTask::vinfoDownloadFailed);
+ m_vinfoNetJob.reset(netJob);
+ netJob->start();
+}
+
+void DownloadTask::vinfoDownloadFailed()
+{
+ // Something failed. We really need the second download (current version info), so parse
+ // downloads anyways as long as the first one succeeded.
+ if (m_newVersionFileListDownload->m_status != Job_Failed)
+ {
+ processDownloadedVersionInfo();
+ return;
+ }
+
+ // TODO: Give a more detailed error message.
+ qCritical() << "Failed to download version info files.";
+ emitFailed(tr("Failed to download version info files."));
+}
+
+void DownloadTask::processDownloadedVersionInfo()
+{
+ VersionFileList m_currentVersionFileList;
+ VersionFileList m_newVersionFileList;
+ OperationList operationList;
+
+ setStatus(tr("Reading file list for new version..."));
+ qDebug() << "Reading file list for new version...";
+ QString error;
+ if (!parseVersionInfo(m_newVersionFileListDownload->m_data, m_newVersionFileList, error))
+ {
+ qCritical() << error;
+ emitFailed(error);
+ return;
+ }
+
+ // if we have the current version info, use it.
+ if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->m_status != Job_Failed)
+ {
+ setStatus(tr("Reading file list for current version..."));
+ qDebug() << "Reading file list for current version...";
+ // if this fails, it's not a complete loss.
+ QString error;
+ if(!parseVersionInfo( m_currentVersionFileListDownload->m_data, m_currentVersionFileList, error))
+ {
+ qDebug() << error << "This is not a fatal error.";
+ }
+ }
+
+ // We don't need this any more.
+ m_currentVersionFileListDownload.reset();
+ m_newVersionFileListDownload.reset();
+ m_vinfoNetJob.reset();
+
+ setStatus(tr("Processing file lists - figuring out how to install the update..."));
+
+ // make a new netjob for the actual update files
+ NetJobPtr netJob (new NetJob("Update Files"));
+
+ // fill netJob and operationList
+ if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, operationList, m_keepLocalUpdater))
+ {
+ emitFailed(tr("Failed to process update lists..."));
+ return;
+ }
+
+ // write the instruction file for the file swapper
+ if(!writeInstallScript(operationList, PathCombine(m_updateFilesDir.path(), "file_list.xml")))
+ {
+ emitFailed(tr("Failed to write update script file."));
+ return;
+ }
+
+ // Now start the download.
+ QObject::connect(netJob.get(), &NetJob::succeeded, this, &DownloadTask::fileDownloadFinished);
+ QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged);
+ QObject::connect(netJob.get(), &NetJob::failed, this, &DownloadTask::fileDownloadFailed);
+
+ setStatus(tr("Downloading %1 update files.").arg(QString::number(netJob->size())));
+ qDebug() << "Begin downloading update files to" << m_updateFilesDir.path();
+ m_filesNetJob = netJob;
+ m_filesNetJob->start();
+}
+
+void DownloadTask::fileDownloadFinished()
+{
+ emitSucceeded();
+}
+
+void DownloadTask::fileDownloadFailed()
+{
+ // TODO: Give more info about the failure.
+ qCritical() << "Failed to download update files.";
+ emitFailed(tr("Failed to download update files."));
+}
+
+void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total)
+{
+ setProgress((int)(((float)current / (float)total) * 100));
+}
+
+QString DownloadTask::updateFilesDir()
+{
+ return m_updateFilesDir.path();
+}
+
+} \ No newline at end of file
diff --git a/logic/updater/DownloadTask.h b/logic/updater/DownloadTask.h
new file mode 100644
index 00000000..2b8c6299
--- /dev/null
+++ b/logic/updater/DownloadTask.h
@@ -0,0 +1,85 @@
+/* Copyright 2013-2014 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "logic/tasks/Task.h"
+#include "logic/net/NetJob.h"
+#include "GoUpdate.h"
+
+namespace GoUpdate
+{
+/*!
+ * The DownloadTask is a task that takes a given version ID and repository URL,
+ * downloads that version's files from the repository, and prepares to install them.
+ */
+class DownloadTask : public Task
+{
+ Q_OBJECT
+
+public:
+ explicit DownloadTask(Status status, QObject* parent = 0);
+
+ /// Get the directory that will contain the update files.
+ QString updateFilesDir();
+
+ /// set updater download behavior
+ void setUseLocalUpdater(bool useLocal);
+
+protected:
+ //! Entry point for tasks.
+ virtual void executeTask() override;
+
+ /*!
+ * Downloads the version info files from the repository.
+ * The files for both the current build, and the build that we're updating to need to be downloaded.
+ * If the current version's info file can't be found, MultiMC will not delete files that
+ * were removed between versions. It will still replace files that have changed, however.
+ * Note that although the repository URL for the current version is not given to the update task,
+ * the task will attempt to look it up in the UpdateChecker's channel list.
+ * If an error occurs here, the function will call emitFailed and return false.
+ */
+ void loadVersionInfo();
+
+ NetJobPtr m_vinfoNetJob;
+ ByteArrayDownloadPtr m_currentVersionFileListDownload;
+ ByteArrayDownloadPtr m_newVersionFileListDownload;
+
+ NetJobPtr m_filesNetJob;
+
+ Status m_status;
+
+ bool m_keepLocalUpdater;
+
+ /*!
+ * Temporary directory to store update files in.
+ * This will be set to not auto delete. Task will fail if this fails to be created.
+ */
+ QTemporaryDir m_updateFilesDir;
+
+protected slots:
+ /*!
+ * This function is called when version information is finished downloading
+ * and at least the new file list download succeeded
+ */
+ void processDownloadedVersionInfo();
+ void vinfoDownloadFailed();
+
+ void fileDownloadFinished();
+ void fileDownloadFailed();
+ void fileDownloadProgressChanged(qint64 current, qint64 total);
+};
+
+} \ No newline at end of file
diff --git a/logic/updater/DownloadUpdateTask.cpp b/logic/updater/DownloadUpdateTask.cpp
deleted file mode 100644
index 228d26d2..00000000
--- a/logic/updater/DownloadUpdateTask.cpp
+++ /dev/null
@@ -1,549 +0,0 @@
-/* Copyright 2013-2015 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "DownloadUpdateTask.h"
-
-#include "MultiMC.h"
-#include "logic/Env.h"
-#include "BuildConfig.h"
-
-#include "logic/updater/UpdateChecker.h"
-#include "logic/net/NetJob.h"
-#include "pathutils.h"
-
-#include <QFile>
-#include <QTemporaryDir>
-#include <QCryptographicHash>
-
-#include <QDomDocument>
-
-DownloadUpdateTask::DownloadUpdateTask(QString rootPath, QString repoUrl, int versionId, QObject *parent)
- : Task(parent)
-{
- m_cVersionId = BuildConfig.VERSION_BUILD;
- m_rootPath = rootPath;
-
- m_nRepoUrl = repoUrl;
- m_nVersionId = versionId;
-
- m_updateFilesDir.setAutoRemove(false);
-}
-
-void DownloadUpdateTask::executeTask()
-{
- // GO!
- // This will call the next step when it's done.
- findCurrentVersionInfo();
-}
-
-void DownloadUpdateTask::processChannels()
-{
- auto checker = MMC->updateChecker();
-
- // Now, check the channel list again.
- if (!checker->hasChannels())
- {
- // We still couldn't load the channel list. Give up. Call loadVersionInfo and return.
- qDebug() << "Reloading the channel list didn't work. Giving up.";
- loadVersionInfo();
- return;
- }
-
- QList<UpdateChecker::ChannelListEntry> channels = checker->getChannelList();
- QString channelId = BuildConfig.VERSION_CHANNEL;
-
- m_cRepoUrl.clear();
- // Search through the channel list for a channel with the correct ID.
- for (auto channel : channels)
- {
- if (channel.id == channelId)
- {
- qDebug() << "Found matching channel.";
- m_cRepoUrl = channel.url;
- break;
- }
- }
-
- // Now that we've done that, load version info.
- loadVersionInfo();
-}
-
-void DownloadUpdateTask::findCurrentVersionInfo()
-{
- setStatus(tr("Finding information about the current version..."));
-
- auto checker = MMC->updateChecker();
-
- if (!checker->hasChannels())
- {
- // Load the channel list and wait for it to finish loading.
- qDebug() << "No channel list entries found. Will try reloading it.";
-
- QObject::connect(checker.get(), &UpdateChecker::channelListLoaded, this,
- &DownloadUpdateTask::processChannels);
- checker->updateChanList(false);
- }
- else
- {
- processChannels();
- }
-}
-
-void DownloadUpdateTask::loadVersionInfo()
-{
- setStatus(tr("Loading version information..."));
-
- // Create the net job for loading version info.
- NetJob *netJob = new NetJob("Version Info");
-
- // Find the index URL.
- QUrl newIndexUrl = QUrl(m_nRepoUrl).resolved(QString::number(m_nVersionId) + ".json");
- qDebug() << m_nRepoUrl << " turns into " << newIndexUrl;
-
- // Add a net action to download the version info for the version we're updating to.
- netJob->addNetAction(ByteArrayDownload::make(newIndexUrl));
-
- // If we have a current version URL, get that one too.
- if (!m_cRepoUrl.isEmpty())
- {
- QUrl cIndexUrl = QUrl(m_cRepoUrl).resolved(QString::number(m_cVersionId) + ".json");
- netJob->addNetAction(ByteArrayDownload::make(cIndexUrl));
- qDebug() << m_cRepoUrl << " turns into " << cIndexUrl;
- }
-
- // Connect slots so we know when it's done.
- QObject::connect(netJob, &NetJob::succeeded, this,
- &DownloadUpdateTask::vinfoDownloadFinished);
- QObject::connect(netJob, &NetJob::failed, this, &DownloadUpdateTask::vinfoDownloadFailed);
-
- // Store the NetJob in a class member. We don't want to lose it!
- m_vinfoNetJob.reset(netJob);
-
- // Finally, we start the n