aboutsummaryrefslogtreecommitdiff
path: root/logic/lists
diff options
context:
space:
mode:
Diffstat (limited to 'logic/lists')
-rw-r--r--logic/lists/BaseVersionList.cpp (renamed from logic/lists/InstVersionList.cpp)36
-rw-r--r--logic/lists/BaseVersionList.h (renamed from logic/lists/InstVersionList.h)14
-rw-r--r--logic/lists/ForgeVersionList.cpp297
-rw-r--r--logic/lists/ForgeVersionList.h109
-rw-r--r--logic/lists/InstanceList.cpp218
-rw-r--r--logic/lists/JavaVersionList.cpp203
-rw-r--r--logic/lists/JavaVersionList.h93
-rw-r--r--logic/lists/LwjglVersionList.cpp70
-rw-r--r--logic/lists/LwjglVersionList.h8
-rw-r--r--logic/lists/MinecraftVersionList.cpp113
-rw-r--r--logic/lists/MinecraftVersionList.h23
11 files changed, 928 insertions, 256 deletions
diff --git a/logic/lists/InstVersionList.cpp b/logic/lists/BaseVersionList.cpp
index 7dc67155..61da5eeb 100644
--- a/logic/lists/InstVersionList.cpp
+++ b/logic/lists/BaseVersionList.cpp
@@ -13,33 +13,33 @@
* limitations under the License.
*/
-#include "logic/lists/InstVersionList.h"
-#include "logic/InstanceVersion.h"
+#include "logic/lists/BaseVersionList.h"
+#include "logic/BaseVersion.h"
-InstVersionList::InstVersionList(QObject *parent) :
+BaseVersionList::BaseVersionList(QObject *parent) :
QAbstractListModel(parent)
{
}
-InstVersionPtr InstVersionList::findVersion( const QString& descriptor )
+BaseVersionPtr BaseVersionList::findVersion( const QString& descriptor )
{
for (int i = 0; i < count(); i++)
{
- if (at(i)->descriptor == descriptor)
+ if (at(i)->descriptor() == descriptor)
return at(i);
}
- return InstVersionPtr();
+ return BaseVersionPtr();
}
-InstVersionPtr InstVersionList::getLatestStable() const
+BaseVersionPtr BaseVersionList::getLatestStable() const
{
if (count() <= 0)
- return InstVersionPtr();
+ return BaseVersionPtr();
else
return at(0);
}
-QVariant InstVersionList::data(const QModelIndex &index, int role) const
+QVariant BaseVersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
@@ -48,7 +48,7 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
return QVariant();
- InstVersionPtr version = at(index.row());
+ BaseVersionPtr version = at(index.row());
switch (role)
{
@@ -56,20 +56,17 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
switch (index.column())
{
case NameColumn:
- return version->name;
+ return version->name();
case TypeColumn:
return version->typeString();
- case TimeColumn:
- return version->timestamp;
-
default:
return QVariant();
}
case Qt::ToolTipRole:
- return version->descriptor;
+ return version->descriptor();
case VersionPointerRole:
return qVariantFromValue(version);
@@ -79,7 +76,7 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
}
}
-QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, int role) const
+QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, int role) const
{
switch (role)
{
@@ -91,9 +88,6 @@ QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, i
case TypeColumn:
return "Type";
-
- case TimeColumn:
- return "Time";
default:
return QVariant();
@@ -117,13 +111,13 @@ QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, i
}
}
-int InstVersionList::rowCount(const QModelIndex &parent) const
+int BaseVersionList::rowCount(const QModelIndex &parent) const
{
// Return count
return count();
}
-int InstVersionList::columnCount(const QModelIndex &parent) const
+int BaseVersionList::columnCount(const QModelIndex &parent) const
{
return 2;
}
diff --git a/logic/lists/InstVersionList.h b/logic/lists/BaseVersionList.h
index bc6aa5d4..d37431ed 100644
--- a/logic/lists/InstVersionList.h
+++ b/logic/lists/BaseVersionList.h
@@ -20,7 +20,7 @@
#include <QAbstractListModel>
#include <QSharedPointer>
-#include "logic/InstanceVersion.h"
+#include "logic/BaseVersion.h"
class Task;
@@ -36,7 +36,7 @@ class Task;
* all have a default implementation, but they can be overridden by plugins to
* change the behavior of the list.
*/
-class InstVersionList : public QAbstractListModel
+class BaseVersionList : public QAbstractListModel
{
Q_OBJECT
public:
@@ -57,7 +57,7 @@ public:
TimeColumn
};
- explicit InstVersionList(QObject *parent = 0);
+ explicit BaseVersionList(QObject *parent = 0);
/*!
* \brief Gets a task that will reload the version list.
@@ -71,7 +71,7 @@ public:
virtual bool isLoaded() = 0;
//! Gets the version at the given index.
- virtual const InstVersionPtr at(int i) const = 0;
+ virtual const BaseVersionPtr at(int i) const = 0;
//! Returns the number of versions in the list.
virtual int count() const = 0;
@@ -90,14 +90,14 @@ public:
* \return A const pointer to the version with the given descriptor. NULL if
* one doesn't exist.
*/
- virtual InstVersionPtr findVersion(const QString &descriptor);
+ virtual BaseVersionPtr findVersion(const QString &descriptor);
/*!
* \brief Gets the latest stable version of this instance type.
* This is the version that will be selected by default.
* By default, this is simply the first version in the list.
*/
- virtual InstVersionPtr getLatestStable() const;
+ virtual BaseVersionPtr getLatestStable() const;
/*!
* Sorts the version list.
@@ -117,5 +117,5 @@ protected slots:
* then copies the versions and sets their parents correctly.
* \param versions List of versions whose parents should be set.
*/
- virtual void updateListData(QList<InstVersionPtr > versions) = 0;
+ virtual void updateListData(QList<BaseVersionPtr > versions) = 0;
};
diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp
new file mode 100644
index 00000000..491a43d7
--- /dev/null
+++ b/logic/lists/ForgeVersionList.cpp
@@ -0,0 +1,297 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * 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
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ForgeVersionList.h"
+#include <logic/net/DownloadJob.h>
+#include "MultiMC.h"
+
+#include <QtNetwork>
+#include <QtXml>
+#include <QRegExp>
+
+#include <logger/QsLog.h>
+
+#define JSON_URL "http://files.minecraftforge.net/minecraftforge/json"
+
+ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent)
+{
+}
+
+Task *ForgeVersionList::getLoadTask()
+{
+ return new ForgeListLoadTask(this);
+}
+
+bool ForgeVersionList::isLoaded()
+{
+ return m_loaded;
+}
+
+const BaseVersionPtr ForgeVersionList::at(int i) const
+{
+ return m_vlist.at(i);
+}
+
+int ForgeVersionList::count() const
+{
+ return m_vlist.count();
+}
+
+int ForgeVersionList::columnCount(const QModelIndex &parent) const
+{
+ return 3;
+}
+
+QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() > count())
+ return QVariant();
+
+ auto version = std::dynamic_pointer_cast<ForgeVersion>(m_vlist[index.row()]);
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (index.column())
+ {
+ case 0:
+ return version->name();
+
+ case 1:
+ return version->mcver;
+
+ case 2:
+ return version->typeString();
+ default:
+ return QVariant();
+ }
+
+ case Qt::ToolTipRole:
+ return version->descriptor();
+
+ case VersionPointerRole:
+ return qVariantFromValue(m_vlist[index.row()]);
+
+ default:
+ return QVariant();
+ }
+}
+
+QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (section)
+ {
+ case 0:
+ return "Version";
+
+ case 1:
+ return "Minecraft";
+
+ case 2:
+ return "Type";
+
+ default:
+ return QVariant();
+ }
+
+ case Qt::ToolTipRole:
+ switch (section)
+ {
+ case 0:
+ return "The name of the version.";
+
+ case 1:
+ return "Minecraft version";
+
+ case 2:
+ return "The version's type.";
+
+ default:
+ return QVariant();
+ }
+
+ default:
+ return QVariant();
+ }
+}
+
+BaseVersionPtr ForgeVersionList::getLatestStable() const
+{
+ return BaseVersionPtr();
+}
+
+void ForgeVersionList::updateListData(QList<BaseVersionPtr> versions)
+{
+ beginResetModel();
+ m_vlist = versions;
+ m_loaded = true;
+ endResetModel();
+ // NOW SORT!!
+ // sort();
+}
+
+void ForgeVersionList::sort()
+{
+ // NO-OP for now
+}
+
+ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList *vlist) : Task()
+{
+ m_list = vlist;
+}
+
+void ForgeListLoadTask::executeTask()
+{
+ auto job = new DownloadJob("Version index");
+ // we do not care if the version is stale or not.
+ auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json");
+
+ // verify by poking the server.
+ forgeListEntry->stale = true;
+
+ job->addCacheDownload(QUrl(JSON_URL), forgeListEntry);
+ listJob.reset(job);
+ connect(listJob.get(), SIGNAL(succeeded()), SLOT(list_downloaded()));
+ connect(listJob.get(), SIGNAL(failed()), SLOT(list_failed()));
+ connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
+ listJob->start();
+}
+
+void ForgeListLoadTask::list_failed()
+{
+ auto DlJob = listJob->first();
+ auto reply = DlJob->m_reply;
+ if(reply)
+ {
+ QLOG_ERROR() << "Getting forge version list failed: " << reply->errorString();
+ }
+ else
+ QLOG_ERROR() << "Getting forge version list failed for reasons unknown.";
+}
+
+void ForgeListLoadTask::list_downloaded()
+{
+ QByteArray data;
+ {
+ auto DlJob = listJob->first();
+ auto filename = std::dynamic_pointer_cast<CacheDownload>(DlJob)->m_target_path;
+ QFile listFile(filename);
+ if(!listFile.open(QIODevice::ReadOnly))
+ return;
+ data = listFile.readAll();
+ DlJob.reset();
+ }
+
+ QJsonParseError jsonError;
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
+
+
+ if (jsonError.error != QJsonParseError::NoError)
+ {
+ emitFailed("Error parsing version list JSON:" + jsonError.errorString());
+ return;
+ }
+
+ if (!jsonDoc.isObject())
+ {
+ emitFailed("Error parsing version list JSON: jsonDoc is not an object");
+ return;
+ }
+
+ QJsonObject root = jsonDoc.object();
+
+ // Now, get the array of versions.
+ if (!root.value("builds").isArray())
+ {
+ emitFailed(
+ "Error parsing version list JSON: version list object is missing 'builds' array");
+ return;
+ }
+ QJsonArray builds = root.value("builds").toArray();
+
+ QList<BaseVersionPtr> tempList;
+ for (int i = 0; i < builds.count(); i++)
+ {
+ // Load the version info.
+ if (!builds[i].isObject())
+ {
+ // FIXME: log this somewhere
+ continue;
+ }
+ QJsonObject obj = builds[i].toObject();
+ int build_nr = obj.value("build").toDouble(0);
+ if (!build_nr)
+ continue;
+ QJsonArray files = obj.value("files").toArray();
+ QString url, jobbuildver, mcver, buildtype, filename;
+ QString changelog_url, installer_url;
+ QString installer_filename;
+ bool valid = false;
+ for (int j = 0; j < files.count(); j++)
+ {
+ if (!files[j].isObject())
+ continue;
+ QJsonObject file = files[j].toObject();
+ buildtype = file.value("buildtype").toString();
+ if ((buildtype == "client" || buildtype == "universal") && !valid)
+ {
+ mcver = file.value("mcver").toString();
+ url = file.value("url").toString();
+ jobbuildver = file.value("jobbuildver").toString();
+ int lastSlash = url.lastIndexOf('/');
+ filename = url.mid(lastSlash + 1);
+ valid = true;
+ }
+ else if (buildtype == "changelog")
+ {
+ QString ext = file.value("ext").toString();
+ if (ext.isEmpty())
+ continue;
+ changelog_url = file.value("url").toString();
+ }
+ else if (buildtype == "installer")
+ {
+ installer_url = file.value("url").toString();
+ int lastSlash = installer_url.lastIndexOf('/');
+ installer_filename = installer_url.mid(lastSlash + 1);
+ }
+ }
+ if (valid)
+ {
+ // Now, we construct the version object and add it to the list.
+ std::shared_ptr<ForgeVersion> fVersion(new ForgeVersion());
+ fVersion->universal_url = url;
+ fVersion->changelog_url = changelog_url;
+ fVersion->installer_url = installer_url;
+ fVersion->jobbuildver = jobbuildver;
+ fVersion->mcver = mcver;
+ if (installer_filename.isEmpty())
+ fVersion->filename = filename;
+ else
+ fVersion->filename = installer_filename;
+ fVersion->m_buildnr = build_nr;
+ tempList.append(fVersion);
+ }
+ }
+ m_list->updateListData(tempList);
+
+ emitSucceeded();
+ return;
+}
diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h
new file mode 100644
index 00000000..56a207c8
--- /dev/null
+++ b/logic/lists/ForgeVersionList.h
@@ -0,0 +1,109 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * 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
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <QObject>
+#include <QAbstractListModel>
+#include <QSharedPointer>
+#include <QUrl>
+
+#include <QNetworkReply>
+#include "BaseVersionList.h"
+#include "logic/tasks/Task.h"
+#include "logic/net/DownloadJob.h"
+
+class ForgeVersion;
+typedef std::shared_ptr<ForgeVersion> ForgeVersionPtr;
+
+struct ForgeVersion : public BaseVersion
+{
+ virtual QString descriptor()
+ {
+ return filename;
+ }
+ ;
+ virtual QString name()
+ {
+ return "Forge " + jobbuildver;
+ }
+ ;
+ virtual QString typeString() const
+ {
+ if (installer_url.isEmpty())
+ return "Universal";
+ else
+ return "Installer";
+ }
+ ;
+
+ int m_buildnr = 0;
+ QString universal_url;
+ QString changelog_url;
+ QString installer_url;
+ QString jobbuildver;
+ QString mcver;
+ QString filename;
+};
+
+class ForgeVersionList : public BaseVersionList
+{
+ Q_OBJECT
+public:
+ friend class ForgeListLoadTask;
+
+ explicit ForgeVersionList(QObject *parent = 0);
+
+ virtual Task *getLoadTask();
+ virtual bool isLoaded();
+ virtual const BaseVersionPtr at(int i) const;
+ virtual int count() const;
+ virtual void sort();
+
+ virtual BaseVersionPtr getLatestStable() const;
+
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation,
+ int role) const;
+ virtual int columnCount(const QModelIndex &parent) const;
+
+protected:
+ QList<BaseVersionPtr> m_vlist;
+
+ bool m_loaded;
+
+protected
+slots:
+ virtual void updateListData(QList<BaseVersionPtr> versions);
+};
+
+class ForgeListLoadTask : public Task
+{
+ Q_OBJECT
+
+public:
+ explicit ForgeListLoadTask(ForgeVersionList *vlist);
+
+ virtual void executeTask();
+
+protected
+slots:
+ void list_downloaded();
+ void list_failed();
+
+protected:
+ DownloadJobPtr listJob;
+ ForgeVersionList *m_list;
+};
diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp
index b930f781..9740d5a5 100644
--- a/logic/lists/InstanceList.cpp
+++ b/logic/lists/InstanceList.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
@@ -29,13 +29,13 @@
#include "logic/lists/IconList.h"
#include "logic/BaseInstance.h"
#include "logic/InstanceFactory.h"
+#include <logger/QsLog.h>
const static int GROUP_FILE_FORMAT_VERSION = 1;
-InstanceList::InstanceList(const QString &instDir, QObject *parent) :
- QAbstractListModel ( parent ), m_instDir("instances")
+InstanceList::InstanceList(const QString &instDir, QObject *parent)
+ : QAbstractListModel(parent), m_instDir("instances")
{
-
}
InstanceList::~InstanceList()
@@ -43,32 +43,32 @@ InstanceList::~InstanceList()
saveGroupList();
}
-int InstanceList::rowCount ( const QModelIndex& parent ) const
+int InstanceList::rowCount(const QModelIndex &parent) const
{
- Q_UNUSED ( parent );
+ Q_UNUSED(parent);
return m_instances.count();
}
-QModelIndex InstanceList::index ( int row, int column, const QModelIndex& parent ) const
+QModelIndex InstanceList::index(int row, int column, const QModelIndex &parent) const
{
- Q_UNUSED ( parent );
- if ( row < 0 || row >= m_instances.size() )
+ Q_UNUSED(parent);
+ if (row < 0 || row >= m_instances.size())
return QModelIndex();
- return createIndex ( row, column, ( void* ) m_instances.at ( row ).data() );
+ return createIndex(row, column, (void *)m_instances.at(row).get());
}
-QVariant InstanceList::data ( const QModelIndex& index, int role ) const
+QVariant InstanceList::data(const QModelIndex &index, int role) const
{
- if ( !index.isValid() )
+ if (!index.isValid())
{
return QVariant();
}
- BaseInstance *pdata = static_cast<BaseInstance*> ( index.internalPointer() );
- switch ( role )
+ BaseInstance *pdata = static_cast<BaseInstance *>(index.internalPointer());
+ switch (role)
{
case InstancePointerRole:
{
- QVariant v = qVariantFromValue((void *) pdata);
+ QVariant v = qVariantFromValue((void *)pdata);
return v;
}
case Qt::DisplayRole:
@@ -96,12 +96,12 @@ QVariant InstanceList::data ( const QModelIndex& index, int role ) const
return QVariant();
}
-Qt::ItemFlags InstanceList::flags ( const QModelIndex& index ) const
+Qt::ItemFlags InstanceList::flags(const QModelIndex &index) const
{
Qt::ItemFlags f;
- if ( index.isValid() )
+ if (index.isValid())
{
- f |= ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+ f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
return f;
}
@@ -116,23 +116,23 @@ void InstanceList::saveGroupList()
{
QString groupFileName = m_instDir + "/instgroups.json";
QFile groupFile(groupFileName);
-
+
// if you can't open the file, fail
- if (!groupFile.open(QIODevice::WriteOnly| QIODevice::Truncate))
+ if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
// An error occurred. Ignore it.
- qDebug("Failed to read instance group file.");
+ QLOG_ERROR() << "Failed to read instance group file.";
return;
}
QTextStream out(&groupFile);
- QMap<QString, QSet<QString> > groupMap;
- for(auto instance: m_instances)
+ QMap<QString, QSet<QString>> groupMap;
+ for (auto instance : m_instances)
{
QString id = instance->id();
QString group = instance->group();
- if(group.isEmpty())
+ if (group.isEmpty())
continue;
- if(!groupMap.count(group))
+ if (!groupMap.count(group))
{
QSet<QString> set;
set.insert(id);
@@ -145,109 +145,114 @@ void InstanceList::saveGroupList()
}
}
QJsonObject toplevel;
- toplevel.insert("formatVersion",QJsonValue(QString("1")));
+ toplevel.insert("formatVersion", QJsonValue(QString("1")));
QJsonObject groupsArr;
- for(auto iter = groupMap.begin(); iter != groupMap.end(); iter++)
+ for (auto iter = groupMap.begin(); iter != groupMap.end(); iter++)
{
auto list = iter.value();
auto name = iter.key();
QJsonObject groupObj;
QJsonArray instanceArr;
- groupObj.insert("hidden",QJsonValue(QString("false")));
- for(auto item: list)
+ groupObj.insert("hidden", QJsonValue(QString("false")));
+ for (auto item : list)
{
instanceArr.append(QJsonValue(item));
}
- groupObj.insert("instances",instanceArr);
- groupsArr.insert(name,groupObj);
+ groupObj.insert("instances", instanceArr);
+ groupsArr.insert(name, groupObj);
}
- toplevel.insert("groups",groupsArr);
+ toplevel.insert("groups", groupsArr);
QJsonDocument doc(toplevel);
groupFile.write(doc.toJson());
groupFile.close();
}
-void InstanceList::loadGroupList(QMap<QString, QString> & groupMap)
+void InstanceList::loadGroupList(QMap<QString, QString> &groupMap)
{
QString groupFileName = m_instDir + "/instgroups.json";
-
+
// if there's no group file, fail
- if(!QFileInfo(groupFileName).exists())
+ if (!QFileInfo(groupFileName).exists())
return;
-
+
QFile groupFile(groupFileName);
-
+
// if you can't open the file, fail
if (!groupFile.open(QIODevice::ReadOnly))
{
// An error occurred. Ignore it.
- qDebug("Failed to read instance group file.");
+ QLOG_ERROR() << "Failed to read instance group file.";
return;
}
-
+
QTextStream in(&groupFile);
QString jsonStr = in.readAll();
groupFile.close();
-
+
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error);
-
+
// if the json was bad, fail
if (error.error != QJsonParseError::NoError)
{
- qWarning(QString("Failed to parse instance group file: %1 at offset %2").
- arg(error.errorString(), QString::number(error.offset)).toUtf8());
+ QLOG_ERROR() << QString("Failed to parse instance group file: %1 at offset %2")
+ .arg(error.errorString(), QString::number(error.offset))
+ .toUtf8();
return;
}
-
+
// if the root of the json wasn't an object, fail
if (!jsonDoc.isObject())
{
qWarning("Invalid group file. Root entry should be an object.");
return;
}
-
+
QJsonObject rootObj = jsonDoc.object();
-
+
// Make sure the format version matches, otherwise fail.
if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION)
return;
-
+
// Get the groups. if it's not an object, fail
if (!rootObj.value("groups").isObject())
{
qWarning("Invalid group list JSON: 'groups' should be an object.");
return;
}
-
+
// Iterate through all the groups.
QJsonObject groupMapping = rootObj.value("groups").toObject();
for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.end(); iter++)
{
QString groupName = iter.key();
-
+
// If not an object, complain and skip to the next one.
if (!iter.value().isObject())
{
qWarning(QString("Group '%1' in the group list should "
- "be an object.").arg(groupName).toUtf8());
+ "be an object.")
+ .arg(groupName)
+ .toUtf8());
continue;
}
-
+
QJsonObject groupObj = iter.value().toObject();
if (!groupObj.value("instances").isArray())
{
qWarning(QString("Group '%1' in the group list is invalid. "
- "It should contain an array "
- "called 'instances'.").arg(groupName).toUtf8());
+ "It should contain an array "
+ "called 'instances'.")
+ .arg(groupName)
+ .toUtf8());
continue;
}
-
+
// Iterate through the list of instances in the group.
QJsonArray instancesArray = groupObj.value("instances").toArray();
-
- for (QJsonArray::iterator iter2 = instancesArray.begin();
- iter2 != instancesArray.end(); iter2++)
+
+ for (QJsonArray::iterator iter2 = instancesArray.begin(); iter2 != instancesArray.end();
+ iter2++)
{
groupMap[(*iter2).toString()] = groupName;
}
@@ -259,9 +264,9 @@ InstanceList::InstListError InstanceList::loadList()
// load the instance groups
QMap<QString, QString> groupMap;
loadGroupList(groupMap);
-
+
beginResetModel();
-
+
m_instances.clear();
QDir dir(m_instDir);
QDirIterator iter(dir);
@@ -270,53 +275,55 @@ InstanceList::InstListError InstanceList::loadList()
QString subDir = iter.next();
if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists())
continue;
-
+
BaseInstance *instPtr = NULL;
auto &loader = InstanceFactory::get();
auto error = loader.loadInstance(instPtr, subDir);
-
- switch(error)
+
+ switch (error)
{
- case InstanceFactory::NoLoadError:
- break;
- case InstanceFactory::NotAnInstance:
- break;
+ case InstanceFactory::NoLoadError:
+ break;
+ case InstanceFactory::NotAnInstance:
+ break;
}
-
- if (error != InstanceFactory::NoLoadError &&
- error != InstanceFactory::NotAnInstance)
+
+ if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance)
{
- QString errorMsg = QString("Failed to load instance %1: ").
- arg(QFileInfo(subDir).baseName()).toUtf8();
-
+ QString errorMsg = QString("Failed to load instance %1: ")
+ .arg(QFileInfo(subDir).baseName())
+ .toUtf8();
+
switch (error)
{
default:
- errorMsg += QString("Unknown instance loader error %1").
- arg(error);
+ errorMsg += QString("Unknown instance loader error %1").arg(error);
break;
}
- qDebug(errorMsg.toUtf8());
+ QLOG_ERROR() << errorMsg.toUtf8();
}
else if (!instPtr)
{
- qDebug(QString("Error loading instance %1. Instance loader returned null.").
- arg(QFileInfo(subDir).baseName()).toUtf8());
+ QLOG_ERROR() << QString("Error loading instance %1. Instance loader returned null.")
+ .arg(QFileInfo(subDir).baseName())
+ .toUtf8();
}
else
{
- QSharedPointer<BaseInstance> inst(instPtr);
+ std::shared_ptr<BaseInstance> inst(instPtr);
auto iter = groupMap.find(inst->id());
- if(iter != groupMap.end())
+ if (iter != groupMap.end())
{
inst->setGroupInitial((*iter));
}
- qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
+ QLOG_INFO() << "Loaded instance " << inst->name();
inst->setParent(this);
m_instances.append(inst);
- connect(instPtr, SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*)));
- connect(instPtr, SIGNAL(groupChanged()),this, SLOT(groupChanged()));
- connect(instPtr, SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*)));
+ connect(instPtr, SIGNAL(propertiesChanged(BaseInstance *)), this,
+ SLOT(propertiesChanged(BaseInstance *)));
+ connect(instPtr, SIGNAL(groupChanged()), this, SLOT(groupChanged()));
+ connect(instPtr, SIGNAL(nuked(BaseInstance *)), this,
+ SLOT(instanceNuked(BaseInstance *)));
}
}
endResetModel();
@@ -332,7 +339,8 @@ void InstanceList::clear()
m_instances.clear();
endResetModel();
emit dataIsInvalid();
-};
+}
+;
/// Add an instance. Triggers notifications, returns the new index
int InstanceList::add(InstancePtr t)
@@ -340,9 +348,10 @@ int InstanceList::add(InstancePtr t)
beginInsertRows(QModelIndex(), m_instances.size(), m_instances.size());
m_instances.append(t);
t->setParent(this);
- connect(t.data(), SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*)));
- connect(t.data(), SIGNAL(groupChanged()),this, SLOT(groupChanged()));
- connect(t.data(), SIGNAL(nuked(BaseInstance*)), this, SLOT(instanceNuked(BaseInstance*)));
+ connect(t.get(), SIGNAL(propertiesChanged(BaseInstance *)), this,
+ SLOT(propertiesChanged(BaseInstance *)));
+ connect(t.get(), SIGNAL(groupChanged()), this, SLOT(groupChanged()));
+ connect(t.get(), SIGNAL(nuked(BaseInstance *)), this, SLOT(instanceNuked(BaseInstance *)));
endInsertRows();
return count() - 1;
}
@@ -351,7 +360,7 @@ InstancePtr InstanceList::getInstanceById(QString instId)
{
QListIterator<InstancePtr> iter(m_instances);
InstancePtr inst;
- while(iter.hasNext())
+ while (iter.hasNext())
{
inst = iter.next();
if (inst->id() == instId)
@@ -363,11 +372,11 @@ InstancePtr InstanceList::getInstanceById(QString instId)
return iter.peekPrevious();
}
-int InstanceList::getInstIndex ( BaseInstance* inst )
+int InstanceList::getInstIndex(BaseInstance *inst)
{
- for(int i = 0; i < m_instances.count(); i++)
+ for (int i = 0; i < m_instances.count(); i++)
{
- if(inst == m_instances[i].data())
+ if (inst == m_instances[i].get())
{
return i;
}
@@ -375,40 +384,39 @@ int InstanceList::getInstIndex ( BaseInstance* inst )
return -1;
}
-
-void InstanceList::instanceNuked ( BaseInstance* inst )
+void InstanceList::instanceNuked(BaseInstance *inst)
{
int i = getInstIndex(inst);
- if(i != -1)
+ if (i != -1)
{
- beginRemoveRows(QModelIndex(),i,i);
+ beginRemoveRows(QModelIndex(), i, i);
m_instances.removeAt(i);
endRemoveRows();
}
}
-
-void InstanceList::propertiesChanged(BaseInstance * inst)
+void InstanceList::propertiesChanged(BaseInstance *inst)
{
int i = getInstIndex(inst);
- if(i != -1)
+ if (i != -1)
{
emit dataChanged(index(i), index(i));
}
}
-InstanceProxyModel::InstanceProxyModel ( QObject *parent )
- : KCategorizedSortFilterProxyModel ( parent )
+InstanceProxyModel::InstanceProxyModel(QObject *parent)
+ : KCategorizedSortFilterProxyModel(parent)
{
// disable since by default we are globally sorting by date:
setCategorizedModel(true);
}
-bool InstanceProxyModel::subSortLessThan (const QModelIndex& left, const QModelIndex& right ) const
+bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
+ const QModelIndex &right) const
{
- BaseInstance *pdataLeft = static_cast<BaseInstance*> ( left.internalPointer() );
- BaseInstance *pdataRight = static_cast<BaseInstance*> ( right.internalPointer() );
- //kDebug() << *pdataLeft << *pdataRight;
+ BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
+ BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());
+ // kDebug() << *pdataLeft << *pdataRight;
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
- //return pdataLeft->name() < pdataRight->name();
+ // return pdataLeft->name() < pdataRight->name();
}
diff --git a/logic/lists/JavaVersionList.cpp b/logic/lists/JavaVersionList.cpp
new file mode 100644
index 00000000..5389c4cc
--- /dev/null
+++ b/logic/lists/JavaVersionList.cpp
@@ -0,0 +1,203 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * 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
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JavaVersionList.h"
+#include "MultiMC.h"
+
+#include <QtNetwork>
+#include <QtXml>
+#include <QRegExp>
+
+#include <logger/QsLog.h>
+#include <logic/JavaUtils.h>
+
+JavaVersionList::JavaVersionList(QObject *parent) : BaseVersionList(parent)
+{
+}
+
+Task *JavaVersionList::getLoadTask()
+{
+ return new JavaListLoadTask(this);
+}
+
+
+const BaseVersionPtr JavaVersionList::at(int i) const
+{
+ return m_vlist.at(i);
+}
+
+bool JavaVersionList::isLoaded()
+{
+ return m_loaded;
+}
+
+int JavaVersionList::count() const
+{
+ return m_vlist.count();
+}
+
+int JavaVersionList::columnCount(const QModelIndex &parent) const
+{
+ return 4;
+}
+
+QVariant JavaVersionList::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() > count())
+ return QVariant();
+
+ auto version = std::dynamic_pointer_cast<JavaVersion>(m_vlist[index.row()]);
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (index.column())
+ {
+ case 0:
+ return version->id;
+
+ case 1:
+ return version->arch;
+
+ case 2:
+ return version->path;
+
+ case 3:
+ return version->recommended ? tr("Yes") : tr("No");
+
+ default:
+ return QVariant();
+ }
+
+ case Qt::ToolTipRole:
+ return version->descriptor();
+
+ case VersionPointerRole:
+ return qVariantFromValue(m_vlist[index.row()]);
+
+ default:
+ return QVariant();
+ }
+}
+
+QVariant JavaVersionList::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ switch (role)
+ {
+ case Qt::DisplayRole:
+ switch (section)
+ {
+ case 0:
+ return "Version";
+
+ case 1:
+ return "Arch";
+
+ case 2:
+ return "Path";
+
+ case 3:
+ return "Recommended";
+
+ default:
+ return QVariant();
+ }
+
+ case Qt::ToolTipRole:
+ switch (section)
+ {
+ case 0:
+ return "The name of the version.";
+
+ case 1:
+ return "The architecture this version is for.";
+
+ case 2:
+ return "Path to this Java version.";
+
+ case 3:
+ return "Whether the version is recommended or not.";
+
+ default:
+ return QVariant();
+ }
+
+ default:
+ return QVariant();
+ }
+}
+
+BaseVersionPtr JavaVersionList::getTopRecommended() const
+{
+ for (int i = 0; i < m_vlist.length(); i++)
+ {
+ auto ver = std::dynamic_pointer_cast<JavaVersion>(m_vlist.at(i));
+ if (ver->recommended)
+ {
+ return m_vlist.at(i);
+ }
+ }
+ return BaseVersionPtr();
+}
+
+void JavaVersionList::updateListData(QList<BaseVersionPtr> versions)
+{
+ beginResetModel();
+ m_vlist = versions;
+ m_loaded = true;
+ endResetModel();
+ // NOW SORT!!
+ // sort();
+}
+
+void JavaVersionList::sort()
+{
+ // NO-OP for now
+}
+
+JavaListLoadTask::JavaListLoadTask(JavaVersionList *vlist)
+{
+ m_list = vlist;
+ m_currentRecommended = NULL;
+}
+
+JavaListLoadTask::~JavaListLoadTask()
+{
+}
+
+void JavaListLoadTask::executeTask()
+{
+ setStatus("Detecting Java installations...");
+
+ JavaUtils ju;
+ QList<JavaVersionPtr> javas = ju.FindJavaPaths();
+
+ QList<BaseVersionPtr> javas_bvp;
+ for(int i = 0; i < javas.length(); i++)
+ {
+ BaseVersionPtr java = std::dynamic_pointer_cast<BaseVersion>(javas.at(i));
+
+ if(java)
+ {
+ javas_bvp.append(java);
+ }
+ }
+
+ m_list->updateListData(javas_bvp);
+
+ emitSucceeded();
+}
diff --git a/logic/lists/JavaVersionList.h b/logic/lists/JavaVersionList.h
new file mode 100644
index 00000000..23bccfe4
--- /dev/null
+++ b/logic/lists/JavaVersionList.h
@@ -0,0 +1,93 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * 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
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <QObject>
+#include <QAbstractListModel>
+#include <QSharedPointer>
+
+#include "BaseVersionList.h"
+#include "logic/tasks/Task.h"
+
+class JavaListLoadTask;
+
+struct JavaVersion : public BaseVersion
+{
+ virtual QString descriptor()
+ {
+ return id;
+ }
+
+ virtual QString name()
+ {
+ return id;
+ }
+
+ virtual QString typeString() const
+ {
+ return arch;
+ }
+
+ QString id;
+ QString arch;
+ QString path;
+ bool recommended;
+};
+
+typedef std::shared_ptr<JavaVersion> JavaVersionPtr;
+
+class JavaVersionList : public BaseVersionList
+{
+ Q_OBJECT
+public:
+ explicit JavaVersionList(QObject *parent = 0);
+
+ virtual Task *getLoadTask();
+ virtual bool isLoaded();
+ virtual const BaseVersionPtr at(int i) const;
+ virtual int count() const;
+ virtual void sort();
+
+ virtual BaseVersionPtr getTopRecommended() const;
+
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation,
+ int role) const;
+ virtual int columnCount(const QModelIndex &parent) const;
+
+public slots:
+ virtual void updateListData(QList<BaseVersionPtr> versions);
+
+protected:
+ QList<BaseVersionPtr> m_vlist;
+
+ bool m_loaded = false;
+};
+
+class JavaListLoadTask : public Task
+{
+ Q_OBJECT
+
+public:
+ explicit JavaListLoadTask(JavaVersionList *vlist);
+ ~JavaListLoadTask();
+
+ virtual void executeTask();
+
+protected:
+ JavaVersionList *m_list;
+ JavaVersion *m_currentRecommended;
+};
diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp
index d7826a82..6bf401ec 100644
--- a/logic/lists/LwjglVersionList.cpp
+++ b/logic/lists/LwjglVersionList.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
@@ -17,23 +17,14 @@
#include "MultiMC.h"
#include <QtNetwork>
-
#include <QtXml>
-
#include <QRegExp>
-#define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss"
-
-LWJGLVersionList mainVersionList;
-
-LWJGLVersionList &LWJGLVersionList::get()
-{
- return mainVersionList;
-}
+#include <logger/QsLog.h>
+#define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss"
-LWJGLVersionList::LWJGLVersionList(QObject *parent) :
- QAbstractListModel(parent)
+LWJGLVersionList::LWJGLVersionList(QObject *parent) : QAbstractListModel(parent)
{
setLoading(false);
}
@@ -42,20 +33,20 @@ QVariant LWJGLVersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
-
+
if (index.row() > count())
return QVariant();
-
+
const PtrLWJGLVersion version = at(index.row());
-
+
switch (role)
{
case Qt::DisplayRole:
return version->name();
-
+
case Qt::ToolTipRole:
return version->url();
-
+
default:
return QVariant();
}
@@ -67,10 +58,10 @@ QVariant LWJGLVersionList::headerData(int section, Qt::Orientation orientation,
{
case Qt::DisplayRole:
return "Version";
-
+
case Qt::ToolTipRole:
return "LWJGL version name.";
-
+
default:
return QVariant();
}
@@ -89,7 +80,7 @@ bool LWJGLVersionList::isLoading() const
void LWJGLVersionList::loadList()
{
Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)");
-
+
setLoading(true);
auto worker = MMC->qnam();
reply = worker->get(QNetworkRequest(QUrl(RSS_URL)));
@@ -110,68 +101,68 @@ void LWJGLVersionList::netRequestComplete()
if (reply->error() == QNetworkReply::NoError)
{
QRegExp lwjglRegex("lwjgl-(([0-9]\\.?)+)\\.zip");
- Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list",
- "LWJGL regex is invalid");
-
+ Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list", "LWJGL regex is invalid");
+
QDomDocument doc;
-
+
QString xmlErrorMsg;
int errorLine;
if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine))
{
- failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + QString::number(errorLine));
+ failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " +
+ QString::number(errorLine));
setLoading(false);
return;
}
-
+
QDomNodeList items = doc.elementsByTagName("item");
-
+
QList<PtrLWJGLVersion> tempList;
-
+
for (int i = 0; i < items.length(); i++)
{
Q_ASSERT_X(items.at(i).isElement(), "load LWJGL list",
"XML element isn't an element... wat?");
-
+
QDomElement linkElement = getDomElementByTagName(items.at(i).toElement(), "link");
if (linkElement.isNull())
{
qWarning() << "Link element" << i << "in RSS feed doesn't exist! Skipping.";
continue;
}
-
+
QString link = linkElement.text();
-
+
// Make sure it's a download link.
if (link.endsWith("/download") && link.contains(lwjglRegex))
{
QString name = link.mid(lwjglRegex.indexIn(link) + 6);
// Subtract 4 here to remove the .zip file extension.
name = name.left(lwjglRegex.matchedLength() - 10);
-
+
QUrl url(link);
if (!url.isValid())
{
qWarning() << "LWJGL version URL isn't valid:" << link << "Skipping.";
continue;
}
-
+
tempList.append(LWJGLVersion::Create(name, link));
}
}
-
+
beginResetModel();
m_vlist.swap(tempList);
endResetModel();
-
- qDebug("Loaded LWJGL list.");
+
+ QLOG_INFO() << "Loaded LWJGL list.";
finished();
}
else
{
failed("Failed to load LWJGL list. Network error: " + reply->errorString());
}
-
+
setLoading(false);
reply->deleteLater();
}
@@ -181,13 +172,12 @@ const PtrLWJGLVersion LWJGLVersionList::getVersion(const QString &versionName)
for (int i = 0; i < count(); i++)
{
QString name = at(i)->name();
- if ( name == versionName)
+ if (name == versionName)
return at(i);
}
return PtrLWJGLVersion();
}
-
void LWJGLVersionList::failed(QString msg)
{
qWarning() << msg;
diff --git a/logic/lists/LwjglVersionList.h b/logic/lists/LwjglVersionList.h
index 638a0b67..99712292 100644
--- a/logic/lists/LwjglVersionList.h
+++ b/logic/lists/LwjglVersionList.h
@@ -17,13 +17,13 @@
#include <QObject>
#include <QAbstractListModel>
-#include <QSharedPointer>
#include <QUrl>
-
#include <QNetworkReply>
+#include <memory>
+
class LWJGLVersion;
-typedef QSharedPointer<LWJGLVersion> PtrLWJGLVersion;
+typedef std::shared_ptr<LWJGLVersion> PtrLWJGLVersion;
class LWJGLVersion : public QObject
{
@@ -53,8 +53,6 @@ class LWJGLVersionList : public QAbstractListModel
public:
explicit LWJGLVersionList(QObject *parent = 0);
- static LWJGLVersionList &get();
-
bool isLoaded() { return m_vlist.length() > 0; }
const PtrLWJGLVersion getVersion(const QString &versionName);
diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp
index 42fb1b50..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
@@ -16,8 +16,6 @@
#include "MinecraftVersionList.h"
#include <MultiMC.h>
-#include <QDebug>
-
#include <QtXml>
#include <QJsonDocument>
@@ -34,12 +32,8 @@
#define ASSETS_URLBASE "http://assets.minecraft.net/"
#define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
-MinecraftVersionList mcVList;
-
-MinecraftVersionList::MinecraftVersionList(QObject *parent) :
- InstVersionList(parent)
+MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent)
{
-
}
Task *MinecraftVersionList::getLoadTask()
@@ -52,7 +46,7 @@ bool MinecraftVersionList::isLoaded()
return m_loaded;
}
-const InstVersionPtr MinecraftVersionList::at(int i) const
+const BaseVersionPtr MinecraftVersionList::at(int i) const
{
return m_vlist.at(i);
}
@@ -62,11 +56,11 @@ int MinecraftVersionList::count() const
return m_vlist.count();
}
-bool cmpVersions(InstVersionPtr first, InstVersionPtr second)
+bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
{
- const InstVersion & left = *first;
- const InstVersion & right = *second;
- return left > right;
+ auto left = std::dynamic_pointer_cast<MinecraftVersion>(first);
+ auto right = std::dynamic_pointer_cast<MinecraftVersion>(second);
+ return left->timestamp > right->timestamp;
}
void MinecraftVersionList::sort()
@@ -76,25 +70,20 @@ void MinecraftVersionList::sort()
endResetModel();
}
-InstVersionPtr MinecraftVersionList::getLatestStable() const
+BaseVersionPtr MinecraftVersionList::getLatestStable() const
{
for (int i = 0; i < m_vlist.length(); i++)
{
- auto ver = m_vlist.at(i).dynamicCast<MinecraftVersion>();
+ auto ver = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist.at(i));
if (ver->is_latest && !ver->is_snapshot)
{
return m_vlist.at(i);
}
}
- return InstVersionPtr();
-}
-
-MinecraftVersionList &MinecraftVersionList::getMainList()
-{
- return mcVList;
+ return BaseVersionPtr();
}
-void MinecraftVersionList::updateListData(QList<InstVersionPtr > versions)
+void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions)
{
beginResetModel();
m_vlist = versions;
@@ -118,7 +107,6 @@ inline QDateTime timeFromS3Time(QString str)
return QDateTime::fromString(str, Qt::ISODate);
}
-
MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
{
m_list = vlist;
@@ -131,9 +119,13 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
legacyWhitelist.insert("1.4.6");
legacyWhitelist.insert("1.4.5");
legacyWhitelist.insert("1.4.4");
+ legacyWhitelist.insert("1.4.3");
legacyWhitelist.insert("1.4.2");
+ legacyWhitelist.insert("1.4.1");
+ legacyWhitelist.insert("1.4");
legacyWhitelist.insert("1.3.2");
legacyWhitelist.insert("1.3.1");
+ legacyWhitelist.insert("1.3");
legacyWhitelist.insert("1.2.5");
legacyWhitelist.insert("1.2.4");
legacyWhitelist.insert("1.2.3");
@@ -156,91 +148,91 @@ void MCVListLoadTask::executeTask()
connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded()));
}
-
void MCVListLoadTask::list_downloaded()
{
- if(vlistReply->error() != QNetworkReply::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<InstVersionPtr > 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.
@@ -248,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;
@@ -272,15 +266,15 @@ 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.
- QSharedPointer<MinecraftVersion> mcVersion(new MinecraftVersion());
- mcVersion->name = mcVersion->descriptor = versionID;
+ std::shared_ptr<MinecraftVersion> mcVersion(new MinecraftVersion());
+ mcVersion->m_name = mcVersion->m_descriptor = versionID;
mcVersion->timestamp = versionTime.toMSecsSinceEpoch();
mcVersion->download_url = dlUrl;
mcVersion->is_latest = is_latest;
@@ -289,12 +283,7 @@ void MCVListLoadTask::list_downloaded()
tempList.append(mcVersion);
}
m_list->updateListData(tempList);
-
+
emitSucceeded();
return;
}
-
-// FIXME: we should have a local cache of the version list and a local cache of version data
-bool MCVListLoadTask::loadFromVList()
-{
-}
diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h
index 0477379f..ed68efbb 100644
--- a/logic/lists/MinecraftVersionList.h
+++ b/logic/lists/MinecraftVersionList.h
@@ -20,14 +20,14 @@
#include <QSet>
#include <QSharedPointer>
-#include "InstVersionList.h"
+#include "BaseVersionList.h"
#include "logic/tasks/Task.h"
#include "logic/MinecraftVersion.h"
class MCVListLoadTask;
class QNetworkReply;
-class MinecraftVersionList : public InstVersionList
+class MinecraftVersionList : public BaseVersionList
{
Q_OBJECT
public:
@@ -37,25 +37,19 @@ public:
virtual Task *getLoadTask();
virtual bool isLoaded();
- virtual const InstVersionPtr at(int i) const;
+ virtual const BaseVersionPtr at(int i) const;
virtual int count() const;
virtual void sort();
- virtual InstVersionPtr getLatestStable() const;
-
- /*!
- * Gets the main version list instance.
- */
- static MinecraftVersionList &getMainList();
-
+ virtual BaseVersionPtr getLatestStable() const;
protected:
- QList<InstVersionPtr > m_vlist;
+ QList<BaseVersionPtr> m_vlist;
- bool m_loaded;
+ bool m_loaded = false;
protected slots:
- virtual void updateListData(QList<InstVersionPtr > versions);
+ virtual void updateListData(QList<BaseVersionPtr> versions);
};
class MCVListLoadTask : public Task
@@ -72,9 +66,6 @@ protected slots:
void list_downloaded();
protected:
- //! Loads versions from Mojang's official version list.
- bool loadFromVList();
-
QNetworkReply *vlistReply;
MinecraftVersionList *m_list;
MinecraftVersion *m_currentStable;