summaryrefslogtreecommitdiffstats
path: root/logic/lists
diff options
context:
space:
mode:
Diffstat (limited to 'logic/lists')
-rw-r--r--logic/lists/MinecraftVersionList.cpp77
1 files changed, 38 insertions, 39 deletions
diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp
index fbf609b5..dd26714a 100644
--- a/logic/lists/MinecraftVersionList.cpp
+++ b/logic/lists/MinecraftVersionList.cpp
@@ -3,7 +3,7 @@
* 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
@@ -32,10 +32,8 @@
#define ASSETS_URLBASE "http://assets.minecraft.net/"
#define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
-MinecraftVersionList::MinecraftVersionList(QObject *parent) :
- BaseVersionList(parent)
+MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent)
{
-
}
Task *MinecraftVersionList::getLoadTask()
@@ -76,7 +74,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
{
for (int i = 0; i < m_vlist.length(); i++)
{
- auto ver =std::dynamic_pointer_cast<MinecraftVersion>(m_vlist.at(i));
+ auto ver = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist.at(i));
if (ver->is_latest && !ver->is_snapshot)
{
return m_vlist.at(i);
@@ -85,7 +83,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
return BaseVersionPtr();
}
-void MinecraftVersionList::updateListData(QList<BaseVersionPtr > versions)
+void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions)
{
beginResetModel();
m_vlist = versions;
@@ -109,7 +107,6 @@ inline QDateTime timeFromS3Time(QString str)
return QDateTime::fromString(str, Qt::ISODate);
}
-
MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
{
m_list = vlist;
@@ -151,91 +148,91 @@ void MCVListLoadTask::executeTask()
connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded()));
}
-
void MCVListLoadTask::list_downloaded()
{
- if(vlistReply->error() != QNetworkReply::NoError)
+ if (vlistReply->error() != QNetworkReply::NoError)
{
vlistReply->deleteLater();
emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString());
return;
}
-
+
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(vlistReply->readAll(), &jsonError);
vlistReply->deleteLater();
-
+
if (jsonError.error != QJsonParseError::NoError)
{
emitFailed("Error parsing version list JSON:" + jsonError.errorString());
return;
}
- if(!jsonDoc.isObject())
+ if (!jsonDoc.isObject())
{
emitFailed("Error parsing version list JSON: jsonDoc is not an object");
return;
}
-
+
QJsonObject root = jsonDoc.object();
-
+
// Get the ID of the latest release and the latest snapshot.
- if(!root.value("latest").isObject())
+ if (!root.value("latest").isObject())
{
emitFailed("Error parsing version list JSON: version list is missing 'latest' object");
return;
}
-
+
QJsonObject latest = root.value("latest").toObject();
-
+
QString latestReleaseID = latest.value("release").toString("");
QString latestSnapshotID = latest.value("snapshot").toString("");
- if(latestReleaseID.isEmpty())
+ if (latestReleaseID.isEmpty())
{
emitFailed("Error parsing version list JSON: latest release field is missing");
return;
}
- if(latestSnapshotID.isEmpty())
+ if (latestSnapshotID.isEmpty())
{
emitFailed("Error parsing version list JSON: latest snapshot field is missing");
return;
}
// Now, get the array of versions.
- if(!root.value("versions").isArray())
+ if (!root.value("versions").isArray())
{
- emitFailed("Error parsing version list JSON: version list object is missing 'versions' array");
+ emitFailed(
+ "Error parsing version list JSON: version list object is missing 'versions' array");
return;
}
QJsonArray versions = root.value("versions").toArray();
-
- QList<BaseVersionPtr > tempList;
+
+ QList<BaseVersionPtr> tempList;
for (int i = 0; i < versions.count(); i++)
{
bool is_snapshot = false;
bool is_latest = false;
-
+
// Load the version info.
- if(!versions[i].isObject())
+ if (!versions[i].isObject())
{
- //FIXME: log this somewhere
+ // FIXME: log this somewhere
continue;
}
QJsonObject version = versions[i].toObject();
QString versionID = version.value("id").toString("");
QString versionTimeStr = version.value("releaseTime").toString("");
QString versionTypeStr = version.value("type").toString("");
- if(versionID.isEmpty() || versionTimeStr.isEmpty() || versionTypeStr.isEmpty())
+ if (versionID.isEmpty() || versionTimeStr.isEmpty() || versionTypeStr.isEmpty())
{
- //FIXME: log this somewhere
+ // FIXME: log this somewhere
continue;
}
-
+
// Parse the timestamp.
QDateTime versionTime = timeFromS3Time(versionTimeStr);
- if(!versionTime.isValid())
+ if (!versionTime.isValid())
{
- //FIXME: log this somewhere
+ // FIXME: log this somewhere
continue;
}
// Parse the type.
@@ -243,23 +240,25 @@ void MCVListLoadTask::list_downloaded()
// OneSix or Legacy. use filter to determine type
if (versionTypeStr == "release")
{
- versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix;
+ versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy
+ : MinecraftVersion::OneSix;
is_latest = (versionID == latestReleaseID);
is_snapshot = false;
}
- else if(versionTypeStr == "snapshot") // It's a snapshot... yay
+ else if (versionTypeStr == "snapshot") // It's a snapshot... yay
{
- versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix;
+ versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy
+ : MinecraftVersion::OneSix;
is_latest = (versionID == latestSnapshotID);
is_snapshot = true;
}
- else if(versionTypeStr == "old_alpha")
+ else if (versionTypeStr == "old_alpha")
{
versionType = MinecraftVersion::Nostalgia;
is_latest = false;
is_snapshot = false;
}
- else if(versionTypeStr == "old_beta")
+ else if (versionTypeStr == "old_beta")
{
versionType = MinecraftVersion::Legacy;
is_latest = false;
@@ -267,12 +266,12 @@ void MCVListLoadTask::list_downloaded()
}
else
{
- //FIXME: log this somewhere
+ // FIXME: log this somewhere
continue;
}
// Get the download URL.
QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/";
-
+
// Now, we construct the version object and add it to the list.
std::shared_ptr<MinecraftVersion> mcVersion(new MinecraftVersion());
mcVersion->m_name = mcVersion->m_descriptor = versionID;
@@ -284,7 +283,7 @@ void MCVListLoadTask::list_downloaded()
tempList.append(mcVersion);
}
m_list->updateListData(tempList);
-
+
emitSucceeded();
return;
}