summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-12-02 00:55:24 +0100
committerPetr Mrázek <peterix@gmail.com>2013-12-02 00:55:24 +0100
commit6aa9bd0f77dcb5128167fae62e32aa5252fe85c6 (patch)
tree632994a61888929af9289927d338bd19a2b3f32c /logic
parent613699b3626aea750093ab7eaaeccaa28c0e87c6 (diff)
downloadMultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar.gz
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar.lz
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.tar.xz
MultiMC-6aa9bd0f77dcb5128167fae62e32aa5252fe85c6.zip
Renew the updater branch
Now with some actual consensus on what the updater will do!
Diffstat (limited to 'logic')
-rw-r--r--logic/GoUpdate.cpp99
-rw-r--r--logic/GoUpdate.h43
2 files changed, 142 insertions, 0 deletions
diff --git a/logic/GoUpdate.cpp b/logic/GoUpdate.cpp
new file mode 100644
index 00000000..6ac53d19
--- /dev/null
+++ b/logic/GoUpdate.cpp
@@ -0,0 +1,99 @@
+
+#include "GoUpdate.h"
+
+#include "config.h"
+#include "logger/QsLog.h"
+
+GoUpdate::GoUpdate()
+{
+ currentBuildIndex = VERSION_BUILD;
+ builderName = VERSION_BUILD_TYPE;
+ repoUrlBase = VERSION_REPO;
+}
+
+void GoUpdate::updateCheckFailed()
+{
+ // TODO: log errors better
+ QLOG_ERROR() << "Update check failed for reasons unknown.";
+}
+
+void GoUpdate::updateCheckFinished()
+{
+ QJsonParseError jsonError;
+ QByteArray data;
+ {
+ ByteArrayDownloadPtr dl =
+ std::dynamic_pointer_cast<ByteArrayDownload>(index_job->first());
+ data = dl->m_data;
+ index_job.reset();
+ }
+
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
+ if (jsonError.error != QJsonParseError::NoError || !jsonDoc.isObject())
+ {
+ return;
+ }
+
+ QVariant doc = jsonDoc.toVariant();
+ auto stuff = doc.toMap();
+
+ // check api version (or later, branch?)
+ int ApiVersion = stuff["ApiVersion"].toInt();
+ if (ApiVersion != 0)
+ return;
+
+ // parse and store the channel list
+ auto parsedChannels = stuff["Channels"].toList();
+ for (auto channel : parsedChannels)
+ {
+ auto chanMap = channel.toMap();
+ channels.append({chanMap["Id"].toString(), chanMap["Name"].toString(),
+ chanMap["CurrentVersion"].toInt()});
+ }
+
+ // parse and store the version list
+ auto parsedVersions = stuff["Versions"].toList();
+ for (auto version : parsedVersions)
+ {
+ auto verMap = version.toMap();
+ int versionId = verMap["Id"].toInt();
+ versions.append({versionId, verMap["Name"].toString()});
+ if (currentBuildIndex < versionId)
+ {
+ newBuildIndex = versionId;
+ }
+ }
+
+ if (newBuildIndex != -1)
+ {
+ QLOG_INFO() << "Update is available.";
+ emit updateAvailable();
+ }
+ else
+ {
+ QLOG_INFO() << "Update check finished.";
+ }
+}
+
+void GoUpdate::checkForUpdate()
+{
+ if (repoUrlBase == "invalid")
+ {
+ return;
+ }
+
+ auto job = new NetJob("Assets index");
+ job->addNetAction(
+ ByteArrayDownload::make(QUrl(repoUrlBase + "/" + VERSION_BRANCH + "/index.json")));
+ connect(job, SIGNAL(succeeded()), SLOT(updateCheckFinished()));
+ connect(job, SIGNAL(failed()), SLOT(updateCheckFailed()));
+ index_job.reset(job);
+ job->start();
+}
+
+/*
+<Forkk> files.multimc.org/lin64/
+<manmaed> Hi Forkkie
+<Forkk> files.multimc.org/win32/
+<Forkk> files.multimc.org/lin32/
+*/
diff --git a/logic/GoUpdate.h b/logic/GoUpdate.h
new file mode 100644
index 00000000..756a71cf
--- /dev/null
+++ b/logic/GoUpdate.h
@@ -0,0 +1,43 @@
+#pragma once
+#include "net/NetJob.h"
+
+class GoUpdate : public QObject
+{
+ Q_OBJECT
+
+public:
+ struct version_channel
+ {
+ QString id;
+ QString name;
+ int latestVersion;
+ };
+
+ struct version_summary
+ {
+ int id;
+ QString name;
+ };
+
+signals:
+ void updateAvailable();
+
+private slots:
+ void updateCheckFinished();
+ void updateCheckFailed();
+
+public:
+ GoUpdate();
+ void checkForUpdate();
+private:
+ NetJobPtr index_job;
+ NetJobPtr fromto_job;
+
+ QString repoUrlBase;
+ QString builderName;
+ int currentBuildIndex;
+ int newBuildIndex = -1;
+
+ QList<version_summary> versions;
+ QList<version_channel> channels;
+};