summaryrefslogtreecommitdiffstats
path: root/logic/lists
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2013-12-20 14:47:26 +0100
committerPetr Mrázek <peterix@gmail.com>2013-12-21 23:40:37 +0100
commit82c87aa06f793b9f38e6cb42d284f00695f4bac5 (patch)
tree21f893b0336a90d4e4b9f14cb5312f2c1ea04280 /logic/lists
parent34a3fedf7b115c84ff305bf72fbc9d568682d84a (diff)
downloadMultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar.gz
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar.lz
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.tar.xz
MultiMC-82c87aa06f793b9f38e6cb42d284f00695f4bac5.zip
Initial FTB support. Allows "tracking" of FTB instances.
Diffstat (limited to 'logic/lists')
-rw-r--r--logic/lists/ForgeVersionList.cpp1
-rw-r--r--logic/lists/InstanceList.cpp151
-rw-r--r--logic/lists/InstanceList.h14
3 files changed, 123 insertions, 43 deletions
diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp
index b5e421af..d6d353da 100644
--- a/logic/lists/ForgeVersionList.cpp
+++ b/logic/lists/ForgeVersionList.cpp
@@ -159,6 +159,7 @@ ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList *vlist) : Task()
void ForgeListLoadTask::executeTask()
{
+ setStatus(tr("Fetching Forge version list"));
auto job = new NetJob("Version index");
// we do not care if the version is stale or not.
auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json");
diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp
index 15fd10ba..539413d8 100644
--- a/logic/lists/InstanceList.cpp
+++ b/logic/lists/InstanceList.cpp
@@ -22,11 +22,14 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
+#include <QXmlStreamReader>
+#include <QRegularExpression>
#include <pathutils.h>
#include "MultiMC.h"
#include "logic/lists/InstanceList.h"
#include "logic/lists/IconList.h"
+#include "logic/lists/MinecraftVersionList.h"
#include "logic/BaseInstance.h"
#include "logic/InstanceFactory.h"
#include "logger/QsLog.h"
@@ -42,6 +45,8 @@ InstanceList::InstanceList(const QString &instDir, QObject *parent)
{
QDir::current().mkpath(m_instDir);
}
+
+ connect(MMC->minecraftlist().get(), &MinecraftVersionList::modelReset, this, &InstanceList::loadList);
}
InstanceList::~InstanceList()
@@ -285,57 +290,87 @@ InstanceList::InstListError InstanceList::loadList()
beginResetModel();
m_instances.clear();
- QDir dir(m_instDir);
- QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable,
- QDirIterator::FollowSymlinks);
- while (iter.hasNext())
+
{
- QString subDir = iter.next();
- if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists())
- continue;
+ QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable,
+ QDirIterator::FollowSymlinks);
+ while (iter.hasNext())
+ {
+ 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);
+ BaseInstance *instPtr = NULL;
+ auto error = InstanceFactory::get().loadInstance(instPtr, subDir);
+ continueProcessInstance(instPtr, error, subDir, groupMap);
+ }
+ }
- if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance)
+ if (MMC->settings()->get("TrackFTBInstances").toBool() && MMC->minecraftlist()->isLoaded())
+ {
+ QDir dir = QDir(MMC->settings()->get("FTBLauncherRoot").toString());
+ QDir dataDir = QDir(MMC->settings()->get("FTBRoot").toString());
+ if (!dir.exists())
{
- 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);
- break;
- }
- QLOG_ERROR() << errorMsg.toUtf8();
+ QLOG_INFO() << "The FTB launcher directory specified does not exist. Please check your settings.";
}
- else if (!instPtr)
+ else if (!dataDir.exists())
{
- QLOG_ERROR() << QString("Error loading instance %1. Instance loader returned null.")
- .arg(QFileInfo(subDir).baseName())
- .toUtf8();
+ QLOG_INFO() << "The FTB directory specified does not exist. Please check your settings";
}
else
{
- std::shared_ptr<BaseInstance> inst(instPtr);
- auto iter = groupMap.find(inst->id());
- if (iter != groupMap.end())
+ dir.cd("ModPacks");
+ QFile f(dir.absoluteFilePath("modpacks.xml"));
+ if (f.open(QFile::ReadOnly))
{
- inst->setGroupInitial((*iter));
+ QXmlStreamReader reader(&f);
+ while (!reader.atEnd())
+ {
+ switch (reader.readNext())
+ {
+ case QXmlStreamReader::StartElement:
+ {
+ if (reader.name() == "modpack")
+ {
+ QXmlStreamAttributes attrs = reader.attributes();
+ const QDir instanceDir = QDir(dataDir.absoluteFilePath(attrs.value("dir").toString()));
+ if (instanceDir.exists())
+ {
+ const QString name = attrs.value("name").toString();
+ const QString iconKey = attrs.value("logo").toString().remove(QRegularExpression("\\..*"));
+ const QString mcVersion = attrs.value("mcVersion").toString();
+ const QString notes = attrs.value("description").toString();
+ QLOG_DEBUG() << dir.absoluteFilePath(attrs.value("logo").toString());
+ MMC->icons()->addIcon(iconKey, iconKey, dir.absoluteFilePath(attrs.value("dir").toString() + QDir::separator() + attrs.value("logo").toString()), true);
+
+ BaseInstance *instPtr = NULL;
+ auto error = InstanceFactory::get().createInstance(instPtr, MMC->minecraftlist()->findVersion(mcVersion), instanceDir.absolutePath(), InstanceFactory::FTBInstance);
+ if (instPtr && error == InstanceFactory::NoCreateError)
+ {
+ instPtr->setGroupInitial("FTB");
+ instPtr->setName(name);
+ instPtr->setIconKey(iconKey);
+ instPtr->setIntendedVersionId(mcVersion);
+ instPtr->setNotes(notes);
+ }
+ continueProcessInstance(instPtr, error, instanceDir, groupMap);
+ }
+ }
+ break;
+ }
+ case QXmlStreamReader::EndElement:
+ break;
+ case QXmlStreamReader::Characters:
+ break;
+ default:
+ break;
+ }
+ }
}
- 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 *)));
}
}
+
endResetModel();
emit dataIsInvalid();
return NoError;
@@ -409,6 +444,46 @@ int InstanceList::getInstIndex(BaseInstance *inst) const
return -1;
}
+void InstanceList::continueProcessInstance(BaseInstance *instPtr, const int error, const QDir &dir, QMap<QString, QString> &groupMap)
+{
+ if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance)
+ {
+ QString errorMsg = QString("Failed to load instance %1: ")
+ .arg(QFileInfo(dir.absolutePath()).baseName())
+ .toUtf8();
+
+ switch (error)
+ {
+ default:
+ errorMsg += QString("Unknown instance loader error %1").arg(error);
+ break;
+ }
+ QLOG_ERROR() << errorMsg.toUtf8();
+ }
+ else if (!instPtr)
+ {
+ QLOG_ERROR() << QString("Error loading instance %1. Instance loader returned null.")
+ .arg(QFileInfo(dir.absolutePath()).baseName())
+ .toUtf8();
+ }
+ else
+ {
+ auto iter = groupMap.find(instPtr->id());
+ if (iter != groupMap.end())
+ {
+ instPtr->setGroupInitial((*iter));
+ }
+ QLOG_INFO() << "Loaded instance " << instPtr->name();
+ instPtr->setParent(this);
+ m_instances.append(std::shared_ptr<BaseInstance>(instPtr));
+ 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 *)));
+ }
+}
+
void InstanceList::instanceNuked(BaseInstance *inst)
{
int i = getInstIndex(inst);
diff --git a/logic/lists/InstanceList.h b/logic/lists/InstanceList.h
index f23b7763..b3ee6cfe 100644
--- a/logic/lists/InstanceList.h
+++ b/logic/lists/InstanceList.h
@@ -25,6 +25,8 @@
class BaseInstance;
+class QDir;
+
class InstanceList : public QAbstractListModel
{
Q_OBJECT
@@ -66,11 +68,6 @@ public:
}
/*!
- * \brief Loads the instance list. Triggers notifications.
- */
- InstListError loadList();
-
- /*!
* \brief Get the instance at index
*/
InstancePtr at(int i) const
@@ -108,6 +105,11 @@ public
slots:
void on_InstFolderChanged(const Setting &setting, QVariant value);
+ /*!
+ * \brief Loads the instance list. Triggers notifications.
+ */
+ InstListError loadList();
+
private
slots:
void propertiesChanged(BaseInstance *inst);
@@ -117,6 +119,8 @@ slots:
private:
int getInstIndex(BaseInstance *inst) const;
+ void continueProcessInstance(BaseInstance *instPtr, const int error, const QDir &dir, QMap<QString, QString> &groupMap);
+
protected:
QString m_instDir;
QList<InstancePtr> m_instances;