2013-02-15 04:40:00 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INSTANCE_H
|
|
|
|
#define INSTANCE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDateTime>
|
|
|
|
|
2013-02-25 20:44:36 +00:00
|
|
|
#include <settingsobject.h>
|
|
|
|
|
2013-02-21 01:10:09 +00:00
|
|
|
#include "inifile.h"
|
2013-03-06 18:32:15 +00:00
|
|
|
#include "instancetypeinterface.h"
|
2013-03-08 19:56:26 +00:00
|
|
|
#include "instversionlist.h"
|
2013-02-21 01:10:09 +00:00
|
|
|
|
2013-02-26 22:47:39 +00:00
|
|
|
#include "libmmc_config.h"
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-02-26 22:47:39 +00:00
|
|
|
class LIBMULTIMC_EXPORT Instance : public QObject
|
2013-02-15 04:40:00 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2013-03-13 18:13:28 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
2013-03-18 22:35:54 +00:00
|
|
|
//! The instance's group.
|
|
|
|
Q_PROPERTY(QString group READ group WRITE setGroup)
|
|
|
|
|
2013-03-13 18:13:28 +00:00
|
|
|
/*!
|
|
|
|
* 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)
|
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
/*!
|
|
|
|
* 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 shouldUpdateGame READ shouldUpdateGame STORED false)
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Whether or not the game will be forced to update on the next launch.
|
|
|
|
* If this is set to true, shouldUpdateGame will be true, regardless of whether or not
|
|
|
|
* the current and intended versions match.
|
|
|
|
* It should be noted that this is set to false automatically when game updates are run.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(bool shouldForceUpdateGame READ shouldForceUpdateGame WRITE setShouldForceUpdateGame)
|
|
|
|
|
2013-03-13 18:13:28 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* 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 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)
|
|
|
|
|
2013-05-03 19:41:37 +00:00
|
|
|
/*!
|
|
|
|
* 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)
|
|
|
|
|
2013-03-13 18:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 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 config file.
|
|
|
|
Q_PROPERTY(QString configFile READ configFile STORED false)
|
|
|
|
|
|
|
|
//! Path to the instance's modlist file.
|
|
|
|
Q_PROPERTY(QString modListFile READ modListFile STORED false)
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
public:
|
2013-02-18 20:50:11 +00:00
|
|
|
explicit Instance(const QString &rootDir, QObject *parent = 0);
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
// Please, for the sake of my (and everyone else's) sanity, at least keep this shit
|
|
|
|
// *somewhat* organized. Also, documentation is semi-important here. Please don't
|
|
|
|
// leave undocumented stuff behind.
|
2013-03-13 18:13:28 +00:00
|
|
|
// As a side-note, doxygen processes comments for accessor functions and
|
|
|
|
// properties separately, so please document properties in the massive block of
|
|
|
|
// Q_PROPERTY declarations above rather than documenting their accessors.
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
//////// STUFF ////////
|
2013-02-21 01:10:09 +00:00
|
|
|
virtual QString id() const;
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-02-21 01:10:09 +00:00
|
|
|
virtual QString rootDir() const;
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \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.
|
|
|
|
*/
|
2013-02-21 01:10:09 +00:00
|
|
|
virtual InstanceList *instList() const;
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
|
2013-02-25 22:36:27 +00:00
|
|
|
//////// INSTANCE INFO ////////
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
//// General Info ////
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual QString name() const { return settings().get("name").toString(); }
|
2013-03-19 05:24:34 +00:00
|
|
|
virtual void setName(QString val)
|
|
|
|
{
|
|
|
|
settings().set("name", val);
|
|
|
|
emit propertiesChanged(this);
|
|
|
|
}
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual QString iconKey() const { return settings().get("iconKey").toString(); }
|
2013-03-19 05:24:34 +00:00
|
|
|
virtual void setIconKey(QString val)
|
|
|
|
{
|
|
|
|
settings().set("iconKey", val);
|
|
|
|
emit propertiesChanged(this);
|
|
|
|
}
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual QString notes() const { return settings().get("notes").toString(); }
|
|
|
|
virtual void setNotes(QString val) { settings().set("notes", val); }
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-03-18 22:35:54 +00:00
|
|
|
virtual QString group() const { return m_group; }
|
2013-03-19 05:24:34 +00:00
|
|
|
virtual void setGroup(QString val)
|
|
|
|
{
|
|
|
|
m_group = val;
|
|
|
|
emit propertiesChanged(this);
|
|
|
|
}
|
2013-03-18 22:35:54 +00:00
|
|
|
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
|
|
|
|
virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
//// Version Stuff ////
|
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual QString currentVersion() const { return settings().get("JarVersion").toString(); }
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual void setCurrentVersion(QString val) { settings().set("JarVersion", val); }
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual QString lwjglVersion() const { return settings().get("LwjglVersion").toString(); }
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual void setLWJGLVersion(QString val) { settings().set("LwjglVersion", val); }
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual QString intendedVersion() const { return settings().get("IntendedJarVersion").toString(); }
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); }
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual bool shouldUpdateGame() const
|
|
|
|
{ return shouldForceUpdateGame() || intendedVersion() != currentVersion(); }
|
|
|
|
|
|
|
|
virtual bool shouldForceUpdateGame() const { return settings().get("ShouldForceUpdate").toBool(); }
|
|
|
|
virtual void setShouldForceUpdateGame(bool val) { settings().set("ShouldForceUpdate", val); }
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
//// Timestamps ////
|
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual qint64 lastLaunch() const { return settings().get("lastLaunchTime").value<qint64>(); }
|
2013-02-15 04:40:00 +00:00
|
|
|
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
|
2013-03-19 05:24:34 +00:00
|
|
|
{
|
|
|
|
settings().set("lastLaunchTime", val);
|
|
|
|
emit propertiesChanged(this);
|
|
|
|
}
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); }
|
2013-05-03 19:41:37 +00:00
|
|
|
virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); }
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-02-20 14:32:26 +00:00
|
|
|
////// 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 configFile() const;
|
|
|
|
QString modListFile() const;
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-03-08 19:56:26 +00:00
|
|
|
//////// 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.
|
|
|
|
*/
|
2013-05-03 19:41:37 +00:00
|
|
|
virtual InstVersionList *versionList() const;
|
2013-03-06 18:32:15 +00:00
|
|
|
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
//////// 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.
|
|
|
|
*/
|
2013-05-08 17:56:43 +00:00
|
|
|
virtual bool shouldUpdateCurrentVersion() const;
|
2013-02-15 04:40:00 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \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.
|
|
|
|
*/
|
2013-05-03 19:41:37 +00:00
|
|
|
virtual void updateCurrentVersion(bool keepCurrent = false);
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-02-25 20:44:36 +00:00
|
|
|
|
|
|
|
//// 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.
|
|
|
|
*/
|
2013-02-25 22:36:27 +00:00
|
|
|
virtual SettingsObject &settings() const;
|
2013-02-15 04:40:00 +00:00
|
|
|
|
2013-03-19 05:24:34 +00:00
|
|
|
signals:
|
|
|
|
/*!
|
|
|
|
* \brief Signal emitted when properties relevant to the instance view change
|
|
|
|
*/
|
|
|
|
void propertiesChanged(Instance * inst);
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
private:
|
2013-02-18 20:50:11 +00:00
|
|
|
QString m_rootDir;
|
2013-03-18 22:35:54 +00:00
|
|
|
QString m_group;
|
2013-02-25 22:36:27 +00:00
|
|
|
SettingsObject *m_settings;
|
2013-02-15 04:40:00 +00:00
|
|
|
};
|
|
|
|
|
2013-02-22 15:17:31 +00:00
|
|
|
// pointer for lazy people
|
|
|
|
typedef QSharedPointer<Instance> InstancePtr;
|
|
|
|
|
2013-02-15 04:40:00 +00:00
|
|
|
#endif // INSTANCE_H
|