summaryrefslogtreecommitdiffstats
path: root/libinstance
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-02-20 19:45:00 -0600
committerAndrew <forkk@forkk.net>2013-02-20 19:45:00 -0600
commitf3b6eeeac4e1606a288c7f12fec271fbb7f120f6 (patch)
tree50885f4302d1df8386716df9423fcd3c529010ee /libinstance
parentdd2e836b4cf4cfa043f9ea2911f58f1d22d4e282 (diff)
downloadMultiMC-f3b6eeeac4e1606a288c7f12fec271fbb7f120f6.tar
MultiMC-f3b6eeeac4e1606a288c7f12fec271fbb7f120f6.tar.gz
MultiMC-f3b6eeeac4e1606a288c7f12fec271fbb7f120f6.tar.lz
MultiMC-f3b6eeeac4e1606a288c7f12fec271fbb7f120f6.tar.xz
MultiMC-f3b6eeeac4e1606a288c7f12fec271fbb7f120f6.zip
Got instance loading working.
Diffstat (limited to 'libinstance')
-rw-r--r--libinstance/include/instanceloader.h11
-rw-r--r--libinstance/include/instancetypeinterface.h4
-rw-r--r--libinstance/src/instancelist.cpp9
-rw-r--r--libinstance/src/instanceloader.cpp6
4 files changed, 18 insertions, 12 deletions
diff --git a/libinstance/include/instanceloader.h b/libinstance/include/instanceloader.h
index 39696639..96be36fb 100644
--- a/libinstance/include/instanceloader.h
+++ b/libinstance/include/instanceloader.h
@@ -51,6 +51,7 @@ public:
* - InstExists is returned by createInstance() if the given instance directory is already an instance.
* - NotAnInstance is returned by loadInstance() if the given instance directory is not a valid instance.
* - WrongInstType is returned by loadInstance() if the given instance directory's type doesn't match the given type.
+ * - CantCreateDir is returned by createInstance( if the given instance directory can't be created.)
*/
enum InstTypeError
{
@@ -62,7 +63,8 @@ public:
TypeNotRegistered,
InstExists,
NotAnInstance,
- WrongInstType
+ WrongInstType,
+ CantCreateDir
};
/*!
@@ -83,8 +85,9 @@ public:
* \return An InstTypeError error code.
* - TypeNotRegistered if the given type is not registered with the InstanceLoader.
* - InstExists if the given instance directory is already an instance.
+ * - CantCreateDir if the given instance directory cannot be created.
*/
- InstTypeError createInstance(Instance *inst, const InstanceTypeInterface *type, const QString &instDir);
+ InstTypeError createInstance(Instance *&inst, const InstanceTypeInterface *type, const QString &instDir);
/*!
* \brief Loads an instance from the given directory.
@@ -97,7 +100,7 @@ public:
* - NotAnInstance if the given instance directory isn't a valid instance.
* - WrongInstType if the given instance directory's type isn't the same as the given type.
*/
- InstTypeError loadInstance(Instance *inst, const InstanceTypeInterface *type, const QString &instDir);
+ InstTypeError loadInstance(Instance *&inst, const InstanceTypeInterface *type, const QString &instDir);
/*!
* \brief Loads an instance from the given directory.
@@ -108,7 +111,7 @@ public:
* - TypeNotRegistered if the instance's type is not registered with the InstanceLoader.
* - NotAnInstance if the given instance directory isn't a valid instance.
*/
- InstTypeError loadInstance(Instance *inst, const QString &instDir);
+ InstTypeError loadInstance(Instance *&inst, const QString &instDir);
/*!
* \brief Finds an instance type with the given ID.
diff --git a/libinstance/include/instancetypeinterface.h b/libinstance/include/instancetypeinterface.h
index a061b9d2..30a12d99 100644
--- a/libinstance/include/instancetypeinterface.h
+++ b/libinstance/include/instancetypeinterface.h
@@ -67,7 +67,7 @@ protected:
* TypeNotRegistered if the given type is not registered with the InstanceLoader.
* InstExists if the given instance directory is already an instance.
*/
- virtual InstanceLoader::InstTypeError createInstance(Instance *inst, const QString &instDir) const = 0;
+ virtual InstanceLoader::InstTypeError createInstance(Instance *&inst, const QString &instDir) const = 0;
/*!
* \brief Loads an instance from the given directory.
@@ -78,7 +78,7 @@ protected:
* NotAnInstance if the given instance directory isn't a valid instance.
* WrongInstType if the given instance directory's type isn't an instance of this type.
*/
- virtual InstanceLoader::InstTypeError loadInstance(Instance *inst, const QString &instDir) const = 0;
+ virtual InstanceLoader::InstTypeError loadInstance(Instance *&inst, const QString &instDir) const = 0;
};
Q_DECLARE_INTERFACE(InstanceTypeInterface, InstanceTypeInterface_IID)
diff --git a/libinstance/src/instancelist.cpp b/libinstance/src/instancelist.cpp
index 15f79d05..3b0b668f 100644
--- a/libinstance/src/instancelist.cpp
+++ b/libinstance/src/instancelist.cpp
@@ -43,9 +43,10 @@ InstanceList::InstListError InstanceList::loadList()
QString subDir = iter.next();
if (QFileInfo(PathCombine(subDir, "instance.cfg")).exists())
{
- QSharedPointer<Instance> inst;
+ Instance *instPtr = NULL;
+
InstanceLoader::InstTypeError error = InstanceLoader::get().
- loadInstance(inst.data(), subDir);
+ loadInstance(instPtr, subDir);
if (error != InstanceLoader::NoError &&
error != InstanceLoader::NotAnInstance)
@@ -66,13 +67,15 @@ InstanceList::InstListError InstanceList::loadList()
}
qDebug(errorMsg.toUtf8());
}
- else if (!inst.data())
+ else if (!instPtr)
{
qDebug(QString("Error loading instance %1. Instance loader returned null.").
arg(QFileInfo(subDir).baseName()).toUtf8());
}
else
{
+ QSharedPointer<Instance> inst(instPtr);
+
qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
inst->setParent(this);
append(QSharedPointer<Instance>(inst));
diff --git a/libinstance/src/instanceloader.cpp b/libinstance/src/instanceloader.cpp
index eff9d56e..620562b6 100644
--- a/libinstance/src/instanceloader.cpp
+++ b/libinstance/src/instanceloader.cpp
@@ -49,7 +49,7 @@ InstanceLoader::InstTypeError InstanceLoader::registerInstanceType(InstanceTypeI
return NoError;
}
-InstanceLoader::InstTypeError InstanceLoader::createInstance(Instance *inst,
+InstanceLoader::InstTypeError InstanceLoader::createInstance(Instance *&inst,
const InstanceTypeInterface *type,
const QString &instDir)
{
@@ -61,7 +61,7 @@ InstanceLoader::InstTypeError InstanceLoader::createInstance(Instance *inst,
return type->createInstance(inst, instDir);
}
-InstanceLoader::InstTypeError InstanceLoader::loadInstance(Instance *inst,
+InstanceLoader::InstTypeError InstanceLoader::loadInstance(Instance *&inst,
const InstanceTypeInterface *type,
const QString &instDir)
{
@@ -72,7 +72,7 @@ InstanceLoader::InstTypeError InstanceLoader::loadInstance(Instance *inst,
return type->loadInstance(inst, instDir);
}
-InstanceLoader::InstTypeError InstanceLoader::loadInstance(Instance *inst,
+InstanceLoader::InstTypeError InstanceLoader::loadInstance(Instance *&inst,
const QString &instDir)
{
QFileInfo instConfig(PathCombine(instDir, "instance.cfg"));