2013-02-15 10:10:00 +05:30
|
|
|
/* 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-26 02:14:36 +05:30
|
|
|
#include <settingsobject.h>
|
|
|
|
|
2013-02-21 06:40:09 +05:30
|
|
|
#include "inifile.h"
|
2013-03-07 00:02:15 +05:30
|
|
|
#include "instancetypeinterface.h"
|
2013-03-09 01:26:26 +05:30
|
|
|
#include "instversionlist.h"
|
2013-02-21 06:40:09 +05:30
|
|
|
|
2013-02-27 04:17:39 +05:30
|
|
|
#include "libmmc_config.h"
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
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-27 04:17:39 +05:30
|
|
|
class LIBMULTIMC_EXPORT Instance : public QObject
|
2013-02-15 10:10:00 +05:30
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-02-19 02:20:11 +05:30
|
|
|
explicit Instance(const QString &rootDir, QObject *parent = 0);
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
|
|
//////// STUFF ////////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Get 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.
|
|
|
|
*
|
|
|
|
* \return The instance's ID.
|
|
|
|
*/
|
2013-02-21 06:40:09 +05:30
|
|
|
virtual QString id() const;
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the path to the instance's root directory.
|
|
|
|
* \return The path to the instance's root directory.
|
|
|
|
*/
|
2013-02-21 06:40:09 +05:30
|
|
|
virtual QString rootDir() const;
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \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 06:40:09 +05:30
|
|
|
virtual InstanceList *instList() const;
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
2013-02-26 04:06:27 +05:30
|
|
|
//////// INSTANCE INFO ////////
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
//// General Info ////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets this instance's name.
|
|
|
|
* This is the name that will be displayed to the user.
|
|
|
|
* \return The instance's name.
|
|
|
|
* \sa setName
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual QString name() { return settings().get("name").toString(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the instance's name
|
|
|
|
* \param val The instance's new name.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setName(QString val) { settings().set("name", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the instance's icon key.
|
|
|
|
* \return The instance's icon key.
|
|
|
|
* \sa setIconKey()
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual QString iconKey() const { return settings().get("iconKey").toString(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the instance's icon key.
|
|
|
|
* \param val The new icon key.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setIconKey(QString val) { settings().set("iconKey", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the instance's notes.
|
|
|
|
* \return The instances notes.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual QString notes() const { return settings().get("notes").toString(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the instance's notes.
|
|
|
|
* \param val The instance's new notes.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setNotes(QString val) { settings().set("notes", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Checks if the instance's minecraft.jar needs to be rebuilt.
|
|
|
|
* If this is true, the instance's mods will be reinstalled to its
|
|
|
|
* minecraft.jar file. This value is automatically set to true when
|
|
|
|
* the jar mod list changes.
|
|
|
|
* \return Whether or not the instance's jar file should be rebuilt.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets whether or not the instance's minecraft.jar needs to be rebuilt.
|
|
|
|
* \param val Whether the instance's minecraft needs to be rebuilt or not.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
//// Version Stuff ////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the instance's current version.
|
|
|
|
* This value represents the instance's current version. If this value
|
|
|
|
* is different from intendedVersion(), the instance should be updated.
|
|
|
|
* This value is updated by the updateCurrentVersion() function.
|
|
|
|
* \return A string representing the instance's current version.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual QString currentVersion() { return settings().get("JarVersion").toString(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the instance's current version.
|
|
|
|
* This is used to keep track of the instance's current version. Don't
|
|
|
|
* mess with this unless you know what you're doing.
|
|
|
|
* \param val The new value.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setCurrentVersion(QString val) { settings().set("JarVersion", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the version of LWJGL that this instance should use.
|
|
|
|
* If no LWJGL version is specified in the instance's config file,
|
|
|
|
* defaults to "Mojang"
|
|
|
|
* \return The instance's LWJGL version.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual QString lwjglVersion() { return settings().get("LwjglVersion").toString(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the version of LWJGL that this instance should use.
|
|
|
|
* \param val The LWJGL version to use
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setLWJGLVersion(QString val) { settings().set("LwjglVersion", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the version that this instance should try to update to.
|
|
|
|
* If this value differs from currentVersion(), the instance will
|
|
|
|
* download the intended version when it launches.
|
|
|
|
* \return The instance's intended version.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual QString intendedVersion() { return settings().get("IntendedJarVersion").toString(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the version that this instance should try to update to.
|
|
|
|
* \param val The instance's new intended version.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// Timestamps ////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the time that the instance was last launched.
|
|
|
|
* Measured in milliseconds since epoch. QDateTime::currentMSecsSinceEpoch()
|
|
|
|
* \return The time that the instance was last launched.
|
|
|
|
*/
|
2013-02-26 04:06:27 +05:30
|
|
|
virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value<qint64>(); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the time that the instance was last launched.
|
|
|
|
* \param val The time to set. Defaults to QDateTime::currentMSecsSinceEpoch()
|
|
|
|
*/
|
|
|
|
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
|
2013-02-26 04:06:27 +05:30
|
|
|
{ settings().set("lastLaunchTime", val); }
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
|
2013-02-20 20:02:26 +05:30
|
|
|
////// Directories //////
|
|
|
|
//! Gets the path to the instance's minecraft folder.
|
|
|
|
QString minecraftDir() const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Gets the path to the instance's instance mods folder.
|
|
|
|
* This is the folder where the jar mods are kept.
|
|
|
|
*/
|
|
|
|
QString instModsDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's bin folder.
|
|
|
|
QString binDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's saves folder.
|
|
|
|
QString savesDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's mods folder. (.minecraft/mods)
|
|
|
|
QString mlModsDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's coremods folder.
|
|
|
|
QString coreModsDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's resources folder.
|
|
|
|
QString resourceDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's screenshots folder.
|
|
|
|
QString screenshotsDir() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's texture packs folder.
|
|
|
|
QString texturePacksDir() const;
|
|
|
|
|
|
|
|
|
|
|
|
////// Files //////
|
|
|
|
//! Gets the path to the instance's minecraft.jar
|
|
|
|
QString mcJar() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's mcbackup.jar.
|
|
|
|
QString mcBackup() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's config file.
|
|
|
|
QString configFile() const;
|
|
|
|
|
|
|
|
//! Gets the path to the instance's modlist file.
|
|
|
|
QString modListFile() const;
|
|
|
|
|
2013-02-15 10:10:00 +05:30
|
|
|
|
2013-03-07 00:02:15 +05:30
|
|
|
|
2013-03-09 01:26:26 +05:30
|
|
|
//////// 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 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-07 00:02:15 +05:30
|
|
|
//////// INSTANCE TYPE STUFF ////////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns a pointer to this instance's type.
|
|
|
|
* \return A pointer to this instance's type interface.
|
|
|
|
*/
|
|
|
|
virtual const InstanceTypeInterface *instanceType() const = 0;
|
|
|
|
|
|
|
|
|
2013-02-15 10:10:00 +05:30
|
|
|
//////// 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() = 0;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \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) = 0;
|
|
|
|
|
2013-02-26 02:14:36 +05:30
|
|
|
|
|
|
|
//// 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-26 04:06:27 +05:30
|
|
|
virtual SettingsObject &settings() const;
|
2013-02-15 10:10:00 +05:30
|
|
|
|
|
|
|
private:
|
2013-02-19 02:20:11 +05:30
|
|
|
QString m_rootDir;
|
2013-02-26 04:06:27 +05:30
|
|
|
SettingsObject *m_settings;
|
2013-02-15 10:10:00 +05:30
|
|
|
};
|
|
|
|
|
2013-02-22 20:47:31 +05:30
|
|
|
// pointer for lazy people
|
|
|
|
typedef QSharedPointer<Instance> InstancePtr;
|
|
|
|
|
2013-02-15 10:10:00 +05:30
|
|
|
#endif // INSTANCE_H
|