summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-12-25 01:19:38 +0100
committerPetr Mrázek <peterix@gmail.com>2013-12-25 01:19:38 +0100
commit5a2df0d41a1570fcb9b36de2ae654415bee1d209 (patch)
treeda14620780a5d9b5b6b013b27ca40913cdc3803f
parent2d144631e7b6fd608d9a1f9cb966ce3e68fe95a0 (diff)
parentb1ec7841e04f2a60f54895e1646bc33486fd9fbf (diff)
downloadMultiMC-5a2df0d41a1570fcb9b36de2ae654415bee1d209.tar
MultiMC-5a2df0d41a1570fcb9b36de2ae654415bee1d209.tar.gz
MultiMC-5a2df0d41a1570fcb9b36de2ae654415bee1d209.tar.lz
MultiMC-5a2df0d41a1570fcb9b36de2ae654415bee1d209.tar.xz
MultiMC-5a2df0d41a1570fcb9b36de2ae654415bee1d209.zip
Merge branch 'develop' of https://github.com/robotbrain/MultiMC5 into develop
-rw-r--r--gui/MainWindow.cpp5
-rw-r--r--logic/updater/UpdateChecker.cpp71
-rw-r--r--logic/updater/UpdateChecker.h6
-rw-r--r--tests/tst_UpdateChecker.cpp2
4 files changed, 53 insertions, 31 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 4fb4489f..006f5b8e 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -681,7 +681,10 @@ void MainWindow::on_actionConfig_Folder_triggered()
void MainWindow::on_actionCheckUpdate_triggered()
{
auto updater = MMC->updateChecker();
- updater->checkForUpdate();
+ connect(updater.get(), &UpdateChecker::noUpdateFound, [this](){
+ CustomMessageBox::selectable(this, "No update found.", "No MultiMC update was found!\nYou are using the latest version.")->exec();
+ });
+ updater->checkForUpdate(true);
}
void MainWindow::on_actionSettings_triggered()
diff --git a/logic/updater/UpdateChecker.cpp b/logic/updater/UpdateChecker.cpp
index af56288c..d0795c0d 100644
--- a/logic/updater/UpdateChecker.cpp
+++ b/logic/updater/UpdateChecker.cpp
@@ -47,14 +47,16 @@ bool UpdateChecker::hasChannels() const
return !m_channels.isEmpty();
}
-void UpdateChecker::checkForUpdate()
+void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
{
QLOG_DEBUG() << "Checking for updates.";
- // If the channel list hasn't loaded yet, load it and defer checking for updates until later.
+ // If the channel list hasn't loaded yet, load it and defer checking for updates until
+ // later.
if (!m_chanListLoaded)
{
- QLOG_DEBUG() << "Channel list isn't loaded yet. Loading channel list and deferring update check.";
+ QLOG_DEBUG() << "Channel list isn't loaded yet. Loading channel list and deferring "
+ "update check.";
m_checkUpdateWaiting = true;
updateChanList();
return;
@@ -72,7 +74,8 @@ void UpdateChecker::checkForUpdate()
// TODO: Allow user to select channels. For now, we'll just use the current channel.
QString updateChannel = m_currentChannel;
- // Find the desired channel within the channel list and get its repo URL. If if cannot be found, error.
+ // Find the desired channel within the channel list and get its repo URL. If if cannot be
+ // found, error.
m_repoUrl = "";
for (ChannelListEntry entry : m_channels)
{
@@ -91,20 +94,22 @@ void UpdateChecker::checkForUpdate()
auto job = new NetJob("GoUpdate Repository Index");
job->addNetAction(ByteArrayDownload::make(indexUrl));
- connect(job, SIGNAL(succeeded()), SLOT(updateCheckFinished()));
+ connect(job, &NetJob::succeeded, [this, notifyNoUpdate]()
+ { updateCheckFinished(notifyNoUpdate); });
connect(job, SIGNAL(failed()), SLOT(updateCheckFailed()));
indexJob.reset(job);
job->start();
}
-void UpdateChecker::updateCheckFinished()
+void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
{
QLOG_DEBUG() << "Finished downloading repo index. Checking for new versions.";
QJsonParseError jsonError;
QByteArray data;
{
- ByteArrayDownloadPtr dl = std::dynamic_pointer_cast<ByteArrayDownload>(indexJob->first());
+ ByteArrayDownloadPtr dl =
+ std::dynamic_pointer_cast<ByteArrayDownload>(indexJob->first());
data = dl->m_data;
indexJob.reset();
}
@@ -112,7 +117,8 @@ void UpdateChecker::updateCheckFinished()
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
if (jsonError.error != QJsonParseError::NoError || !jsonDoc.isObject())
{
- QLOG_ERROR() << "Failed to parse GoUpdate repository index. JSON error" << jsonError.errorString() << "at offset" << jsonError.offset;
+ QLOG_ERROR() << "Failed to parse GoUpdate repository index. JSON error"
+ << jsonError.errorString() << "at offset" << jsonError.offset;
return;
}
@@ -122,7 +128,8 @@ void UpdateChecker::updateCheckFinished()
int apiVersion = object.value("ApiVersion").toVariant().toInt(&success);
if (apiVersion != API_VERSION || !success)
{
- QLOG_ERROR() << "Failed to check for updates. API version mismatch. We're using" << API_VERSION << "server has" << apiVersion;
+ QLOG_ERROR() << "Failed to check for updates. API version mismatch. We're using"
+ << API_VERSION << "server has" << apiVersion;
return;
}
@@ -132,19 +139,27 @@ void UpdateChecker::updateCheckFinished()
for (QJsonValue versionVal : versions)
{
QJsonObject version = versionVal.toObject();
- if (newestVersion.value("Id").toVariant().toInt() < version.value("Id").toVariant().toInt())
+ if (newestVersion.value("Id").toVariant().toInt() <
+ version.value("Id").toVariant().toInt())
{
- QLOG_DEBUG() << "Found newer version with ID" << version.value("Id").toVariant().toInt();
+ QLOG_DEBUG() << "Found newer version with ID"
+ << version.value("Id").toVariant().toInt();
newestVersion = version;
}
}
- // We've got the version with the greatest ID number. Now compare it to our current build number and update if they're different.
+ // 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 != MMC->version().build)
{
// Update!
- emit updateAvailable(m_repoUrl, newestVersion.value("Name").toVariant().toString(), newBuildNumber);
+ emit updateAvailable(m_repoUrl, newestVersion.value("Name").toVariant().toString(),
+ newBuildNumber);
+ }
+ else if (notifyNoUpdate)
+ {
+ emit noUpdateFound();
}
m_updateChecking = false;
@@ -163,12 +178,13 @@ void UpdateChecker::updateChanList()
if (m_channelListUrl.isEmpty())
{
QLOG_ERROR() << "Failed to update channel list. No channel list URL set."
- << "If you'd like to use MultiMC's update system, please pass the channel list URL to CMake at compile time.";
+ << "If you'd like to use MultiMC's update system, please pass the channel "
+ "list URL to CMake at compile time.";
return;
}
m_chanListLoading = true;
- NetJob* job = new NetJob("Update System Channel List");
+ NetJob *job = new NetJob("Update System Channel List");
job->addNetAction(ByteArrayDownload::make(QUrl(m_channelListUrl)));
QObject::connect(job, &NetJob::succeeded, this, &UpdateChecker::chanListDownloadFinished);
QObject::connect(job, &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed);
@@ -180,7 +196,8 @@ void UpdateChecker::chanListDownloadFinished()
{
QByteArray data;
{
- ByteArrayDownloadPtr dl = std::dynamic_pointer_cast<ByteArrayDownload>(chanListJob->first());
+ ByteArrayDownloadPtr dl =
+ std::dynamic_pointer_cast<ByteArrayDownload>(chanListJob->first());
data = dl->m_data;
chanListJob.reset();
}
@@ -190,17 +207,20 @@ void UpdateChecker::chanListDownloadFinished()
if (jsonError.error != QJsonParseError::NoError)
{
// TODO: Report errors to the user.
- QLOG_ERROR() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at" << jsonError.offset;
+ QLOG_ERROR() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at"
+ << jsonError.offset;
return;
}
-
+
QJsonObject object = jsonDoc.object();
bool success = false;
int formatVersion = object.value("format_version").toVariant().toInt(&success);
if (formatVersion != CHANLIST_FORMAT || !success)
{
- QLOG_ERROR() << "Failed to check for updates. Channel list format version mismatch. We're using" << CHANLIST_FORMAT << "server has" << formatVersion;
+ QLOG_ERROR()
+ << "Failed to check for updates. Channel list format version mismatch. We're using"
+ << CHANLIST_FORMAT << "server has" << formatVersion;
return;
}
@@ -210,12 +230,10 @@ void UpdateChecker::chanListDownloadFinished()
for (QJsonValue chanVal : channelArray)
{
QJsonObject channelObj = chanVal.toObject();
- ChannelListEntry entry{
- channelObj.value("id").toVariant().toString(),
- channelObj.value("name").toVariant().toString(),
- channelObj.value("description").toVariant().toString(),
- channelObj.value("url").toVariant().toString()
- };
+ ChannelListEntry entry{channelObj.value("id").toVariant().toString(),
+ channelObj.value("name").toVariant().toString(),
+ channelObj.value("description").toVariant().toString(),
+ channelObj.value("url").toVariant().toString()};
if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty())
{
QLOG_ERROR() << "Channel list entry with empty ID, name, or URL. Skipping.";
@@ -233,7 +251,7 @@ void UpdateChecker::chanListDownloadFinished()
// If we're waiting to check for updates, do that now.
if (m_checkUpdateWaiting)
- checkForUpdate();
+ checkForUpdate(false);
emit channelListLoaded();
}
@@ -244,4 +262,3 @@ void UpdateChecker::chanListDownloadFailed()
QLOG_ERROR() << "Failed to download channel list.";
emit channelListLoaded();
}
-
diff --git a/logic/updater/UpdateChecker.h b/logic/updater/UpdateChecker.h
index 5b7efc05..a47e8903 100644
--- a/logic/updater/UpdateChecker.h
+++ b/logic/updater/UpdateChecker.h
@@ -25,7 +25,7 @@ class UpdateChecker : public QObject
public:
UpdateChecker();
- void checkForUpdate();
+ void checkForUpdate(bool notifyNoUpdate);
void setCurrentChannel(const QString &channel) { m_currentChannel = channel; }
void setChannelListUrl(const QString &url) { m_channelListUrl = url; }
@@ -65,8 +65,10 @@ signals:
//! Signal emitted when the channel list finishes loading or fails to load.
void channelListLoaded();
+ void noUpdateFound();
+
private slots:
- void updateCheckFinished();
+ void updateCheckFinished(bool notifyNoUpdate);
void updateCheckFailed();
void chanListDownloadFinished();
diff --git a/tests/tst_UpdateChecker.cpp b/tests/tst_UpdateChecker.cpp
index af3ae802..162d0009 100644
--- a/tests/tst_UpdateChecker.cpp
+++ b/tests/tst_UpdateChecker.cpp
@@ -149,7 +149,7 @@ slots:
checker.m_channels[0].url = QUrl::fromLocalFile(QDir::current().absoluteFilePath("tests/data/")).toString();
- checker.checkForUpdate();
+ checker.checkForUpdate(false);
QVERIFY(updateAvailableSpy.wait());
QList<QVariant> res = result;