aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-03 15:57:33 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-03 15:57:33 +0200
commit13b1b98f7cf8a3b3b2c15dd42f96537b02c00711 (patch)
treeff3a67221e90eb9aa067e0b0d1f934fd4dd28534
parent2e0cbf393a5320dbf5448ca44a9b5905314b0be8 (diff)
downloadPrismLauncher-13b1b98f7cf8a3b3b2c15dd42f96537b02c00711.tar.gz
PrismLauncher-13b1b98f7cf8a3b3b2c15dd42f96537b02c00711.tar.bz2
PrismLauncher-13b1b98f7cf8a3b3b2c15dd42f96537b02c00711.zip
WTF, I don't even...
-rw-r--r--AppSettings.cpp1
-rw-r--r--AppVersion.cpp8
-rw-r--r--AppVersion.h8
-rw-r--r--backend/BaseInstance.cpp163
-rw-r--r--backend/BaseInstance.h270
-rw-r--r--backend/BaseInstance_p.h14
-rw-r--r--backend/CMakeLists.txt2
-rw-r--r--backend/InstanceFactory.cpp27
-rw-r--r--backend/InstanceFactory.h3
-rw-r--r--backend/LegacyInstance.cpp233
-rw-r--r--backend/LegacyInstance.h104
-rw-r--r--backend/LegacyInstance_p.h10
-rw-r--r--backend/MinecraftProcess.cpp97
-rw-r--r--backend/MinecraftProcess.h35
-rw-r--r--backend/MinecraftVersion.cpp14
-rw-r--r--backend/MinecraftVersion.h14
-rw-r--r--backend/OneSixInstance.cpp18
-rw-r--r--backend/OneSixInstance.h12
-rw-r--r--backend/OneSixInstance_p.h8
-rw-r--r--backend/lists/MinecraftVersionList.cpp152
-rw-r--r--backend/lists/MinecraftVersionList.h6
-rw-r--r--backend/tasks/GameUpdateTask.cpp81
-rw-r--r--backend/tasks/GameUpdateTask.h2
-rw-r--r--gui/instancemodel.cpp2
-rw-r--r--gui/instancesettings.cpp16
-rw-r--r--gui/mainwindow.cpp43
-rw-r--r--gui/mainwindow.h4
-rw-r--r--gui/settingsdialog.cpp2
-rw-r--r--main.cpp11
29 files changed, 610 insertions, 750 deletions
diff --git a/AppSettings.cpp b/AppSettings.cpp
index 835d42ac..9a4cb99f 100644
--- a/AppSettings.cpp
+++ b/AppSettings.cpp
@@ -47,7 +47,6 @@ AppSettings::AppSettings(QObject *parent) :
// registerSetting(new Setting("StdErrColor", QColor(Qt::red)));
// Window Size
- registerSetting(new Setting("LaunchCompatMode", false));
registerSetting(new Setting("LaunchMaximized", false));
registerSetting(new Setting("MinecraftWinWidth", 854));
registerSetting(new Setting("MinecraftWinHeight", 480));
diff --git a/AppVersion.cpp b/AppVersion.cpp
index 2db3da26..86b00920 100644
--- a/AppVersion.cpp
+++ b/AppVersion.cpp
@@ -17,9 +17,9 @@
#include "config.h"
-Version Version::current(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD);
+AppVersion AppVersion::current(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD);
-Version::Version(int major, int minor, int revision, int build, QObject *parent) :
+AppVersion::AppVersion(int major, int minor, int revision, int build, QObject *parent) :
QObject(parent)
{
this->major = major;
@@ -28,7 +28,7 @@ Version::Version(int major, int minor, int revision, int build, QObject *parent)
this->build = build;
}
-Version::Version(const Version& ver)
+AppVersion::AppVersion(const AppVersion& ver)
{
this->major = ver.major;
this->minor = ver.minor;
@@ -36,7 +36,7 @@ Version::Version(const Version& ver)
this->build = ver.build;
}
-QString Version::toString() const
+QString AppVersion::toString() const
{
return QString("%1.%2.%3.%4").arg(
QString::number(major),
diff --git a/AppVersion.h b/AppVersion.h
index 504f1d17..86f53950 100644
--- a/AppVersion.h
+++ b/AppVersion.h
@@ -20,14 +20,14 @@
/*!
* \brief The Version class represents a MultiMC version number.
*/
-class Version : public QObject
+class AppVersion : public QObject
{
Q_OBJECT
public:
- explicit Version(int major = 0, int minor = 0, int revision = 0,
+ explicit AppVersion(int major = 0, int minor = 0, int revision = 0,
int build = 0, QObject *parent = 0);
- Version(const Version& ver);
+ AppVersion(const AppVersion& ver);
/*!
* \brief Converts the Version to a string.
@@ -60,6 +60,6 @@ public:
*/
int build;
- static Version current;
+ static AppVersion current;
};
diff --git a/backend/BaseInstance.cpp b/backend/BaseInstance.cpp
index c2ffa664..d94f3de9 100644
--- a/backend/BaseInstance.cpp
+++ b/backend/BaseInstance.cpp
@@ -14,6 +14,7 @@
*/
#include "BaseInstance.h"
+#include "BaseInstance_p.h"
#include <QFileInfo>
@@ -24,56 +25,52 @@
#include "pathutils.h"
#include <lists/MinecraftVersionList.h>
-BaseInstance::BaseInstance(const QString &rootDir, QObject *parent) :
- QObject(parent)
+
+BaseInstance::BaseInstance( BaseInstancePrivate* d_in,
+ const QString& rootDir,
+ SettingsObject* settings_obj,
+ QObject* parent
+ )
+:inst_d(d_in), QObject(parent)
{
- m_rootDir = rootDir;
- m_settings = new INISettingsObject(PathCombine(rootDir, "instance.cfg"), this);
+ I_D(BaseInstance);
+ d->m_settings = settings_obj;
+ d->m_rootDir = rootDir;
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 Setting("OverrideJava", false));
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")));
+ settings().registerSetting(new Setting("OverrideCommands", false));
+ 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 Setting("OverrideWindow", false));
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 Setting("OverrideMemory", false));
settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc")));
settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc")));
// Auto login
+ settings().registerSetting(new Setting("OverrideLogin", false));
settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin")));
// Console
+ settings().registerSetting(new Setting("OverrideConsole", false));
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
@@ -81,9 +78,17 @@ QString BaseInstance::id() const
return QFileInfo(rootDir()).fileName();
}
+QString BaseInstance::instanceType() const
+{
+ I_D(BaseInstance);
+ return d->m_settings->get("InstanceType").toString();
+}
+
+
QString BaseInstance::rootDir() const
{
- return m_rootDir;
+ I_D(BaseInstance);
+ return d->m_rootDir;
}
InstanceList *BaseInstance::instList() const
@@ -94,106 +99,72 @@ InstanceList *BaseInstance::instList() const
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
+InstVersionList *BaseInstance::versionList() const
{
- return PathCombine(minecraftDir(), "bin");
+ return &MinecraftVersionList::getMainList();
}
-QString BaseInstance::savesDir() const
+SettingsObject &BaseInstance::settings() const
{
- return PathCombine(minecraftDir(), "saves");
+ I_D(BaseInstance);
+ return *d->m_settings;
}
-QString BaseInstance::mlModsDir() const
+qint64 BaseInstance::lastLaunch() const
{
- return PathCombine(minecraftDir(), "mods");
+ I_D(BaseInstance);
+ return d->m_settings->get ( "lastLaunchTime" ).value<qint64>();
}
-
-QString BaseInstance::coreModsDir() const
+void BaseInstance::setLastLaunch ( qint64 val )
{
- return PathCombine(minecraftDir(), "coremods");
+ I_D(BaseInstance);
+ d->m_settings->set ( "lastLaunchTime", val );
+ emit propertiesChanged ( this );
}
-QString BaseInstance::resourceDir() const
+void BaseInstance::setGroup ( QString val )
{
- return PathCombine(minecraftDir(), "resources");
+ I_D(BaseInstance);
+ d->m_group = val;
+ emit propertiesChanged ( this );
}
-
-QString BaseInstance::screenshotsDir() const
+QString BaseInstance::group() const
{
- return PathCombine(minecraftDir(), "screenshots");
+ I_D(BaseInstance);
+ return d->m_group;
}
-QString BaseInstance::texturePacksDir() const
+void BaseInstance::setNotes ( QString val )
{
- return PathCombine(minecraftDir(), "texturepacks");
+ I_D(BaseInstance);
+ d->m_settings->set ( "notes", val );
}
-
-QString BaseInstance::mcJar() const
+QString BaseInstance::notes() const
{
- return PathCombine(binDir(), "minecraft.jar");
+ I_D(BaseInstance);
+ return d->m_settings->get ( "notes" ).toString();
}
-QString BaseInstance::mcBackup() const
+void BaseInstance::setIconKey ( QString val )
{
- return PathCombine(binDir(), "mcbackup.jar");
+ I_D(BaseInstance);
+ d->m_settings->set ( "iconKey", val );
+ emit propertiesChanged ( this );
}
-
-QString BaseInstance::modListFile() const
+QString BaseInstance::iconKey() const
{
- return PathCombine(rootDir(), "modlist");
+ I_D(BaseInstance);
+ return d->m_settings->get ( "iconKey" ).toString();
}
-InstVersionList *BaseInstance::versionList() const
+void BaseInstance::setName ( QString val )
{
- return &MinecraftVersionList::getMainList();
+ I_D(BaseInstance);
+ d->m_settings->set ( "name", val );
+ emit propertiesChanged ( this );
}
-
-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
+QString BaseInstance::name() const
{
- return *m_settings;
+ I_D(BaseInstance);
+ return d->m_settings->get ( "name" ).toString();
}
diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h
index 51f55b5e..088075f2 100644
--- a/backend/BaseInstance.h
+++ b/backend/BaseInstance.h
@@ -25,7 +25,10 @@
#include "libmmc_config.h"
+class MinecraftProcess;
+class GameUpdateTask;
class InstanceList;
+class BaseInstancePrivate;
/*!
* \brief Base class for instances.
@@ -38,128 +41,21 @@ class InstanceList;
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)
-
+protected:
+ /// no-touchy!
+ BaseInstance(BaseInstancePrivate * d, const QString &rootDir, SettingsObject * settings, QObject *parent = 0);
public:
- explicit BaseInstance(const QString &rootDir, QObject *parent = 0);
+ /// virtual destructor to make sure the destruction is COMPLETE
+ virtual ~BaseInstance() {};
+
+ /// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to be unique.
+ QString id() const;
- //////// STUFF ////////
- virtual QString id() const;
+ /// get the type of this instance
+ QString instanceType() const;
- virtual QString rootDir() const;
+ /// Path to the instance's root directory.
+ QString rootDir() const;
/*!
* \brief Gets the instance list that this instance is a part of.
@@ -167,128 +63,52 @@ public:
* (the parent is not an InstanceList).
* \return A pointer to the InstanceList containing this instance.
*/
- virtual InstanceList *instList() const;
+ 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);
- }
+ /// The name of the instance that is displayed to the user.
+ QString name() const;
- virtual QString notes() const { return settings().get("notes").toString(); }
- virtual void setNotes(QString val) { settings().set("notes", val); }
+ /// Set the name of the instance that is displayed to the user.
+ void setName(QString val);
- virtual QString group() const { return m_group; }
- virtual void setGroup(QString val)
- {
- m_group = val;
- emit propertiesChanged(this);
- }
+ /// The instance's icon key.
+ QString iconKey() const;
- virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
- virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
+ /// Set the instance's icon key.
+ void setIconKey(QString val);
+ //! The instance's notes.
+ QString notes() const;
- //// Version Stuff ////
-
- virtual QString currentVersion() const { return settings().get("JarVersion").toString(); }
- virtual void setCurrentVersion(QString val) { settings().set("JarVersion", val); }
+ /// set the instance notes text
+ void setNotes(QString val);
- virtual QString lwjglVersion() const { return settings().get("LwjglVersion").toString(); }
- virtual void setLWJGLVersion(QString val) { settings().set("LwjglVersion", val); }
+ //! The instance's group.
+ QString group() const;
- virtual QString intendedVersion() const { return settings().get("IntendedJarVersion").toString(); }
- virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); }
+ /// set the instance group
+ void setGroup(QString 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;
+ /**
+ * Gets the time that the instance was last launched.
+ * Stored in milliseconds since epoch.
+ */
+ qint64 lastLaunch() const;
+ /// Sets the last launched time to 'val' milliseconds since epoch
+ void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch());
- //////// 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.
@@ -296,16 +116,20 @@ public:
*/
virtual SettingsObject &settings() const;
+ /// returns a valid update task if update is needed, NULL otherwise
+ virtual GameUpdateTask* doUpdate() = 0;
+
+ /// returns a valid minecraft process, ready for launch
+ virtual MinecraftProcess* prepareForLaunch(QString user, QString session) = 0;
+
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;
+protected:
+ QSharedPointer<BaseInstancePrivate> inst_d;
};
// pointer for lazy people
diff --git a/backend/BaseInstance_p.h b/backend/BaseInstance_p.h
new file mode 100644
index 00000000..a30916a4
--- /dev/null
+++ b/backend/BaseInstance_p.h
@@ -0,0 +1,14 @@
+#pragma once
+#include <QString>
+#include <settingsobject.h>
+
+class BaseInstance;
+
+#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.data()
+
+struct BaseInstancePrivate
+{
+ QString m_rootDir;
+ QString m_group;
+ SettingsObject *m_settings;
+}; \ No newline at end of file
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index a17b7dfe..9bd07c01 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -89,3 +89,5 @@ 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
index 318650ae..ee582d3f 100644
--- a/backend/InstanceFactory.cpp
+++ b/backend/InstanceFactory.cpp
@@ -19,8 +19,12 @@
#include <QFileInfo>
#include "BaseInstance.h"
+#include "LegacyInstance.h"
+#include "OneSixInstance.h"
#include "inifile.h"
+#include <inisettingsobject.h>
+#include <setting.h>
#include "pathutils.h"
@@ -34,12 +38,25 @@ InstanceFactory::InstanceFactory() :
InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst, const QString &instDir)
{
- BaseInstance *loadedInst = new BaseInstance(instDir, this);
+ auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
- // TODO: Sanity checks to verify that the instance is valid.
+ m_settings->registerSetting(new Setting("InstanceType", "Legacy"));
- inst = loadedInst;
+ QString inst_type = m_settings->get("InstanceType").toString();
+ //FIXME: replace with a map lookup, where instance classes register their types
+ if(inst_type == "Legacy")
+ {
+ inst = new LegacyInstance(instDir, m_settings, this);
+ }
+ else if(inst_type == "OneSix")
+ {
+ inst = new OneSixInstance(instDir, m_settings, this);
+ }
+ else
+ {
+ return InstanceFactory::UnknownLoadError;
+ }
return NoLoadError;
}
@@ -53,8 +70,8 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&
{
return InstanceFactory::CantCreateDir;
}
-
- inst = new BaseInstance(instDir, this);
+ return InstanceFactory::UnknownCreateError;
+ //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
index 0dd4c5d8..26857ef9 100644
--- a/backend/InstanceFactory.h
+++ b/backend/InstanceFactory.h
@@ -51,10 +51,9 @@ public:
};
/*!
- * \brief Creates an instance with the given type and stores it in inst.
+ * \brief Creates a stub instance
*
* \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.
diff --git a/backend/LegacyInstance.cpp b/backend/LegacyInstance.cpp
index e69de29b..001400e5 100644
--- a/backend/LegacyInstance.cpp
+++ b/backend/LegacyInstance.cpp
@@ -0,0 +1,233 @@
+#include "LegacyInstance.h"
+#include "LegacyInstance_p.h"
+#include "MinecraftProcess.h"
+#include <setting.h>
+#include <pathutils.h>
+#include <cmdutils.h>
+#include <QFileInfo>
+#include <QDir>
+#include <QImage>
+
+#define LAUNCHER_FILE "MultiMCLauncher.jar"
+
+LegacyInstance::LegacyInstance(const QString& rootDir, SettingsObject* settings, QObject* parent)
+ :BaseInstance( new LegacyInstancePrivate(),rootDir, settings, parent)
+{
+ 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", ""));
+}
+
+QString LegacyInstance::minecraftDir() const
+{
+ QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
+ QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
+
+ if (dotMCDir.exists() && !mcDir.exists())
+ return dotMCDir.filePath();
+ else
+ return mcDir.filePath();
+}
+
+GameUpdateTask* LegacyInstance::doUpdate()
+{
+ // legacy instances no longer update
+ return nullptr;
+}
+
+MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session)
+{
+ MinecraftProcess * proc = new MinecraftProcess(this);
+
+ // FIXME: extract the icon
+ // QImage(":/icons/instances/" + iconKey()).save(PathCombine(minecraftDir(), "icon.png"));
+
+ // extract the legacy launcher
+ QFile(":/launcher/launcher.jar").copy(PathCombine(minecraftDir(), LAUNCHER_FILE));
+
+ // set the process arguments
+ {
+ QStringList args;
+
+ // window size
+ QString windowSize;
+ if (settings().get("LaunchMaximized").toBool())
+ windowSize = "