aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
committerPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
commit2e0cbf393a5320dbf5448ca44a9b5905314b0be8 (patch)
tree4baac9cf015ca7b15d83de33c705e0d8d4497d30 /backend
parent8808a8b108b82916eaf30f9aca50cd3ab16af230 (diff)
downloadPrismLauncher-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.gz
PrismLauncher-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.bz2
PrismLauncher-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.zip
Massive renaming in the backend folder, all around restructure in the same.
Diffstat (limited to 'backend')
-rw-r--r--backend/BaseInstance.cpp199
-rw-r--r--backend/BaseInstance.h313
-rw-r--r--backend/CMakeLists.txt91
-rw-r--r--backend/InstanceFactory.cpp61
-rw-r--r--backend/InstanceFactory.h79
-rw-r--r--backend/InstanceVersion.cpp67
-rw-r--r--backend/InstanceVersion.h121
-rw-r--r--backend/LegacyInstance.cpp0
-rw-r--r--backend/LegacyInstance.h1
-rw-r--r--backend/MinecraftProcess.cpp229
-rw-r--r--backend/MinecraftProcess.h111
-rw-r--r--backend/MinecraftVersion.cpp104
-rw-r--r--backend/MinecraftVersion.h80
-rw-r--r--backend/OneSixInstance.cpp0
-rw-r--r--backend/OneSixInstance.h1
-rw-r--r--backend/OneSixVersion.cpp91
-rw-r--r--backend/OneSixVersion.h265
-rw-r--r--backend/VersionFactory.cpp194
-rw-r--r--backend/VersionFactory.h25
-rw-r--r--backend/libmmc_config.h24
-rw-r--r--backend/lists/InstVersionList.cpp129
-rw-r--r--backend/lists/InstVersionList.h121
-rw-r--r--backend/lists/InstanceList.cpp232
-rw-r--r--backend/lists/InstanceList.h92
-rw-r--r--backend/lists/LwjglVersionList.cpp204
-rw-r--r--backend/lists/LwjglVersionList.h132
-rw-r--r--backend/lists/MinecraftVersionList.cpp528
-rw-r--r--backend/lists/MinecraftVersionList.h106
-rw-r--r--backend/tasks/GameUpdateTask.cpp283
-rw-r--r--backend/tasks/GameUpdateTask.h157
-rw-r--r--backend/tasks/LoginResponse.cpp69
-rw-r--r--backend/tasks/LoginResponse.h94
-rw-r--r--backend/tasks/LoginTask.cpp121
-rw-r--r--backend/tasks/LoginTask.h49
-rw-r--r--backend/tasks/Task.cpp83
-rw-r--r--backend/tasks/Task.h78
-rw-r--r--backend/tasks/UserInfo.cpp49
-rw-r--r--backend/tasks/UserInfo.h41
38 files changed, 4624 insertions, 0 deletions
diff --git a/backend/BaseInstance.cpp b/backend/BaseInstance.cpp
new file mode 100644
index 00000000..c2ffa664
--- /dev/null
+++ b/backend/BaseInstance.cpp
@@ -0,0 +1,199 @@
+/* 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 "BaseInstance.h"
+
+#include <QFileInfo>
+
+#include "inisettingsobject.h"
+#include "setting.h"
+#include "overridesetting.h"
+
+#include "pathutils.h"
+#include <lists/MinecraftVersionList.h>
+
+BaseInstance::BaseInstance(const QString &rootDir, QObject *parent) :
+ QObject(parent)
+{
+ m_rootDir = rootDir;
+ m_settings = new INISettingsObject(PathCombine(rootDir, "instance.cfg"), this);
+
+ settings().registerSetting(new Setting("name", "Unnamed Instance"));
+ settings().registerSetting(new Setting("iconKey", "default"));
+ settings().registerSetting(new Setting("notes", ""));
+ settings().registerSetting(new Setting("NeedsRebuild", true));
+ settings().registerSetting(new Setting("ShouldUpdate", false));
+ settings().registerSetting(new Setting("JarVersion", "Unknown"));
+ settings().registerSetting(new Setting("LwjglVersion", "2.9.0"));
+ settings().registerSetting(new Setting("IntendedJarVersion", ""));
+ settings().registerSetting(new Setting("lastLaunchTime", 0));
+
+ // Java Settings
+ settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath")));
+ settings().registerSetting(new OverrideSetting("JvmArgs", globalSettings->getSetting("JvmArgs")));
+
+ // Custom Commands
+ settings().registerSetting(new OverrideSetting("PreLaunchCommand",
+ globalSettings->getSetting("PreLaunchCommand")));
+ settings().registerSetting(new OverrideSetting("PostExitCommand",
+ globalSettings->getSetting("PostExitCommand")));
+
+ // Window Size
+ settings().registerSetting(new OverrideSetting("LaunchCompatMode", globalSettings->getSetting("LaunchCompatMode")));
+ settings().registerSetting(new OverrideSetting("LaunchMaximized", globalSettings->getSetting("LaunchMaximized")));
+ settings().registerSetting(new OverrideSetting("MinecraftWinWidth", globalSettings->getSetting("MinecraftWinWidth")));
+ settings().registerSetting(new OverrideSetting("MinecraftWinHeight", globalSettings->getSetting("MinecraftWinHeight")));
+
+ // Memory
+ settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc")));
+ settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc")));
+
+ // Auto login
+ settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin")));
+
+ // Console
+ settings().registerSetting(new OverrideSetting("ShowConsole", globalSettings->getSetting("ShowConsole")));
+ settings().registerSetting(new OverrideSetting("AutoCloseConsole", globalSettings->getSetting("AutoCloseConsole")));
+
+ // Overrides
+ settings().registerSetting(new Setting("OverrideConsole", false));
+ settings().registerSetting(new Setting("OverrideWindow", false));
+ settings().registerSetting(new Setting("OverrideLogin", false));
+ settings().registerSetting(new Setting("OverrideMemory", false));
+ settings().registerSetting(new Setting("OverrideJava", false));
+ settings().registerSetting(new Setting("OverrideCommands", false));
+}
+
+QString BaseInstance::id() const
+{
+ return QFileInfo(rootDir()).fileName();
+}
+
+QString BaseInstance::rootDir() const
+{
+ return m_rootDir;
+}
+
+InstanceList *BaseInstance::instList() const
+{
+ if (parent()->inherits("InstanceList"))
+ return (InstanceList *)parent();
+ else
+ return NULL;
+}
+
+QString BaseInstance::minecraftDir() const
+{
+ QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
+ QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
+
+ if (dotMCDir.exists() && !mcDir.exists())
+ return dotMCDir.filePath();
+ else
+ return mcDir.filePath();
+}
+
+QString BaseInstance::instModsDir() const
+{
+ return PathCombine(rootDir(), "instMods");
+}
+
+QString BaseInstance::binDir() const
+{
+ return PathCombine(minecraftDir(), "bin");
+}
+
+QString BaseInstance::savesDir() const
+{
+ return PathCombine(minecraftDir(), "saves");
+}
+
+QString BaseInstance::mlModsDir() const
+{
+ return PathCombine(minecraftDir(), "mods");
+}
+
+QString BaseInstance::coreModsDir() const
+{
+ return PathCombine(minecraftDir(), "coremods");
+}
+
+QString BaseInstance::resourceDir() const
+{
+ return PathCombine(minecraftDir(), "resources");
+}
+
+QString BaseInstance::screenshotsDir() const
+{
+ return PathCombine(minecraftDir(), "screenshots");
+}
+
+QString BaseInstance::texturePacksDir() const
+{
+ return PathCombine(minecraftDir(), "texturepacks");
+}
+
+QString BaseInstance::mcJar() const
+{
+ return PathCombine(binDir(), "minecraft.jar");
+}
+
+QString BaseInstance::mcBackup() const
+{
+ return PathCombine(binDir(), "mcbackup.jar");
+}
+
+QString BaseInstance::modListFile() const
+{
+ return PathCombine(rootDir(), "modlist");
+}
+
+InstVersionList *BaseInstance::versionList() const
+{
+ return &MinecraftVersionList::getMainList();
+}
+
+bool BaseInstance::shouldUpdateCurrentVersion() const
+{
+ QFileInfo jar(mcJar());
+ return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate();
+}
+
+void BaseInstance::updateCurrentVersion(bool keepCurrent)
+{
+ QFileInfo jar(mcJar());
+
+ if(!jar.exists())
+ {
+ setLastCurrentVersionUpdate(0);
+ setCurrentVersion("Unknown");
+ return;
+ }
+
+ qint64 time = jar.lastModified().toUTC().toMSecsSinceEpoch();
+
+ setLastCurrentVersionUpdate(time);
+ if (!keepCurrent)
+ {
+ // TODO: Implement GetMinecraftJarVersion function.
+ QString newVersion = "Unknown";//javautils::GetMinecraftJarVersion(jar.absoluteFilePath());
+ setCurrentVersion(newVersion);
+ }
+}
+
+SettingsObject &BaseInstance::settings() const
+{
+ return *m_settings;
+}
diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h
new file mode 100644
index 00000000..51f55b5e
--- /dev/null
+++ b/backend/BaseInstance.h
@@ -0,0 +1,313 @@
+/* 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 <QDateTime>
+
+#include <settingsobject.h>
+
+#include "inifile.h"
+#include "lists/InstVersionList.h"
+
+#include "libmmc_config.h"
+
+class InstanceList;
+
+/*!
+ * \brief Base class for instances.
+ * This class implements many functions that are common between instances and
+ * provides a standard interface for all instances.
+ *
+ * To create a new instance type, create a new class inheriting from this class
+ * and implement the pure virtual functions.
+ */
+class LIBMULTIMC_EXPORT BaseInstance : public QObject
+{
+ Q_OBJECT
+
+ // Properties
+ /*!
+ * The instance's ID.
+ * This is a unique identifier string that is, by default, set to the
+ * instance's folder name. It's not always the instance's folder name,
+ * however, as any class deriving from Instance can override the id()
+ * method and change how the ID is determined. The instance's ID should
+ * always remain constant. Undefined behavior results if an already loaded
+ * instance's ID changes.
+ */
+ Q_PROPERTY(QString id READ id STORED false)
+
+ //! Path to the instance's root directory.
+ Q_PROPERTY(QString rootDir READ rootDir)
+
+ //! The name of the instance that is displayed to the user.
+ Q_PROPERTY(QString name READ name WRITE setName)
+
+ //! The instance's icon key.
+ Q_PROPERTY(QString iconKey READ iconKey WRITE setIconKey)
+
+ //! The instance's notes.
+ Q_PROPERTY(QString notes READ notes WRITE setNotes)
+
+ //! The instance's group.
+ Q_PROPERTY(QString group READ group WRITE setGroup)
+
+ /*!
+ * Gets the time that the instance was last launched.
+ * Stored in milliseconds since epoch.
+ * This value is usually used for things like sorting instances by the time
+ * they were last launched.
+ */
+ Q_PROPERTY(qint64 lastLaunch READ lastLaunch WRITE setLastLaunch)
+
+ /*!
+ * Whether or not the instance's minecraft.jar needs to be rebuilt.
+ * If this is true, when the instance launches, its jar mods will be
+ * re-added to a fresh minecraft.jar file.
+ */
+ Q_PROPERTY(bool shouldRebuild READ shouldRebuild WRITE setShouldRebuild)
+
+ /*!
+ * Whether or not Minecraft should be downloaded when the instance is launched.
+ * This returns true if shouldForceUpdate game is true or if the intended and
+ * current versions don't match.
+ */
+ Q_PROPERTY(bool shouldUpdate READ shouldUpdate WRITE setShouldUpdate)
+
+ /*!
+ * The instance's current version.
+ * This value represents the instance's current version. If this value is
+ * different from the intendedVersion, the instance should be updated.
+ * \warning Don't change this value unless you know what you're doing.
+ */
+ Q_PROPERTY(QString currentVersion READ currentVersion WRITE setCurrentVersion)
+
+ /*!
+ * The version that the user has set for this instance to use.
+ * If this is not the same as currentVersion, the instance's game updater
+ * will be run on launch.
+ */
+ Q_PROPERTY(QString intendedVersion READ intendedVersion WRITE setIntendedVersion)
+
+ //! The version of LWJGL that this instance uses.
+ Q_PROPERTY(QString lwjglVersion READ lwjglVersion WRITE setLWJGLVersion)
+
+
+ /*!
+ * Gets the last time that the current version was checked.
+ * This is checked against the last modified time on the jar file to see if
+ * the current version needs to be checked again.
+ */
+ Q_PROPERTY(qint64 lastCurrentVersionUpdate READ lastCurrentVersionUpdate WRITE setLastCurrentVersionUpdate)
+
+ // Dirs
+ //! Path to the instance's .minecraft folder.
+ Q_PROPERTY(QString minecraftDir READ minecraftDir STORED false)
+
+ //! Path to the instance's instMods folder.
+ Q_PROPERTY(QString instModsDir READ instModsDir STORED false)
+
+ //! Path to the instance's bin folder.
+ Q_PROPERTY(QString binDir READ binDir STORED false)
+
+ //! Path to the instance's saves folder.
+ Q_PROPERTY(QString savesDir READ savesDir STORED false)
+
+ //! Path to the instance's mods folder (.minecraft/mods)
+ Q_PROPERTY(QString mlModsDir READ mlModsDir STORED false)
+
+ //! Path to the instance's coremods folder.
+ Q_PROPERTY(QString coreModsDir READ coreModsDir STORED false)
+
+ //! Path to the instance's resources folder.
+ Q_PROPERTY(QString resourceDir READ resourceDir STORED false)
+
+ //! Path to the instance's screenshots folder.
+ Q_PROPERTY(QString screenshotsDir READ screenshotsDir STORED false)
+
+ //! Path to the instance's texturepacks folder.
+ Q_PROPERTY(QString texturePacksDir READ texturePacksDir STORED false)
+
+
+ // Files
+ //! Path to the instance's minecraft.jar
+ Q_PROPERTY(QString mcJar READ mcJar STORED false)
+
+ //! Path to the instance's mcbackup.jar
+ Q_PROPERTY(QString mcBackup READ mcBackup STORED false)
+
+ //! Path to the instance's modlist file.
+ Q_PROPERTY(QString modListFile READ modListFile STORED false)
+
+public:
+ explicit BaseInstance(const QString &rootDir, QObject *parent = 0);
+
+ //////// STUFF ////////
+ virtual QString id() const;
+
+ virtual QString rootDir() const;
+
+ /*!
+ * \brief Gets the instance list that this instance is a part of.
+ * Returns NULL if this instance is not in a list
+ * (the parent is not an InstanceList).
+ * \return A pointer to the InstanceList containing this instance.
+ */
+ virtual InstanceList *instList() const;
+
+
+ //////// INSTANCE INFO ////////
+
+ //// General Info ////
+ virtual QString name() const { return settings().get("name").toString(); }
+ virtual void setName(QString val)
+ {
+ settings().set("name", val);
+ emit propertiesChanged(this);
+ }
+
+ virtual QString iconKey() const { return settings().get("iconKey").toString(); }
+ virtual void setIconKey(QString val)
+ {
+ settings().set("iconKey", val);
+ emit propertiesChanged(this);
+ }
+
+ virtual QString notes() const { return settings().get("notes").toString(); }
+ virtual void setNotes(QString val) { settings().set("notes", val); }
+
+ virtual QString group() const { return m_group; }
+ virtual void setGroup(QString val)
+ {
+ m_group = val;
+ emit propertiesChanged(this);
+ }
+
+ virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
+ virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
+
+
+ //// Version Stuff ////
+
+ virtual QString currentVersion() const { return settings().get("JarVersion").toString(); }
+ virtual void setCurrentVersion(QString val) { settings().set("JarVersion", val); }
+
+ virtual QString lwjglVersion() const { return settings().get("LwjglVersion").toString(); }
+ virtual void setLWJGLVersion(QString val) { settings().set("LwjglVersion", val); }
+
+ virtual QString intendedVersion() const { return settings().get("IntendedJarVersion").toString(); }
+ virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); }
+
+ virtual bool shouldUpdate() const
+ {
+ QVariant var = settings().get("ShouldUpdate");
+ if(!var.isValid() || var.toBool() == false)
+ {
+ return intendedVersion() != currentVersion();
+ }
+ return true;
+ }
+ virtual void setShouldUpdate(bool val) { settings().set("ShouldUpdate", val); }
+
+ //// Timestamps ////
+
+ virtual qint64 lastLaunch() const { return settings().get("lastLaunchTime").value<qint64>(); }
+ virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
+ {
+ settings().set("lastLaunchTime", val);
+ emit propertiesChanged(this);
+ }
+
+ virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); }
+ virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); }
+
+ ////// Directories //////
+ QString minecraftDir() const;
+ QString instModsDir() const;
+ QString binDir() const;
+ QString savesDir() const;
+ QString mlModsDir() const;
+ QString coreModsDir() const;
+ QString resourceDir() const;
+ QString screenshotsDir() const;
+ QString texturePacksDir() const;
+
+
+ ////// Files //////
+ QString mcJar() const;
+ QString mcBackup() const;
+ QString modListFile() const;
+
+
+ //////// LISTS, LISTS, AND MORE LISTS ////////
+ /*!
+ * \brief Gets a pointer to this instance's version list.
+ * \return A pointer to the available version list for this instance.
+ */
+ virtual InstVersionList *versionList() const;
+
+
+ //////// OTHER FUNCTIONS ////////
+
+ //// Version System ////
+
+ /*!
+ * \brief Checks whether or not the currentVersion of the instance needs to be updated.
+ * If this returns true, updateCurrentVersion is called. In the
+ * standard instance, this is determined by checking a timestamp
+ * stored in the instance config file against the last modified time of Minecraft.jar.
+ * \return True if updateCurrentVersion() should be called.
+ */
+ virtual bool shouldUpdateCurrentVersion() const;
+
+ /*!
+ * \brief Updates the current version.
+ * This function should first set the current version timestamp
+ * (setCurrentVersionTimestamp()) to the current time. Next, if
+ * keepCurrent is false, this function should check what the
+ * instance's current version is and call setCurrentVersion() to
+ * update it. This function will automatically be called when the
+ * instance is loaded if shouldUpdateCurrentVersion returns true.
+ * \param keepCurrent If true, only the version timestamp will be updated.
+ */
+ virtual void updateCurrentVersion(bool keepCurrent = false);
+
+
+ //// Settings System ////
+
+ /*!
+ * \brief Gets this instance's settings object.
+ * This settings object stores instance-specific settings.
+ * \return A pointer to this instance's settings object.
+ */
+ virtual SettingsObject &settings() const;
+
+signals:
+ /*!
+ * \brief Signal emitted when properties relevant to the instance view change
+ */
+ void propertiesChanged(BaseInstance * inst);
+
+private:
+ QString m_rootDir;
+ QString m_group;
+ SettingsObject *m_settings;
+};
+
+// pointer for lazy people
+typedef QSharedPointer<BaseInstance> InstancePtr;
+
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
new file mode 100644
index 00000000..a17b7dfe
--- /dev/null
+++ b/backend/CMakeLists.txt
@@ -0,0 +1,91 @@
+project(libMultiMC)
+
+set(CMAKE_AUTOMOC ON)
+
+# Find Qt
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Network REQUIRED)
+find_package(Qt5Xml REQUIRED)
+
+# Include Qt headers.
+include_directories(${Qt5Base_INCLUDE_DIRS})
+include_directories(${Qt5Network_INCLUDE_DIRS})
+
+# Include utility library.
+include_directories(${CMAKE_SOURCE_DIR}/libutil/include)
+
+# Include settings library.
+include_directories(${CMAKE_SOURCE_DIR}/libsettings/include)
+
+SET(LIBINST_HEADERS
+libmmc_config.h
+
+# Instance Stuff
+BaseInstance.h
+LegacyInstance.h
+OneSixInstance.h
+InstanceFactory.h
+
+# Versions
+InstanceVersion.h
+MinecraftVersion.h
+OneSixVersion.h
+VersionFactory.h
+
+# Lists
+lists/InstanceList.h
+lists/InstVersionList.h
+lists/MinecraftVersionList.h
+lists/LwjglVersionList.h
+
+# Tasks
+tasks/Task.h
+tasks/LoginTask.h
+tasks/LoginResponse.h
+tasks/UserInfo.h
+tasks/GameUpdateTask.h
+
+MinecraftProcess.h
+)
+
+SET(LIBINST_SOURCES
+# Instance Stuff
+BaseInstance.cpp
+LegacyInstance.cpp
+OneSixInstance.cpp
+InstanceFactory.cpp
+
+# Versions
+InstanceVersion.cpp
+MinecraftVersion.cpp
+OneSixVersion.cpp
+VersionFactory.cpp
+
+# Lists
+lists/InstanceList.cpp
+lists/InstVersionList.cpp
+lists/MinecraftVersionList.cpp
+lists/LwjglVersionList.cpp
+
+# Tasks
+tasks/Task.cpp
+tasks/LoginTask.cpp
+tasks/GameUpdateTask.cpp
+tasks/UserInfo.cpp
+tasks/LoginResponse.cpp
+
+MinecraftProcess.cpp
+)
+
+# Set the include dir path.
+SET(LIBMULTIMC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE)
+
+# Include self.
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_BINARY_DIR}/include)
+
+add_definitions(-DLIBMULTIMC_LIBRARY)
+
+add_library(backend SHARED ${LIBINST_SOURCES} ${LIBINST_HEADERS})
+qt5_use_modules(backend Core Network Xml)
+target_link_libraries(backend libUtil libSettings)
diff --git a/backend/InstanceFactory.cpp b/backend/InstanceFactory.cpp
new file mode 100644
index 00000000..318650ae
--- /dev/null
+++ b/backend/InstanceFactory.cpp
@@ -0,0 +1,61 @@
+/* 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 "InstanceFactory.h"
+
+#include <QDir>
+#include <QFileInfo>
+
+#include "BaseInstance.h"
+
+#include "inifile.h"
+
+#include "pathutils.h"
+
+InstanceFactory InstanceFactory::loader;
+
+InstanceFactory::InstanceFactory() :
+ QObject(NULL)
+{
+
+}
+
+InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst, const QString &instDir)
+{
+ BaseInstance *loadedInst = new BaseInstance(instDir, this);
+
+ // TODO: Sanity checks to verify that the instance is valid.
+
+ inst = loadedInst;
+
+ return NoLoadError;
+}
+
+
+InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&inst, const QString &instDir)
+{
+ QDir rootDir(instDir);
+
+ qDebug(instDir.toUtf8());
+ if (!rootDir.exists() && !rootDir.mkpath("."))
+ {
+ return InstanceFactory::CantCreateDir;
+ }
+
+ inst = new BaseInstance(instDir, this);
+
+ //FIXME: really, how do you even know?
+ return InstanceFactory::NoCreateError;
+}
diff --git a/backend/InstanceFactory.h b/backend/InstanceFactory.h
new file mode 100644
index 00000000..0dd4c5d8
--- /dev/null
+++ b/backend/InstanceFactory.h
@@ -0,0 +1,79 @@
+/* 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 <QMap>
+#include <QList>
+
+#include "libmmc_config.h"
+
+class BaseInstance;
+
+/*!
+ * The \bInstanceFactory\b is a singleton that manages loading and creating instances.
+ */
+class LIBMULTIMC_EXPORT 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,
+ UnknownCreateError,
+ InstExists,
+ CantCreateDir
+ };
+
+ /*!
+ * \brief Creates an instance with the given type and stores it in inst.
+ *
+ * \param inst Pointer to store the created instance in.
+ * \param type The type of instance to create.
+ * \param instDir The 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(BaseInstance *&inst, 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(BaseInstance *&inst, const QString &instDir);
+
+private:
+ InstanceFactory();
+
+ static InstanceFactory loader;
+};
diff --git a/backend/InstanceVersion.cpp b/backend/InstanceVersion.cpp
new file mode 100644
index 00000000..1b9b0a5b
--- /dev/null
+++ b/backend/InstanceVersion.cpp
@@ -0,0 +1,67 @@
+/* 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 "InstanceVersion.h"
+#include "lists/InstVersionList.h"
+
+InstVersion::InstVersion(const QString &descriptor,
+ const QString &name,
+ qint64 timestamp,
+ InstVersionList *parent) :