From 055198303c7bf15f456687838c37650871596946 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 3 May 2013 14:41:37 -0500 Subject: Removed old plugin system and implemented some version list stuff. --- libmultimc/include/instance.h | 26 +++---- libmultimc/include/instanceloader.h | 66 ++---------------- libmultimc/include/instancetypeinterface.h | 4 +- libmultimc/include/instversion.h | 86 ++++++++++++++++++----- libmultimc/include/instversionlist.h | 17 ++++- libmultimc/include/minecraftversion.h | 95 ++++++++++++++++++++++++++ libmultimc/include/minecraftversionlist.h | 105 +++++++++++++++++++++++++++++ 7 files changed, 308 insertions(+), 91 deletions(-) create mode 100644 libmultimc/include/minecraftversion.h create mode 100644 libmultimc/include/minecraftversionlist.h (limited to 'libmultimc/include') diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h index 258a0dab..e72a0be3 100644 --- a/libmultimc/include/instance.h +++ b/libmultimc/include/instance.h @@ -103,6 +103,13 @@ class LIBMULTIMC_EXPORT Instance : public QObject */ Q_PROPERTY(qint64 lastLaunch READ lastLaunch WRITE setLastLaunch) + /*! + * 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 @@ -225,6 +232,9 @@ public: emit propertiesChanged(this); } + virtual qint64 lastCurrentVersionUpdate() { return settings().get("lastVersionUpdate").value(); } + virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); } + ////// Directories ////// QString minecraftDir() const; @@ -250,17 +260,7 @@ public: * \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; - - - - //////// 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; + virtual InstVersionList *versionList() const; //////// OTHER FUNCTIONS //////// @@ -274,7 +274,7 @@ public: * 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; + virtual bool shouldUpdateCurrentVersion(); /*! * \brief Updates the current version. @@ -286,7 +286,7 @@ public: * 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; + virtual void updateCurrentVersion(bool keepCurrent = false); //// Settings System //// diff --git a/libmultimc/include/instanceloader.h b/libmultimc/include/instanceloader.h index 3326d7d0..fd6d04d6 100644 --- a/libmultimc/include/instanceloader.h +++ b/libmultimc/include/instanceloader.h @@ -22,15 +22,10 @@ #include "libmmc_config.h" -class InstanceTypeInterface; class Instance; -typedef QList InstTypeList; - /*! - * \brief The InstanceLoader is a singleton that manages all of the instance types and handles loading and creating instances. - * Instance types are registered with the instance loader through its registerInstType() function. - * Creating instances is done through the InstanceLoader's createInstance() function. This function takes + * The InstanceLoader is a singleton that manages loading and creating instances. */ class LIBMULTIMC_EXPORT InstanceLoader : public QObject { @@ -46,94 +41,45 @@ public: * * - NoError indicates that no error occurred. * - OtherError indicates that an unspecified error occurred. - * - TypeIDExists is returned by registerInstanceType() if the ID of the type being registered already exists. - * - TypeNotRegistered is returned by createInstance() and loadInstance() when the given type is not registered. * - InstExists is returned by createInstance() if the given instance directory is already an instance. * - NotAnInstance is returned by loadInstance() if the given instance directory is not a valid instance. - * - WrongInstType is returned by loadInstance() if the given instance directory's type doesn't match the given type. * - CantCreateDir is returned by createInstance( if the given instance directory can't be created.) */ - enum InstTypeError + enum InstLoaderError { NoError = 0, OtherError, - TypeIDExists, - - TypeNotRegistered, InstExists, NotAnInstance, - WrongInstType, CantCreateDir }; - /*! - * \brief Registers the given InstanceType with the instance loader. - * - * \param type The InstanceType to register. - * \return An InstTypeError error code. - * - TypeIDExists if the given type's is already registered to another instance type. - */ - InstTypeError registerInstanceType(InstanceTypeInterface *type); - /*! * \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 InstTypeError error code. - * - TypeNotRegistered if the given type is not registered with the InstanceLoader. + * \return An InstLoaderError error code. * - InstExists if the given instance directory is already an instance. * - CantCreateDir if the given instance directory cannot be created. */ - InstTypeError createInstance(Instance *&inst, const InstanceTypeInterface *type, const QString &instDir); - - /*! - * \brief Loads an instance from the given directory. - * - * \param inst Pointer to store the loaded instance in. - * \param type The type of instance to load. - * \param instDir The instance's directory. - * \return An InstTypeError error code. - * - TypeNotRegistered if the given type is not registered with the InstanceLoader. - * - NotAnInstance if the given instance directory isn't a valid instance. - * - WrongInstType if the given instance directory's type isn't the same as the given type. - */ - InstTypeError loadInstance(Instance *&inst, const InstanceTypeInterface *type, const QString &instDir); + InstLoaderError createInstance(Instance *&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 InstTypeError error code. - * - TypeNotRegistered if the instance's type is not registered with the InstanceLoader. + * \return An InstLoaderError error code. * - NotAnInstance if the given instance directory isn't a valid instance. */ - InstTypeError loadInstance(Instance *&inst, const QString &instDir); - - /*! - * \brief Finds an instance type with the given ID. - * If one cannot be found, returns NULL. - * - * \param id The ID of the type to find. - * \return The type with the given ID. NULL if none were found. - */ - const InstanceTypeInterface *findType(const QString &id); - - /*! - * \brief Gets a list of the registered instance types. - * - * \return A list of instance types. - */ - InstTypeList typeList(); + InstLoaderError loadInstance(Instance *&inst, const QString &instDir); private: InstanceLoader(); - QMap m_typeMap; - static InstanceLoader loader; }; diff --git a/libmultimc/include/instancetypeinterface.h b/libmultimc/include/instancetypeinterface.h index ba13f820..4fbc2593 100644 --- a/libmultimc/include/instancetypeinterface.h +++ b/libmultimc/include/instancetypeinterface.h @@ -75,7 +75,7 @@ protected: * TypeNotRegistered if the given type is not registered with the InstanceLoader. * InstExists if the given instance directory is already an instance. */ - virtual InstanceLoader::InstTypeError createInstance(Instance *&inst, const QString &instDir) const = 0; + virtual InstanceLoader::InstLoaderError createInstance(Instance *&inst, const QString &instDir) const = 0; /*! * \brief Loads an instance from the given directory. @@ -86,7 +86,7 @@ protected: * NotAnInstance if the given instance directory isn't a valid instance. * WrongInstType if the given instance directory's type isn't an instance of this type. */ - virtual InstanceLoader::InstTypeError loadInstance(Instance *&inst, const QString &instDir) const = 0; + virtual InstanceLoader::InstLoaderError loadInstance(Instance *&inst, const QString &instDir) const = 0; }; Q_DECLARE_INTERFACE(InstanceTypeInterface, InstanceTypeInterface_IID) diff --git a/libmultimc/include/instversion.h b/libmultimc/include/instversion.h index 9d13dbe4..e91e68ba 100644 --- a/libmultimc/include/instversion.h +++ b/libmultimc/include/instversion.h @@ -22,36 +22,92 @@ class InstVersionList; +/*! + * An abstract base class for instance versions. + * InstVersions hold information about versions such as their names, identifiers, + * types, etc. + */ class LIBMULTIMC_EXPORT InstVersion : public QObject { Q_OBJECT -public: + /*! - * \brief Constructs a new InstVersion with the given parent. - * The parent *must* be the InstVersionList that contains this InstVersion. - * The InstVersion should be added to the list immediately after being created. + * A string used to identify this version in config files. + * This should be unique within the version list or shenanigans will occur. + */ + Q_PROPERTY(QString descriptor READ descriptor CONSTANT) + + /*! + * The name of this version as it is displayed to the user. + * For example: "1.5.1" + */ + Q_PROPERTY(QString name READ name) + + /*! + * The name of this version's type as it is displayed to the user. + * For example: "Latest Version", "Snapshot", or "MCNostalgia" + */ + Q_PROPERTY(QString typeName READ typeName) + + /*! + * Whether or not this is a meta version. + * Meta versions are not real versions, merely versions that act as aliases + * for other versions. + * For example: There could be a meta version called "Latest" that always + * points to the latest version. The user would pick this version and when + * a new version came out, it would point to the new one and update the instance + * automatically. */ - explicit InstVersion(InstVersionList *parent = 0); + Q_PROPERTY(bool isMeta READ isMeta) - //! Gets the string used to identify this version in config files. - virtual QString descriptor() const = 0; /*! - * \breif Returns this InstVersion's name. - * This is displayed to the user in the GUI and is usually just the version number ("1.4.7"), for example. + * Gets the version's timestamp. + * This is primarily used for sorting versions in a list. */ - virtual QString name() const = 0; + Q_PROPERTY(qint64 timestamp READ timestamp) + +public: /*! - * \brief Returns this InstVersion's type name. - * This is usually displayed to the user in the GUI and specifies what - * kind of version this is. For example: it could be "Snapshot", - * "Latest Version", "MCNostalgia", etc. + * \brief Constructs a new InstVersion with the given parent. + * The parent *must* be the InstVersionList that contains this InstVersion. + * The InstVersion will be added to the list immediately after being created. */ + explicit InstVersion(const QString &descriptor, + const QString &name, + qint64 timestamp, + InstVersionList *parent = 0); + + /*! + * Copy constructor. + * If the 'parent' parameter is not NULL, sets this version's parent to the + * specified object, rather than setting it to the same parent as the version + * we're copying from. + * \param other The version to copy. + * \param parent If not NULL, will be set as the new version object's parent. + */ + InstVersion(const InstVersion &other, QObject *parent = 0); + + virtual QString descriptor() const; + virtual QString name() const; virtual QString typeName() const = 0; + virtual qint64 timestamp() const; + virtual bool isMeta() const; - //! Returns the version list that this InstVersion is a part of. virtual InstVersionList *versionList() const; + + /*! + * Creates a copy of this version with a different parent. + * \param newParent The parent QObject of the copy. + * \return A new, identical copy of this version with the given parent set. + */ + virtual InstVersion *copyVersion(InstVersionList *newParent) const = 0; + +protected: + QString m_descriptor; + QString m_name; + qint64 m_timestamp; }; #endif // INSTVERSION_H diff --git a/libmultimc/include/instversionlist.h b/libmultimc/include/instversionlist.h index b5a9f254..1aabc5cf 100644 --- a/libmultimc/include/instversionlist.h +++ b/libmultimc/include/instversionlist.h @@ -49,7 +49,7 @@ public: explicit InstVersionList(QObject *parent = 0); /*! - * \brief Gets a task that will reload the version list. + * \brief Gets a task that will reload the version islt. * Simply execute the task to load the list. * The task returned by this function should reset the model when it's done. * \return A pointer to a task that reloads the version list. @@ -87,6 +87,21 @@ public: * By default, this is simply the first version in the list. */ virtual const InstVersion *getLatestStable(); + +protected slots: + /*! + * Updates this list with the given list of versions. + * This is done by copying each version in the given list and inserting it + * into this one. + * We need to do this so that we can set the parents of the versions are set to this + * version list. This can't be done in the load task, because the versions the load + * task creates are on the load task's thread and Qt won't allow their parents + * to be set to something created on another thread. + * To get around that problem, we invoke this method on the GUI thread, which + * then copies the versions and sets their parents correctly. + * \param versions List of versions whose parents should be set. + */ + virtual void updateListData(QList versions) = 0; }; #endif // INSTVERSIONLIST_H diff --git a/libmultimc/include/minecraftversion.h b/libmultimc/include/minecraftversion.h new file mode 100644 index 00000000..e30582ac --- /dev/null +++ b/libmultimc/include/minecraftversion.h @@ -0,0 +1,95 @@ +/* Copyright 2013 Andrew Okin + * + * 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 MINECRAFTVERSION_H +#define MINECRAFTVERSION_H + +#include "libmmc_config.h" + +#include "instversion.h" + +class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion +{ + Q_OBJECT + + /*! + * This version's type. Used internally to identify what kind of version this is. + */ + Q_PROPERTY(VersionType versionType READ versionType WRITE setVersionType) + + /*! + * The URL that this version will be downloaded from. + */ + Q_PROPERTY(QString downloadURL READ downloadURL) + + /*! + * ETag/MD5 Used to verify the integrity of the downloaded minecraft.jar. + */ + Q_PROPERTY(QString etag READ etag) + +public: + explicit MinecraftVersion(QString descriptor, + QString name, + qint64 timestamp, + QString dlUrl, + QString etag, + InstVersionList *parent = 0); + + /*! + * Creates a meta version that links to the given version. + * This is *NOT* a copy constructor. + * \param linkedVersion the version that the meta version will link to. + */ + explicit MinecraftVersion(const MinecraftVersion *linkedVersion); + + MinecraftVersion(const MinecraftVersion &other, QObject *parent); + + static InstVersion *mcnVersion(QString rawName, QString niceName); + + enum VersionType + { + OldSnapshot, + Stable, + CurrentStable, + Snapshot, + MCNostalgia, + MetaCustom, + MetaLatestSnapshot, + MetaLatestStable + }; + + virtual QString descriptor() const; + virtual QString name() const; + virtual QString typeName() const; + virtual qint64 timestamp() const; + + virtual VersionType versionType() const; + virtual void setVersionType(VersionType typeName); + + virtual QString downloadURL() const; + virtual QString etag() const; + virtual bool isMeta() const; + + virtual InstVersion *copyVersion(InstVersionList *newParent) const; + +private: + InstVersion *m_linkedVersion; + + QString m_dlUrl; + QString m_etag; + VersionType m_type; +}; + +#endif // MINECRAFTVERSION_H diff --git a/libmultimc/include/minecraftversionlist.h b/libmultimc/include/minecraftversionlist.h new file mode 100644 index 00000000..18eb4ea6 --- /dev/null +++ b/libmultimc/include/minecraftversionlist.h @@ -0,0 +1,105 @@ +/* Copyright 2013 Andrew Okin + * + * 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 MINECRAFTVERSIONLIST_H +#define MINECRAFTVERSIONLIST_H + +#include + +#include + +#include + +#include "instversionlist.h" + +#include "task.h" + +#include "minecraftversion.h" + +#include "libmmc_config.h" + +class MCVListLoadTask; + +class LIBMULTIMC_EXPORT MinecraftVersionList : public InstVersionList +{ + Q_OBJECT +public: + friend class MCVListLoadTask; + + explicit MinecraftVersionList(QObject *parent = 0); + + virtual Task *getLoadTask(); + virtual bool isLoaded(); + virtual const InstVersion *at(int i) const; + virtual int count() const; + virtual void printToStdOut() const; + + /*! + * Gets the main version list instance. + */ + static MinecraftVersionList &getMainList(); + +protected: + QListm_vlist; + + bool m_loaded; + +protected slots: + virtual void updateListData(QList versions); +}; + +class MCVListLoadTask : public Task +{ + Q_OBJECT + +public: + explicit MCVListLoadTask(MinecraftVersionList *vlist); + ~MCVListLoadTask(); + + virtual void executeTask(); + +protected: + void setSubStatus(const QString msg = ""); + + //! Loads versions from Mojang's official version list. + bool loadFromVList(); + + //! Loads versions from assets.minecraft.net. Any duplicates are ignored. + bool loadFromAssets(); + + //! Loads versions from MCNostalgia. + bool loadMCNostalgia(); + + //! Finalizes loading by updating the version list. + bool finalize(); + + void updateStuff(); + + QNetworkAccessManager *netMgr; + + MinecraftVersionList *m_list; + QList tempList; //! < List of loaded versions + QList assetsList; //! < List of versions loaded from assets.minecraft.net + QList mcnList; //! < List of loaded MCNostalgia versions + + MinecraftVersion *m_currentStable; + + bool processedMCVListReply; + bool processedAssetsReply; + bool processedMCNReply; +}; + + +#endif // MINECRAFTVERSIONLIST_H -- cgit v1.2.3