From 9249768db5f5b09d67e81370da828e3cb99cc3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 31 Jan 2015 19:21:47 +0100 Subject: NOISSUE Make tests no longer use the MultiMC object They do not require the application part anymore --- logic/Env.cpp | 17 +++++++++++++++-- logic/Env.h | 12 +++--------- logic/updater/UpdateChecker.cpp | 41 +++++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 31 deletions(-) (limited to 'logic') diff --git a/logic/Env.cpp b/logic/Env.cpp index de93ded3..daf17d65 100644 --- a/logic/Env.cpp +++ b/logic/Env.cpp @@ -4,11 +4,12 @@ #include #include #include "logger/QsLog.h" -#include "MultiMC.h" + +#include Env::Env() { - // null + m_qnam = std::make_shared(); } void Env::destroy() @@ -23,6 +24,18 @@ Env& Env::Env::getInstance() return instance; } +std::shared_ptr< HttpMetaCache > Env::metacache() +{ + Q_ASSERT(m_metacache != nullptr); + return m_metacache; +} + +std::shared_ptr< QNetworkAccessManager > Env::qnam() +{ + return m_qnam; +} + + void Env::initHttpMetaCache(QString rootPath, QString staticDataPath) { m_metacache.reset(new HttpMetaCache("metacache")); diff --git a/logic/Env.h b/logic/Env.h index 523c51f0..3d560a29 100644 --- a/logic/Env.h +++ b/logic/Env.h @@ -22,15 +22,9 @@ public: // call when Qt stuff is being torn down void destroy(); - std::shared_ptr qnam() - { - return m_qnam; - } - - std::shared_ptr metacache() - { - return m_metacache; - } + std::shared_ptr qnam(); + + std::shared_ptr metacache(); /// init the cache. FIXME: possible future hook point void initHttpMetaCache(QString rootPath, QString staticDataPath); diff --git a/logic/updater/UpdateChecker.cpp b/logic/updater/UpdateChecker.cpp index cd0b3c72..8ac84bf1 100644 --- a/logic/updater/UpdateChecker.cpp +++ b/logic/updater/UpdateChecker.cpp @@ -15,11 +15,10 @@ #include "UpdateChecker.h" -#include "logger/QsLog.h" - #include #include #include +#include #define API_VERSION 0 #define CHANLIST_FORMAT 0 @@ -46,13 +45,13 @@ bool UpdateChecker::hasChannels() const void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) { - QLOG_DEBUG() << "Checking for updates."; + qDebug() << "Checking for updates."; // 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 " + qDebug() << "Channel list isn't loaded yet. Loading channel list and deferring " "update check."; m_checkUpdateWaiting = true; m_deferredUpdateChannel = updateChannel; @@ -62,7 +61,7 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) if (m_updateChecking) { - QLOG_DEBUG() << "Ignoring update check request. Already checking for updates."; + qDebug() << "Ignoring update check request. Already checking for updates."; return; } @@ -77,9 +76,12 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) m_repoUrl = entry.url; } + qDebug() << "m_repoUrl = " << m_repoUrl; + // If we didn't find our channel, error. if (m_repoUrl.isEmpty()) { + qCritical() << "m_repoUrl is empty!"; emit updateCheckFailed(); return; } @@ -97,7 +99,7 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) { - QLOG_DEBUG() << "Finished downloading repo index. Checking for new versions."; + qDebug() << "Finished downloading repo index. Checking for new versions."; QJsonParseError jsonError; QByteArray data; @@ -111,7 +113,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); if (jsonError.error != QJsonParseError::NoError || !jsonDoc.isObject()) { - QLOG_ERROR() << "Failed to parse GoUpdate repository index. JSON error" + qCritical() << "Failed to parse GoUpdate repository index. JSON error" << jsonError.errorString() << "at offset" << jsonError.offset; return; } @@ -122,12 +124,12 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) 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" + qCritical() << "Failed to check for updates. API version mismatch. We're using" << API_VERSION << "server has" << apiVersion; return; } - QLOG_DEBUG() << "Processing repository version list."; + qDebug() << "Processing repository version list."; QJsonObject newestVersion; QJsonArray versions = object.value("Versions").toArray(); for (QJsonValue versionVal : versions) @@ -145,7 +147,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) int newBuildNumber = newestVersion.value("Id").toVariant().toInt(); if (newBuildNumber != m_currentBuild) { - QLOG_DEBUG() << "Found newer version with ID" << newBuildNumber; + qDebug() << "Found newer version with ID" << newBuildNumber; // Update! emit updateAvailable(m_repoUrl, newestVersion.value("Name").toVariant().toString(), newBuildNumber); @@ -160,18 +162,17 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) void UpdateChecker::updateCheckFailed() { - // TODO: log errors better - QLOG_ERROR() << "Update check failed for reasons unknown."; + qCritical() << "Update check failed for reasons unknown."; } void UpdateChecker::updateChanList(bool notifyNoUpdate) { - QLOG_DEBUG() << "Loading the channel list."; + qDebug() << "Loading the channel list."; 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 " + qCritical() << "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."; return; } @@ -201,7 +202,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) if (jsonError.error != QJsonParseError::NoError) { // TODO: Report errors to the user. - QLOG_ERROR() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at" + qCritical() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at" << jsonError.offset; return; } @@ -212,7 +213,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) int formatVersion = object.value("format_version").toVariant().toInt(&success); if (formatVersion != CHANLIST_FORMAT || !success) { - QLOG_ERROR() + qCritical() << "Failed to check for updates. Channel list format version mismatch. We're using" << CHANLIST_FORMAT << "server has" << formatVersion; return; @@ -230,7 +231,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) 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."; + qCritical() << "Channel list entry with empty ID, name, or URL. Skipping."; continue; } loadedChannels.append(entry); @@ -241,7 +242,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) m_chanListLoading = false; m_chanListLoaded = true; - QLOG_INFO() << "Successfully loaded UpdateChecker channel list."; + qDebug() << "Successfully loaded UpdateChecker channel list."; // If we're waiting to check for updates, do that now. if (m_checkUpdateWaiting) @@ -253,7 +254,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) void UpdateChecker::chanListDownloadFailed() { m_chanListLoading = false; - QLOG_ERROR() << "Failed to download channel list."; + qCritical() << "Failed to download channel list."; emit channelListLoaded(); } -- cgit v1.2.3