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 applicab