summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-02-01 03:08:25 +0100
committerPetr Mrázek <peterix@gmail.com>2015-04-12 20:57:16 +0200
commit154d19bb74f4c5fc1519aa40cd9dfd20244273a1 (patch)
tree1074077466171fa02ebc50e19ee0fc2257710401
parentc088d3bef0e18c6cd90db15720841705d53c754d (diff)
downloadMultiMC-154d19bb74f4c5fc1519aa40cd9dfd20244273a1.tar
MultiMC-154d19bb74f4c5fc1519aa40cd9dfd20244273a1.tar.gz
MultiMC-154d19bb74f4c5fc1519aa40cd9dfd20244273a1.tar.lz
MultiMC-154d19bb74f4c5fc1519aa40cd9dfd20244273a1.tar.xz
MultiMC-154d19bb74f4c5fc1519aa40cd9dfd20244273a1.zip
SCRATCH eliminate InstanceFactory
-rw-r--r--CMakeLists.txt2
-rw-r--r--MultiMC.cpp6
-rw-r--r--gui/MainWindow.cpp30
-rw-r--r--gui/dialogs/CopyInstanceDialog.cpp1
-rw-r--r--gui/dialogs/NewInstanceDialog.cpp1
-rw-r--r--logic/BaseInstance.cpp9
-rw-r--r--logic/BaseInstance.h2
-rw-r--r--logic/InstanceFactory.cpp135
-rw-r--r--logic/InstanceFactory.h100
-rw-r--r--logic/InstanceList.cpp109
-rw-r--r--logic/InstanceList.h57
-rw-r--r--logic/LegacyInstance.cpp4
-rw-r--r--logic/LegacyInstance.h3
-rw-r--r--logic/OneSixInstance.cpp5
-rw-r--r--logic/OneSixInstance.h3
-rw-r--r--logic/ftb/FTBPlugin.cpp17
-rw-r--r--logic/ftb/LegacyFTBInstance.cpp4
-rw-r--r--logic/ftb/LegacyFTBInstance.h3
-rw-r--r--logic/ftb/OneSixFTBInstance.cpp4
-rw-r--r--logic/ftb/OneSixFTBInstance.h3
-rw-r--r--logic/minecraft/MinecraftInstance.cpp6
-rw-r--r--logic/minecraft/MinecraftInstance.h2
-rw-r--r--logic/settings/SettingsObject.h2
23 files changed, 205 insertions, 303 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 60e92e8a..40bb61fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -394,8 +394,6 @@ SET(MULTIMC_SOURCES
logic/BaseVersion.h
logic/BaseProcess.h
logic/BaseProcess.cpp
- logic/InstanceFactory.h
- logic/InstanceFactory.cpp
logic/BaseInstance.h
logic/BaseInstance.cpp
logic/Mod.h
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 6a967808..0b34d606 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -205,7 +205,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
QLOG_WARN()
<< "Your instance path contains \'!\' and this is known to cause java problems";
}
- m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this));
+ m_instances.reset(new InstanceList(m_settings, InstDirSetting->get().toString(), this));
QLOG_INFO() << "Loading Instances...";
m_instances->loadList();
connect(InstDirSetting.get(), SIGNAL(SettingChanged(const Setting &, QVariant)),
@@ -577,6 +577,10 @@ QIcon MultiMC::getThemedIcon(const QString& name)
void MultiMC::onExit()
{
+ if(m_instances)
+ {
+ m_instances->saveGroupList();
+ }
if (m_updateOnExitPath.size())
{
installUpdates(m_updateOnExitPath, m_updateOnExitFlags);
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 059f6d3b..8aa2e635 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -378,7 +378,6 @@ namespace Ui {
#include "logic/BaseInstance.h"
#include "logic/OneSixInstance.h"
-#include "logic/InstanceFactory.h"
#include "logic/BaseProcess.h"
#include "logic/OneSixUpdate.h"
#include "logic/java/JavaUtils.h"
@@ -1061,7 +1060,7 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDirName = DirNameFromString(instName, instancesDir);
QString instDir = PathCombine(instancesDir, instDirName);
- auto &loader = InstanceFactory::get();
+
QString archivePath;
if (url.isLocalFile())
{
@@ -1105,15 +1104,15 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
return;
}
- auto error = loader.loadInstance(newInstance, instDir);
+ auto error = MMC->instances()->loadInstance(newInstance, instDir);
QString errorMsg = tr("Failed to load instance %1: ").arg(instDirName);
switch (error)
{
- case InstanceFactory::UnknownLoadError:
+ case InstanceList::UnknownLoadError:
errorMsg += tr("Unkown error");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
return;
- case InstanceFactory::NotAnInstance:
+ case InstanceList::NotAnInstance:
errorMsg += tr("Not an instance");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
return;
@@ -1135,20 +1134,21 @@ void MainWindow::instanceFromVersion(QString instName, QString instGroup, QStrin
QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDirName = DirNameFromString(instName, instancesDir);
QString instDir = PathCombine(instancesDir, instDirName);
- auto &loader = InstanceFactory::get();
- auto error = loader.createInstance(newInstance, version, instDir);
+ auto error = MMC->instances()->createInstance(newInstance, version, instDir);
QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName);
switch (error)
{
- case InstanceFactory::NoCreateError: break;
- case InstanceFactory::InstExists:
+ case InstanceList::NoCreateError:
+ break;
+
+ case InstanceList::InstExists:
{
errorMsg += tr("An instance with the given directory name already exists.");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
return;
}
- case InstanceFactory::CantCreateDir:
+ case InstanceList::CantCreateDir:
{
errorMsg += tr("Failed to create the instance directory.");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
@@ -1231,29 +1231,27 @@ void MainWindow::on_actionCopyInstance_triggered()
QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir);
QString instDir = PathCombine(instancesDir, instDirName);
- auto &loader = InstanceFactory::get();
-
InstancePtr newInstance;
- auto error = loader.copyInstance(newInstance, m_selectedInstance, instDir);
+ auto error = MMC->instances()->copyInstance(newInstance, m_selectedInstance, instDir);
QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName);
switch (error)
{
- case InstanceFactory::NoCreateError:
+ case InstanceList::NoCreateError:
newInstance->setName(copyInstDlg.instName());
newInstance->setGroupInitial(copyInstDlg.instGroup());
newInstance->setIconKey(copyInstDlg.iconKey());
MMC->instances()->add(newInstance);
return;
- case InstanceFactory::InstExists:
+ case InstanceList::InstExists:
{
errorMsg += tr("An instance with the given directory name already exists.");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
break;
}
- case InstanceFactory::CantCreateDir:
+ case InstanceList::CantCreateDir:
{
errorMsg += tr("Failed to create the instance directory.");
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
diff --git a/gui/dialogs/CopyInstanceDialog.cpp b/gui/dialogs/CopyInstanceDialog.cpp
index fffcee56..80418e14 100644
--- a/gui/dialogs/CopyInstanceDialog.cpp
+++ b/gui/dialogs/CopyInstanceDialog.cpp
@@ -25,7 +25,6 @@
#include "gui/dialogs/ProgressDialog.h"
#include "gui/dialogs/IconPickerDialog.h"
-#include "logic/InstanceFactory.h"
#include "logic/BaseVersion.h"
#include "logic/icons/IconList.h"
#include "logic/tasks/Task.h"
diff --git a/gui/dialogs/NewInstanceDialog.cpp b/gui/dialogs/NewInstanceDialog.cpp
index adb5c950..bba1f785 100644
--- a/gui/dialogs/NewInstanceDialog.cpp
+++ b/gui/dialogs/NewInstanceDialog.cpp
@@ -17,7 +17,6 @@
#include "NewInstanceDialog.h"
#include "ui_NewInstanceDialog.h"
-#include "logic/InstanceFactory.h"
#include "logic/BaseVersion.h"
#include "logic/icons/IconList.h"
#include "logic/minecraft/MinecraftVersionList.h"
diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp
index a073a921..ce81b90e 100644
--- a/logic/BaseInstance.cpp
+++ b/logic/BaseInstance.cpp
@@ -29,11 +29,10 @@
#include "logic/minecraft/MinecraftVersionList.h"
#include "logic/icons/IconList.h"
-BaseInstance::BaseInstance(const QString &rootDir, SettingsObject *settings, QObject *parent)
- : QObject(parent)
+BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
+ : QObject()
{
-
- m_settings = std::shared_ptr<SettingsObject>(settings);
+ m_settings = settings;
m_rootDir = rootDir;
m_settings->registerSetting("name", "Unnamed Instance");
@@ -42,8 +41,6 @@ BaseInstance::BaseInstance(const QString &rootDir, SettingsObject *settings, QOb
m_settings->registerSetting("notes", "");
m_settings->registerSetting("lastLaunchTime", 0);
- auto globalSettings = MMC->settings();
-
// Java Settings
m_settings->registerSetting("OverrideJava", false);
m_settings->registerSetting("OverrideJavaLocation", false);
diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h
index cbac701c..cd1dcdf0 100644
--- a/logic/BaseInstance.h
+++ b/logic/BaseInstance.h
@@ -51,7 +51,7 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
Q_OBJECT
protected:
/// no-touchy!
- BaseInstance(const QString &rootDir, SettingsObject *settings, QObject *parent = 0);
+ BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
public:
/// virtual destructor to make sure the destruction is COMPLETE
diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp
deleted file mode 100644
index 2f1748cc..00000000
--- a/logic/InstanceFactory.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/* Copyright 2013-2015 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 <QDir>
-#include <QFileInfo>
-
-#include "logic/settings/INIFile.h"
-#include "logic/settings/INISettingsObject.h"
-#include "logic/settings/Setting.h"
-
-#include <pathutils.h>
-#include "logger/QsLog.h"
-
-#include "logic/InstanceFactory.h"
-
-#include "logic/BaseInstance.h"
-#include "logic/LegacyInstance.h"
-#include "logic/OneSixInstance.h"
-#include "logic/OneSixInstance.h"
-#include "logic/BaseVersion.h"
-#include "logic/minecraft/MinecraftVersion.h"
-
-InstanceFactory InstanceFactory::loader;
-
-InstanceFactory::InstanceFactory() : QObject(NULL)
-{
-}
-
-InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst,
- const QString &instDir)
-{
- auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
-
- m_settings->registerSetting("InstanceType", "Legacy");
-
- QString inst_type = m_settings->get("InstanceType").toString();
-
- // FIXME: replace with a map lookup, where instance classes register their types
- if (inst_type == "OneSix" || inst_type == "Nostalgia")
- {
- inst.reset(new OneSixInstance(instDir, m_settings));
- }
- else if (inst_type == "Legacy")
- {
- inst.reset(new LegacyInstance(instDir, m_settings));
- }
- else
- {
- return InstanceFactory::UnknownLoadError;
- }
- inst->init();
- return NoLoadError;
-}
-
-InstanceFactory::InstCreateError
-InstanceFactory::createInstance(InstancePtr &inst, BaseVersionPtr version, const QString &instDir)
-{
- QDir rootDir(instDir);
-
- QLOG_DEBUG() << instDir.toUtf8();
- if (!rootDir.exists() && !rootDir.mkpath("."))
- {
- QLOG_ERROR() << "Can't create instance folder" << instDir;
- return InstanceFactory::CantCreateDir;
- }
-
- if (!version)
- {
- QLOG_ERROR() << "Can't create instance for non-existing MC version";
- return InstanceFactory::NoSuchVersion;
- }
-
- auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
- m_settings->registerSetting("InstanceType", "Legacy");
-
- auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(version);
- if(minecraftVersion)
- {
- auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version);
- m_settings->set("InstanceType", "OneSix");
- inst.reset(new OneSixInstance(instDir, m_settings));
- inst->setIntendedVersionId(version->descriptor());
- inst->init();
- return InstanceFactory::NoCreateError;
- }
- delete m_settings;
- return InstanceFactory::NoSuchVersion;
-}
-
-InstanceFactory::InstCreateError InstanceFactory::copyInstance(InstancePtr &newInstance,
- InstancePtr &oldInstance,
- const QString &instDir)
-{
- QDir rootDir(instDir);
-
- QLOG_DEBUG() << instDir.toUtf8();
- if (!copyPath(oldInstance->instanceRoot(), instDir))
- {
- rootDir.removeRecursively();
- return InstanceFactory::CantCreateDir;
- }
-
- INISettingsObject settings_obj(PathCombine(instDir, "instance.cfg"));
- settings_obj.registerSetting("InstanceType", "Legacy");
- QString inst_type = settings_obj.get("InstanceType").toString();
-
- oldInstance->copy(instDir);
-
- auto error = loadInstance(newInstance, instDir);
-
- switch (error)
- {
- case NoLoadError:
- return NoCreateError;
- case NotAnInstance:
- rootDir.removeRecursively();
- return CantCreateDir;
- default:
- case UnknownLoadError:
- rootDir.removeRecursively();
- return UnknownCreateError;
- }
-}
diff --git a/logic/InstanceFactory.h b/logic/InstanceFactory.h
deleted file mode 100644
index 17ef8f38..00000000
--- a/logic/InstanceFactory.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Copyright 2013-2015 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 <QMap>
-#include <QList>
-
-#include "BaseVersion.h"
-#include "BaseInstance.h"
-
-struct BaseVersion;
-class BaseInstance;
-
-/*!
- * The \b InstanceFactory\b is a singleton that manages loading and creating instances.
- */
-class InstanceFactory : public QObject
-{
- Q_OBJECT
-public:
- /*!
- * \brief Gets a reference to the instance loader.
- */
- static InstanceFactory &get()
- {
- return loader;
- }
-
- enum InstLoadError
- {
- NoLoadError = 0,
- UnknownLoadError,
- NotAnInstance
- };
-
- enum InstCreateError
- {
- NoCreateError = 0,
- NoSuchVersion,
- UnknownCreateError,
- InstExists,
- CantCreateDir
- };
-
- /*!
- * \brief Creates a stub instance
- *
- * \param inst Pointer to store the created instance in.
- * \param version Game version to use for the instance
- * \param instDir The new instance's directory.
- * \param type The type of instance to create
- * \return An InstCreateError error code.
- * - InstExists if the given instance directory is already an instance.
- * - CantCreateDir if the given instance directory cannot be created.
- */
- InstCreateError createInstance(InstancePtr &inst, BaseVersionPtr version,
- const QString &instDir);
-
- /*!
- * \brief Creates a copy of an existing instance with a new name
- *
- * \param newInstance Pointer to store the created instance in.
- * \param oldInstance The instance to copy
- * \param instDir The new instance's directory.
- * \return An InstCreateError error code.
- * - InstExists if the given instance directory is already an instance.
- * - CantCreateDir if the given instance directory cannot be created.
- */
- InstCreateError copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance,
- const QString &instDir);
-
- /*!
- * \brief Loads an instance from the given directory.
- * Checks the instance's INI file to figure out what the instance's type is first.
- * \param inst Pointer to store the loaded instance in.
- * \param instDir The instance's directory.
- * \return An InstLoadError error code.
- * - NotAnInstance if the given instance directory isn't a valid instance.
- */
- InstLoadError loadInstance(InstancePtr &inst, const QString &instDir);
-
-private:
- InstanceFactory();
-
- static InstanceFactory loader;
-};
diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp
index 3aaace8a..db85bcfc 100644
--- a/logic/InstanceList.cpp
+++ b/logic/InstanceList.cpp
@@ -31,18 +31,19 @@
#include "logic/icons/IconList.h"
#include "logic/minecraft/MinecraftVersionList.h"
#include "logic/BaseInstance.h"
-#include "logic/InstanceFactory.h"
-#include "ftb/FTBPlugin.h"
+#include "logic/ftb/FTBPlugin.h"
+#include "settings/INISettingsObject.h"
+#include "OneSixInstance.h"
+#include "LegacyInstance.h"
#include "logger/QsLog.h"
#include "gui/groupview/GroupView.h"
const static int GROUP_FILE_FORMAT_VERSION = 1;
-InstanceList::InstanceList(const QString &instDir, QObject *parent)
+InstanceList::InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent)
: QAbstractListModel(parent), m_instDir(instDir)
{
- connect(MMC, &MultiMC::aboutToQuit, this, &InstanceList::saveGroupList);
-
+ m_globalSettings = globalSettings;
if (!QDir::current().exists(m_instDir))
{
QDir::current().mkpath(m_instDir);
@@ -301,7 +302,7 @@ InstanceList::InstListError InstanceList::loadList()
continue;
QLOG_INFO() << "Loading MultiMC instance from " << subDir;
InstancePtr instPtr;
- auto error = InstanceFactory::get().loadInstance(instPtr, subDir);
+ auto error = loadInstance(instPtr, subDir);
if(!continueProcessInstance(instPtr, error, subDir, groupMap))
continue;
tempList.append(instPtr);
@@ -399,7 +400,7 @@ int InstanceList::getInstIndex(BaseInstance *inst) const
bool InstanceList::continueProcessInstance(InstancePtr instPtr, const int error,
const QDir &dir, QMap<QString, QString> &groupMap)
{
- if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance)
+ if (error != InstanceList::NoLoadError && error != InstanceList::NotAnInstance)
{
QString errorMsg = QString("Failed to load instance %1: ")
.arg(QFileInfo(dir.absolutePath()).baseName())
@@ -433,6 +434,100 @@ bool InstanceList::continueProcessInstance(InstancePtr instPtr, const int error,
}
}
+InstanceList::InstLoadError
+InstanceList::loadInstance(InstancePtr &inst, const QString &instDir)
+{
+ auto instanceSettings = std::make_shared<INISettingsObject>(PathCombine(instDir, "instance.cfg"));
+
+ instanceSettings->registerSetting("InstanceType", "Legacy");
+
+ QString inst_type = instanceSettings->get("InstanceType").toString();
+
+ // FIXME: replace with a map lookup, where instance classes register their types
+ if (inst_type == "OneSix" || inst_type == "Nostalgia")
+ {
+ inst.reset(new OneSixInstance(m_globalSettings, instanceSettings, instDir));
+ }
+ else if (inst_type == "Legacy")
+ {
+ inst.reset(new LegacyInstance(m_globalSettings, instanceSettings, instDir));
+ }
+ else
+ {
+ return InstanceList::UnknownLoadError;
+ }
+ inst->init();
+ return NoLoadError;
+}
+
+InstanceList::InstCreateError
+InstanceList::createInstance(InstancePtr &inst, BaseVersionPtr version, const QString &instDir)
+{
+ QDir rootDir(instDir);
+
+ QLOG_DEBUG() << instDir.toUtf8();
+ if (!rootDir.exists() && !rootDir.mkpath("."))
+ {
+ QLOG_ERROR() << "Can't create instance folder" << instDir;
+ return InstanceList::CantCreateDir;
+ }
+
+ if (!version)
+ {
+ QLOG_ERROR() << "Can't create instance for non-existing MC version";
+ return InstanceList::NoSuchVersion;
+ }
+
+ auto instanceSettings = std::make_shared<INISettingsObject>(PathCombine(instDir, "instance.cfg"));
+ instanceSettings->registerSetting("InstanceType", "Legacy");
+
+ auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(version);
+ if(minecraftVersion)
+ {
+ auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version);
+ instanceSettings->set("InstanceType", "OneSix");
+ inst.reset(new OneSixInstance(m_globalSettings, instanceSettings, instDir));
+ inst->setIntendedVersionId(version->descriptor());
+ inst->init();
+ return InstanceList::NoCreateError;
+ }
+ return InstanceList::NoSuchVersion;
+}
+
+InstanceList::InstCreateError
+InstanceList::copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, const QString &instDir)
+{
+ QDir rootDir(instDir);
+
+ QLOG_DEBUG() << instDir.toUtf8();
+ if (!copyPath(oldInstance->instanceRoot(), instDir))
+ {
+ rootDir.removeRecursively();
+ return InstanceList::CantCreateDir;
+ }
+
+ INISettingsObject settings_obj(PathCombine(instDir, "instance.cfg"));
+ settings_obj.registerSetting("InstanceType", "Legacy");
+ QString inst_type = settings_obj.get("InstanceType").toString();
+
+ oldInstance->copy(instDir);
+
+ auto error = loadInstance(newInstance, instDir);
+
+ switch (error)
+ {
+ case NoLoadError:
+ return NoCreateError;
+ case NotAnInstance:
+ rootDir.removeRecursively();
+ return CantCreateDir;
+ default:
+ case UnknownLoadError:
+ rootDir.removeRecursively();
+ return UnknownCreateError;
+ }
+}
+
void InstanceList::instanceNuked(BaseInstance *inst)
{
int i = getInstIndex(inst);
diff --git a/logic/InstanceList.h b/logic/InstanceList.h
index b7f2b997..1d52663e 100644
--- a/logic/InstanceList.h
+++ b/logic/InstanceList.h
@@ -23,7 +23,6 @@
#include "logic/BaseInstance.h"
class BaseInstance;
-
class QDir;
class InstanceList : public QAbstractListModel
@@ -37,7 +36,7 @@ slots:
void saveGroupList();
public:
- explicit InstanceList(const QString &instDir, QObject *parent = 0);
+ explicit InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent = 0);
virtual ~InstanceList();
public:
@@ -62,6 +61,22 @@ public:
UnknownError
};
+ enum InstLoadError
+ {
+ NoLoadError = 0,
+ UnknownLoadError,
+ NotAnInstance
+ };
+
+ enum InstCreateError
+ {
+ NoCreateError = 0,
+ NoSuchVersion,
+ UnknownCreateError,
+ InstExists,
+ CantCreateDir
+ };
+
QString instDir() const
{
return m_instDir;
@@ -98,6 +113,43 @@ public:
// FIXME: instead of iterating through all instances and forming a set, keep the set around
QStringList getGroups();
+
+ /*!
+ * \brief Creates a stub instance
+ *
+ * \param inst Pointer to store the created instance in.
+ * \param version Game version to use for the instance
+ * \param instDir The new instance's directory.
+ * \return An InstCreateError error code.
+ * - InstExists if the given instance directory is already an instance.
+ * - CantCreateDir if the given instance directory cannot be created.
+ */
+ InstCreateError createInstance(InstancePtr &inst, BaseVersionPtr version,
+ const QString &instDir);
+
+ /*!
+ * \brief Creates a copy of an existing instance with a new name
+ *
+ * \param newInstance Pointer to store the created instance in.
+ * \param oldInstance The instance to copy
+ * \param instDir The new instance's directory.
+ * \return An InstCreateError error code.
+ * - InstExists if the given instance directory is already an instance.
+ * - CantCreateDir if the given instance directory cannot be created.
+ */
+ InstCreateError copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance,
+ const QString &instDir);
+
+ /*!
+ * \brief Loads an instance from the given directory.
+ * Checks the instance's INI file to figure out what the instance's type is first.
+ * \param inst Pointer to store the loaded instance in.
+ * \param instDir The instance's directory.
+ * \return An InstLoadError error code.
+ * - NotAnInstance if the given instance directory isn't a valid instance.
+ */
+ InstLoadError loadInstance(InstancePtr &inst, const QString &instDir);
+
signals:
void dataIsInvalid();
@@ -127,6 +179,7 @@ protected:
QString m_instDir;
QList<InstancePtr> m_instances;
QSet<QString> m_groups;
+ SettingsObjectPtr m_globalSettings;
};
class InstanceProxyModel : public GroupedProxyModel
diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp
index 3d2a83b2..96aeff69 100644
--- a/logic/LegacyInstance.cpp
+++ b/logic/LegacyInstance.cpp
@@ -35,8 +35,8 @@
#include <gui/pages/NotesPage.h>
#include <gui/pages/ScreenshotsPage.h>
-LegacyInstance::LegacyInstance(const QString &rootDir, SettingsObject *settings, QObject *parent)
- : MinecraftInstance(rootDir, settings, parent)
+LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
+ : MinecraftInstance(globalSettings, settings, rootDir)
{
settings->registerSetting("NeedsRebuild", true);
settings->registerSetting("ShouldUpdate", false);
diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h
index de7b2bd2..5c6581c8 100644
--- a/logic/LegacyInstance.h
+++ b/logic/LegacyInstance.h
@@ -26,8 +26,7 @@ class LegacyInstance : public MinecraftInstance, public BasePageProvider
Q_OBJECT
public:
- explicit LegacyInstance(const QString &rootDir, SettingsObject *settings,
- QObject *parent = 0);
+ explicit LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
virtual void init() {};
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index 0e28ce29..95701e80 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -38,9 +38,8 @@
#include "gui/pages/NotesPage.h"
#include "gui/pages/ScreenshotsPage.h"
#include "gui/pages/OtherLogsPage.h"
-
-OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent)
- : MinecraftInstance(rootDir, settings, parent)
+OneSixInstance::OneSixInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
+ : MinecraftInstance(globalSettings, settings, rootDir)
{
m_settings->registerSetting({"IntendedVersion", "MinecraftVersion"}, "");
}
diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h
index d6593d1b..75e2dd3d 100644
--- a/logic/OneSixInstance.h
+++ b/logic/OneSixInstance.h
@@ -25,8 +25,7 @@ class OneSixInstance : public MinecraftInstance, public BasePageProvider
{
Q_OBJECT
public:
- explicit OneSixInstance(const QString &rootDir, SettingsObject *settings,
- QObject *parent = 0);
+ explicit OneSixInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
virtual ~OneSixInstance(){};
virtual void init();
diff --git a/logic/ftb/FTBPlugin.cpp b/logic/ftb/FTBPlugin.cpp
index d9c6fec6..d524e3fd 100644
--- a/logic/ftb/FTBPlugin.cpp
+++ b/logic/ftb/FTBPlugin.cpp
@@ -4,7 +4,6 @@
#include "OneSixFTBInstance.h"
#include <logic/BaseInstance.h>
#include <logic/icons/IconList.h>
-#include <logic/InstanceFactory.h>
#include <logic/InstanceList.h>
#include <logic/minecraft/MinecraftVersionList.h>
#include <logic/settings/INISettingsObject.h>
@@ -134,7 +133,7 @@ QSet<FTBRecord> discoverFTBInstances()
InstancePtr loadInstance(const QString &instDir)
{
- auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
+ auto m_settings = std::make_shared<INISettingsObject>(PathCombine(instDir, "instance.cfg"));
InstancePtr inst;
@@ -144,11 +143,11 @@ InstancePtr loadInstance(const QString &instDir)
if (inst_type == "LegacyFTB")
{
- inst.reset(new LegacyFTBInstance(instDir, m_settings));
+ inst.reset(new LegacyFTBInstance(MMC->settings(), m_settings, instDir));
}
else if (inst_type == "OneSixFTB")
{
- inst.reset(new OneSixFTBInstance(instDir, m_settings));
+ inst.reset(new OneSixFTBInstance(MMC->settings(), m_settings, instDir));
}
inst->init();
return inst;
@@ -173,19 +172,19 @@ InstancePtr createInstance(MinecraftVersionPtr version, const QString &instDir)
return nullptr;
}
- auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
+ auto m_settings = std::make_shared<INISettingsObject>(PathCombine(instDir, "instance.cfg"));
m_settings->registerSetting("InstanceType", "Legacy");
if (version->usesLegacyLauncher())
{
m_settings->set("InstanceType", "LegacyFTB");
- inst.reset(new LegacyFTBInstance(instDir, m_settings));
+ inst.reset(new LegacyFTBInstance(MMC->settings(),m_settings, instDir));
inst->setIntendedVersionId(version->descriptor());
}
else
{
m_settings->set("InstanceType", "OneSixFTB");
- inst.reset(new OneSixFTBInstance(instDir, m_settings));
+ inst.reset(new OneSixFTBInstance(MMC->settings(),m_settings, instDir));
inst->setIntendedVersionId(version->descriptor());
inst->init();
}
@@ -239,7 +238,7 @@ void FTBPlugin::loadInstances(QMap<QString, QString> &groupMap, QList<InstancePt
instPtr->setIconKey(iconKey);
instPtr->setIntendedVersionId(record.mcVersion);
instPtr->setNotes(record.description);
- if (!InstanceList::continueProcessInstance(instPtr, InstanceFactory::NoCreateError, record.instanceDir, groupMap))
+ if (!InstanceList::continueProcessInstance(instPtr, InstanceList::NoCreateError, record.instanceDir, groupMap))
continue;
tempList.append(InstancePtr(instPtr));
}
@@ -259,7 +258,7 @@ void FTBPlugin::loadInstances(QMap<QString, QString> &groupMap, QList<InstancePt
instPtr->setIntendedVersionId(record.mcVersion);
}
instPtr->setNotes(record.description);
- if (!InstanceList::continueProcessInstance(instPtr, InstanceFactory::NoCreateError, record.instanceDir, groupMap))
+ if (!InstanceList::continueProcessInstance(instPtr, InstanceList::NoCreateError, record.instanceDir, groupMap))
continue;
tempList.append(InstancePtr(instPtr));
}
diff --git a/logic/ftb/LegacyFTBInstance.cpp b/logic/ftb/LegacyFTBInstance.cpp
index bbc69e2c..43a9b42a 100644
--- a/logic/ftb/LegacyFTBInstance.cpp
+++ b/logic/ftb/LegacyFTBInstance.cpp
@@ -2,8 +2,8 @@
#include <logic/settings/INISettingsObject.h>
#include <QDir>
-LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) :
- LegacyInstance(rootDir, settings, parent)
+LegacyFTBInstance::LegacyFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) :
+ LegacyInstance(globalSettings, settings, rootDir)
{
}
diff --git a/logic/ftb/LegacyFTBInstance.h b/logic/ftb/LegacyFTBInstance.h
index e67549e1..32e85030 100644
--- a/logic/ftb/LegacyFTBInstance.h
+++ b/logic/ftb/LegacyFTBInstance.h
@@ -6,8 +6,7 @@ class LegacyFTBInstance : public LegacyInstance
{
Q_OBJECT
public:
- explicit LegacyFTBInstance(const QString &rootDir, SettingsObject *settings,
- QObject *parent = 0);
+ explicit LegacyFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
virtual QString getStatusbarDescription();
virtual QString id() const;
virtual void copy(const QDir &newDir);
diff --git a/logic/ftb/OneSixFTBInstance.cpp b/logic/ftb/OneSixFTBInstance.cpp
index 6d64ddd8..8d290a94 100644
--- a/logic/ftb/OneSixFTBInstance.cpp
+++ b/logic/ftb/OneSixFTBInstance.cpp
@@ -11,8 +11,8 @@
#include "MultiMC.h"
#include "pathutils.h"
-OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) :
- OneSixInstance(rootDir, settings, parent)
+OneSixFTBInstance::OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) :
+ OneSixInstance(globalSettings, settings, rootDir)
{
}
diff --git a/logic/ftb/OneSixFTBInstance.h b/logic/ftb/OneSixFTBInstance.h
index 4a9521e0..2b0e13d5 100644
--- a/logic/ftb/OneSixFTBInstance.h
+++ b/logic/ftb/OneSixFTBInstance.h
@@ -8,8 +8,7 @@ class OneSixFTBInstance : public OneSixInstance
{
Q_OBJECT
public:
- explicit OneSixFTBInstance(const QString &rootDir, SettingsObject *settings,
- QObject *parent = 0);
+ explicit OneSixFTBInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
virtual ~OneSixFTBInstance(){};
void copy(const QDir &newDir) override;
diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp
index 090c9389..c7edaf82 100644
--- a/logic/minecraft/MinecraftInstance.cpp
+++ b/logic/minecraft/MinecraftInstance.cpp
@@ -4,11 +4,9 @@
#include <pathutils.h>
#include "logic/minecraft/MinecraftVersionList.h"
-MinecraftInstance::MinecraftInstance(const QString &rootDir, SettingsObject *settings, QObject *parent)
- : BaseInstance(rootDir, settings, parent)
+MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
+ : BaseInstance(globalSettings, settings, rootDir)
{
- auto globalSettings = MMC->settings();
-
// Java Settings
m_settings->registerSetting("OverrideJava", false);
m_settings->registerSetting("OverrideJavaLocation", false);
diff --git a/logic/minecraft/MinecraftInstance.h b/logic/minecraft/MinecraftInstance.h
index 9097a2da..a6c786fb 100644
--- a/logic/minecraft/MinecraftInstance.h
+++ b/logic/minecraft/MinecraftInstance.h
@@ -4,7 +4,7 @@
class MinecraftInstance: public BaseInstance
{
public:
- MinecraftInstance(const QString& rootDir, SettingsObject* settings, QObject* parent = 0);
+ MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir);
virtual ~MinecraftInstance() {};
/// Path to the instance's minecraft directory.
diff --git a/logic/settings/SettingsObject.h b/logic/settings/SettingsObject.h
index f0021cdb..ac8419e8 100644
--- a/logic/settings/SettingsObject.h
+++ b/logic/settings/SettingsObject.h
@@ -175,3 +175,5 @@ protected:
private:
QMap<QString, std::shared_ptr<Setting>> m_settings;
};
+
+typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;