summaryrefslogtreecommitdiffstats
path: root/logic/updater
diff options
context:
space:
mode:
Diffstat (limited to 'logic/updater')
-rw-r--r--logic/updater/DownloadUpdateTask.cpp11
-rw-r--r--logic/updater/DownloadUpdateTask.h17
-rw-r--r--logic/updater/NotificationChecker.cpp5
-rw-r--r--logic/updater/UpdateChecker.cpp20
-rw-r--r--logic/updater/UpdateChecker.h12
5 files changed, 34 insertions, 31 deletions
diff --git a/logic/updater/DownloadUpdateTask.cpp b/logic/updater/DownloadUpdateTask.cpp
index 9d4c5bd8..af0cf0a8 100644
--- a/logic/updater/DownloadUpdateTask.cpp
+++ b/logic/updater/DownloadUpdateTask.cpp
@@ -16,6 +16,7 @@
#include "DownloadUpdateTask.h"
#include "MultiMC.h"
+#include "logic/Env.h"
#include "BuildConfig.h"
#include "logic/updater/UpdateChecker.h"
@@ -28,10 +29,11 @@
#include <QDomDocument>
-DownloadUpdateTask::DownloadUpdateTask(QString repoUrl, int versionId, QObject *parent)
+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;
@@ -293,7 +295,7 @@ DownloadUpdateTask::processFileLists(NetJob *job,
// delete anything in the current one version's list that isn't in the new version's list.
for (VersionFileEntry entry : currentVersion)
{
- QFileInfo toDelete(PathCombine(MMC->root(), entry.path));
+ QFileInfo toDelete(PathCombine(m_rootPath, entry.path));
if (!toDelete.exists())
{
QLOG_ERROR() << "Expected file " << toDelete.absoluteFilePath()
@@ -327,7 +329,7 @@ DownloadUpdateTask::processFileLists(NetJob *job,
// TODO: Let's not MD5sum a ton of files on the GUI thread. We should probably find a
// way to do this in the background.
QString fileMD5;
- QString realEntryPath = PathCombine(MMC->root(), entry.path);
+ QString realEntryPath = PathCombine(m_rootPath, entry.path);
QFile entryFile(realEntryPath);
QFileInfo entryInfo(realEntryPath);
@@ -356,7 +358,6 @@ DownloadUpdateTask::processFileLists(NetJob *job,
}
if (!pass)
{
- QLOG_ERROR() << "ROOT: " << MMC->root();
ops.clear();
return false;
}
@@ -413,7 +414,7 @@ DownloadUpdateTask::processFileLists(NetJob *job,
}
else
{
- auto cache_entry = MMC->metacache()->resolveEntry("root", entry.path);
+ auto cache_entry = ENV.metacache()->resolveEntry("root", entry.path);
QLOG_DEBUG() << "Updater will be in " << cache_entry->getFullPath();
// force check.
cache_entry->stale = true;
diff --git a/logic/updater/DownloadUpdateTask.h b/logic/updater/DownloadUpdateTask.h
index ecfa349b..9a994687 100644
--- a/logic/updater/DownloadUpdateTask.h
+++ b/logic/updater/DownloadUpdateTask.h
@@ -27,13 +27,13 @@ class DownloadUpdateTask : public Task
Q_OBJECT
public:
- explicit DownloadUpdateTask(QString repoUrl, int versionId, QObject* parent=0);
+ explicit DownloadUpdateTask(QString rootPath, QString repoUrl, int versionId, QObject* parent=0);
/*!
* Gets the directory that contains the update files.
*/
QString updateFilesDir();
-
+
public:
// TODO: We should probably put these data structures into a separate header...
@@ -130,7 +130,7 @@ protected:
/*!
* 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
+ * 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.
@@ -142,7 +142,7 @@ protected:
* This function is called when version information is finished downloading.
* This handles parsing the JSON downloaded by the version info network job and then calls processFileLists.
* Note that this function will sometimes be called even if the version info download emits failed. If
- * we couldn't download the current version's info file, we can still update. This will be called even if the
+ * we couldn't download the current version's info file, we can still update. This will be called even if the
* current version's info file fails to download, as long as the new version's info file succeeded.
*/
virtual void parseDownloadedVersionInfo();
@@ -176,7 +176,7 @@ protected:
//! Network job for downloading version info files.
NetJobPtr m_vinfoNetJob;
-
+
//! Network job for downloading update files.
NetJobPtr m_filesNetJob;
@@ -188,6 +188,9 @@ protected:
int m_cVersionId;
QString m_cRepoUrl;
+ // path to the root of the application
+ QString m_rootPath;
+
/*!
* Temporary directory to store update files in.
* This will be set to not auto delete. Task will fail if this fails to be created.
@@ -199,9 +202,9 @@ protected:
* This fixes destination paths for OSX.
* The updater runs in MultiMC.app/Contents/MacOs by default
* The destination paths are such as this: MultiMC.app/blah/blah
- *
+ *
* Therefore we chop off the 'MultiMC.app' prefix
- *
+ *
* Returns false if the path couldn't be fixed (is invalid)
*/
static bool fixPathForOSX(QString &path);
diff --git a/logic/updater/NotificationChecker.cpp b/logic/updater/NotificationChecker.cpp
index 5b458ddd..7a3f314b 100644
--- a/logic/updater/NotificationChecker.cpp
+++ b/logic/updater/NotificationChecker.cpp
@@ -4,9 +4,10 @@
#include <QJsonObject>
#include <QJsonArray>
-#include "MultiMC.h"
+#include "logic/Env.h"
#include "BuildConfig.h"
#include "logic/net/CacheDownload.h"
+#include "logger/QsLog.h"
NotificationChecker::NotificationChecker(QObject *parent)
: QObject(parent), m_notificationsUrl(QUrl(BuildConfig.NOTIFICATION_URL))
@@ -43,7 +44,7 @@ void NotificationChecker::checkForNotifications()
return;
}
m_checkJob.reset(new NetJob("Checking for notifications"));
- auto entry = MMC->metacache()->resolveEntry("root", "notifications.json");
+ auto entry = ENV.metacache()->resolveEntry("root", "notifications.json");
entry->stale = true;
m_checkJob->addNetAction(m_download = CacheDownload::make(m_notificationsUrl, entry));
connect(m_download.get(), &CacheDownload::succeeded, this,
diff --git a/logic/updater/UpdateChecker.cpp b/logic/updater/UpdateChecker.cpp
index c5cd2c2f..cd0b3c72 100644
--- a/logic/updater/UpdateChecker.cpp
+++ b/logic/updater/UpdateChecker.cpp
@@ -15,23 +15,19 @@
#include "UpdateChecker.h"
-#include "MultiMC.h"
-#include "BuildConfig.h"
-
#include "logger/QsLog.h"
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
-#include "logic/settings/SettingsObject.h"
-
#define API_VERSION 0
#define CHANLIST_FORMAT 0
-UpdateChecker::UpdateChecker()
+UpdateChecker::UpdateChecker(QString channelListUrl, int currentBuild)
{
- m_channelListUrl = BuildConfig.CHANLIST_URL;
+ m_channelListUrl = channelListUrl;
+ m_currentBuild = currentBuild;
m_updateChecking = false;
m_chanListLoading = false;
m_checkUpdateWaiting = false;
@@ -48,7 +44,7 @@ bool UpdateChecker::hasChannels() const
return !m_channels.isEmpty();
}
-void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
+void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
{
QLOG_DEBUG() << "Checking for updates.";
@@ -59,6 +55,7 @@ void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
QLOG_DEBUG() << "Channel list isn't loaded yet. Loading channel list and deferring "
"update check.";
m_checkUpdateWaiting = true;
+ m_deferredUpdateChannel = updateChannel;
updateChanList(notifyNoUpdate);
return;
}
@@ -71,9 +68,6 @@ void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
m_updateChecking = true;
- // Get the channel we're checking.
- QString updateChannel = MMC->settings()->get("UpdateChannel").toString();
-
// Find the desired channel within the channel list and get its repo URL. If if cannot be
// found, error.
m_repoUrl = "";
@@ -149,7 +143,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
// We've got the version with the greatest ID number. Now compare it to our current build
// number and update if they're different.
int newBuildNumber = newestVersion.value("Id").toVariant().toInt();
- if (newBuildNumber != BuildConfig.VERSION_BUILD)
+ if (newBuildNumber != m_currentBuild)
{
QLOG_DEBUG() << "Found newer version with ID" << newBuildNumber;
// Update!
@@ -251,7 +245,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
// If we're waiting to check for updates, do that now.
if (m_checkUpdateWaiting)
- checkForUpdate(notifyNoUpdate);
+ checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate);
emit channelListLoaded();
}
diff --git a/logic/updater/UpdateChecker.h b/logic/updater/UpdateChecker.h
index 7c49b6e0..2b08680a 100644
--- a/logic/updater/UpdateChecker.h
+++ b/logic/updater/UpdateChecker.h
@@ -24,10 +24,8 @@ class UpdateChecker : public QObject
Q_OBJECT
public:
- UpdateChecker();
- void checkForUpdate(bool notifyNoUpdate);
-
- void setChannelListUrl(const QString &url) { m_channelListUrl = url; }
+ UpdateChecker(QString channelListUrl, int currentBuild);
+ void checkForUpdate(QString updateChannel, bool notifyNoUpdate);
/*!
* Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake).
@@ -107,5 +105,11 @@ private:
* When the channel list finishes loading, if this is true, the update checker will check for updates.
*/
bool m_checkUpdateWaiting;
+
+ /*!
+ * if m_checkUpdateWaiting, this is the last used update channel
+ */
+ QString m_deferredUpdateChannel;
+ int m_currentBuild = -1;
};