summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-11 18:58:24 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-11 19:05:22 +0200
commit7e78a422e8bb22572706b7fadb58fc45e7b8a7db (patch)
treee91e2aa3364d1a5cb8329a6b7e49b7a46e720ab5
parente5dc113bfceb1e9b52535b7d1abd6f0ec51e1332 (diff)
downloadMultiMC-7e78a422e8bb22572706b7fadb58fc45e7b8a7db.tar
MultiMC-7e78a422e8bb22572706b7fadb58fc45e7b8a7db.tar.gz
MultiMC-7e78a422e8bb22572706b7fadb58fc45e7b8a7db.tar.lz
MultiMC-7e78a422e8bb22572706b7fadb58fc45e7b8a7db.tar.xz
MultiMC-7e78a422e8bb22572706b7fadb58fc45e7b8a7db.zip
Version filtering and general related code sanitization.
Version list dialog has alternating row background set. Nostalgia versions, based on OneSix.
-rw-r--r--backend/CMakeLists.txt8
-rw-r--r--backend/InstanceFactory.cpp39
-rw-r--r--backend/InstanceFactory.h4
-rw-r--r--backend/InstanceVersion.cpp67
-rw-r--r--backend/InstanceVersion.h114
-rw-r--r--backend/MinecraftVersion.cpp93
-rw-r--r--backend/MinecraftVersion.h83
-rw-r--r--backend/NostalgiaInstance.cpp12
-rw-r--r--backend/NostalgiaInstance.h10
-rw-r--r--backend/OneSixUpdate.cpp6
-rw-r--r--backend/OneSixUpdate.h2
-rw-r--r--backend/OneSixVersion.h7
-rw-r--r--backend/VersionFactory.cpp15
-rw-r--r--backend/VersionFactory.h1
-rw-r--r--backend/lists/InstVersionList.cpp22
-rw-r--r--backend/lists/InstVersionList.h11
-rw-r--r--backend/lists/MinecraftVersionList.cpp126
-rw-r--r--backend/lists/MinecraftVersionList.h15
-rw-r--r--gui/mainwindow.cpp2
-rw-r--r--gui/newinstancedialog.cpp13
-rw-r--r--gui/newinstancedialog.h10
-rw-r--r--gui/versionselectdialog.cpp10
-rw-r--r--gui/versionselectdialog.h4
-rw-r--r--gui/versionselectdialog.ui3
24 files changed, 250 insertions, 427 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index 0d0df5e5..68d01f08 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -47,6 +47,9 @@ OneSixUpdate.h
OneSixVersion.h
VersionFactory.h
+# Nostalgia
+NostalgiaInstance.h
+
# Lists
lists/InstanceList.h
lists/InstVersionList.h
@@ -61,8 +64,6 @@ tasks/LoginTask.h
SET(LIBINST_SOURCES
# Base classes and infrastructure
-InstanceVersion.cpp
-MinecraftVersion.cpp
InstanceFactory.cpp
BaseUpdate.cpp
BaseInstance.cpp
@@ -83,6 +84,9 @@ OneSixVersion.cpp
OneSixUpdate.cpp
VersionFactory.cpp
+# Nostalgia
+NostalgiaInstance.cpp
+
# Lists
lists/InstanceList.cpp
lists/InstVersionList.cpp
diff --git a/backend/InstanceFactory.cpp b/backend/InstanceFactory.cpp
index f3636da3..f3511157 100644
--- a/backend/InstanceFactory.cpp
+++ b/backend/InstanceFactory.cpp
@@ -21,7 +21,9 @@
#include "BaseInstance.h"
#include "LegacyInstance.h"
#include "OneSixInstance.h"
+#include "NostalgiaInstance.h"
#include "InstanceVersion.h"
+#include "MinecraftVersion.h"
#include "inifile.h"
#include <inisettingsobject.h>
@@ -54,6 +56,10 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst
{
inst = new OneSixInstance(instDir, m_settings, this);
}
+ else if(inst_type == "Nostalgia")
+ {
+ inst = new NostalgiaInstance(instDir, m_settings, this);
+ }
else
{
return InstanceFactory::UnknownLoadError;
@@ -62,7 +68,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst
}
-InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, const InstVersion* version, const QString& instDir )
+InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, InstVersionPtr version, const QString& instDir )
{
QDir rootDir(instDir);
@@ -71,14 +77,37 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*&
{
return InstanceFactory::CantCreateDir;
}
+ auto mcVer = version.dynamicCast<MinecraftVersion>();
+ if(!mcVer)
+ return InstanceFactory::NoSuchVersion;
auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
m_settings->registerSetting(new Setting("InstanceType", "Legacy"));
- m_settings->set("InstanceType", "OneSix");
- inst = new OneSixInstance(instDir, m_settings, this);
- inst->setIntendedVersionId(version->descriptor());
-
+ switch(mcVer->type)
+ {
+ case MinecraftVersion::Legacy:
+ m_settings->set("InstanceType", "Legacy");
+ inst = new LegacyInstance(instDir, m_settings, this);
+ inst->setIntendedVersionId(version->descriptor);
+ break;
+ case MinecraftVersion::OneSix:
+ m_settings->set("InstanceType", "OneSix");
+ inst = new OneSixInstance(instDir, m_settings, this);
+ inst->setIntendedVersionId(version->descriptor);
+ break;
+ case MinecraftVersion::Nostalgia:
+ m_settings->set("InstanceType", "Nostalgia");
+ inst = new NostalgiaInstance(instDir, m_settings, this);
+ inst->setIntendedVersionId(version->descriptor);
+ break;
+ default:
+ {
+ delete m_settings;
+ return InstanceFactory::NoSuchVersion;
+ }
+ }
+
//FIXME: really, how do you even know?
return InstanceFactory::NoCreateError;
}
diff --git a/backend/InstanceFactory.h b/backend/InstanceFactory.h
index 12139e7d..e1100504 100644
--- a/backend/InstanceFactory.h
+++ b/backend/InstanceFactory.h
@@ -20,6 +20,7 @@
#include <QList>
#include "libmmc_config.h"
+#include "InstanceVersion.h"
class InstVersion;
class BaseInstance;
@@ -46,6 +47,7 @@ public:
enum InstCreateError
{
NoCreateError = 0,
+ NoSuchVersion,
UnknownCreateError,
InstExists,
CantCreateDir
@@ -60,7 +62,7 @@ public:
* - InstExists if the given instance directory is already an instance.
* - CantCreateDir if the given instance directory cannot be created.
*/
- InstCreateError createInstance(BaseInstance *&inst, const InstVersion * version, const QString &instDir);
+ InstCreateError createInstance(BaseInstance *&inst, InstVersionPtr version, const QString &instDir);
/*!
* \brief Loads an instance from the given directory.
diff --git a/backend/InstanceVersion.cpp b/backend/InstanceVersion.cpp
deleted file mode 100644
index 1b9b0a5b..00000000
--- a/backend/InstanceVersion.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 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) :
- QObject(parent), m_descriptor(descriptor), m_name(name), m_timestamp(timestamp)
-{
-
-}
-
-InstVersion::InstVersion(const InstVersion &other, QObject *parent) :
- QObject(parent ? parent : other.parent()),
- m_descriptor(other.descriptor()), m_name(other.name()), m_timestamp(other.timestamp())
-{
-
-}
-
-InstVersionList *InstVersion::versionList() const
-{
- // Parent should *always* be either an InstVersionList or NULL.
- if (!parent() || !parent()->inherits("InstVersionList"))
- return NULL;
- else
- return (InstVersionList *)parent();
-}
-
-bool InstVersion::isLessThan(const InstVersion &other) const
-{
- return timestamp() < other.timestamp();
-}
-
-bool InstVersion::isGreaterThan(const InstVersion &other) const
-{
- return timestamp() > other.timestamp();
-}
-
-QString InstVersion::descriptor() const
-{
- return m_descriptor;
-}
-
-QString InstVersion::name() const
-{
- return m_name;
-}
-
-qint64 InstVersion::timestamp() const
-{
- return m_timestamp;
-}
diff --git a/backend/InstanceVersion.h b/backend/InstanceVersion.h
index 5ebae41e..aeff9842 100644
--- a/backend/InstanceVersion.h
+++ b/backend/InstanceVersion.h
@@ -14,108 +14,56 @@
*/
#pragma once
-
-#include <QObject>
-
#include "libmmc_config.h"
-
-class InstVersionList;
+#include <QSharedPointer>
/*!
- * An abstract base class for instance versions.
- * InstVersions hold information about versions such as their names, identifiers,
- * types, etc.
+ * An abstract base class for versions.
*/
-class LIBMULTIMC_EXPORT InstVersion : public QObject
+struct LIBMULTIMC_EXPORT InstVersion
{
- Q_OBJECT
-
- /*!
- * 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)
-
- /*!
- * Gets the version's timestamp.
- * This is primarily used for sorting versions in a list.
- */
- Q_PROPERTY(qint64 timestamp READ timestamp)
-
-
-public:
- /*!
- * \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 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;
-
/*!
* Checks if this version is less (older) than the given version.
* \param other The version to compare this one to.
* \return True if this version is older than the given version.
*/
- virtual bool isLessThan(const InstVersion &other) const;
-
+ virtual bool operator<(const InstVersion &rhs) const
+ {
+ return timestamp < rhs.timestamp;
+ }
+
/*!
* Checks if this version is greater (newer) than the given version.
* \param other The version to compare this one to.
* \return True if this version is newer than the given version.
*/
- virtual bool isGreaterThan(const InstVersion &other) const;
+ virtual bool operator>( const InstVersion& rhs ) const
+ {
+ return timestamp > rhs.timestamp;
+ }
/*!
- * \sa shouldSortBefore()
+ * A string used to identify this version in config files.
+ * This should be unique within the version list or shenanigans will occur.
*/
- virtual bool operator<(const InstVersion &rhs) { return isLessThan(rhs); }
-
+ QString descriptor;
/*!
- * \sa shouldSortAfter()
+ * The name of this version as it is displayed to the user.
+ * For example: "1.5.1"
*/
- virtual bool operator>(const InstVersion &rhs) { return isGreaterThan(rhs); }
+ QString name;
+ /*!
+ * Gets the version's timestamp.
+ * This is primarily used for sorting versions in a list.
+ */
+ qint64 timestamp;
-protected:
- QString m_descriptor;
- QString m_name;
- qint64 m_timestamp;
+ virtual QString typeString() const
+ {
+ return "InstVersion";
+ }
};
+
+typedef QSharedPointer<InstVersion> InstVersionPtr;
+
+Q_DECLARE_METATYPE( InstVersionPtr ) \ No newline at end of file
diff --git a/backend/MinecraftVersion.cpp b/backend/MinecraftVersion.cpp
deleted file mode 100644
index fdaf0712..00000000
--- a/backend/MinecraftVersion.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/* 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.
- */
-
-#include "MinecraftVersion.h"
-
-MinecraftVersion::MinecraftVersion(QString descriptor,
- QString name,
- qint64 timestamp,
- QString dlUrl,
- QString etag,
- InstVersionList *parent) :
- InstVersion(descriptor, name, timestamp, parent), m_dlUrl(dlUrl), m_etag(etag)
-{
-}
-
-QString MinecraftVersion::descriptor() const
-{
- return m_descriptor;
-}
-
-QString MinecraftVersion::name() const
-{
- return m_name;
-}
-
-QString MinecraftVersion::typeName() const
-{
- switch (versionType())
- {
- case OldSnapshot:
- return "Snapshot";
-
- case Stable:
- return "Stable";
-
- case CurrentStable:
- return "Current Stable";
-
- case Snapshot:
- return "Snapshot";
-
- case Nostalgia:
- return "Nostalgia";
-
- default:
- return QString("Unknown Type %1").arg(versionType());
- }
-}
-
-qint64 MinecraftVersion::timestamp() const
-{
- return m_timestamp;
-}
-
-MinecraftVersion::VersionType MinecraftVersion::versionType() const
-{
- return m_type;
-}
-
-void MinecraftVersion::setVersionType(MinecraftVersion::VersionType typeName)
-{
- m_type = typeName;
-}
-
-QString MinecraftVersion::downloadURL() const
-{
- return m_dlUrl;
-}
-
-QString MinecraftVersion::etag() const
-{
- return m_etag;
-}
-
-InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
-{
- MinecraftVersion *version = new MinecraftVersion(
- descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
- version->setVersionType(versionType());
- return version;
-}
diff --git a/backend/MinecraftVersion.h b/backend/MinecraftVersion.h
index f5cf9805..5cd29925 100644
--- a/backend/MinecraftVersion.h
+++ b/backend/MinecraftVersion.h
@@ -18,50 +18,61 @@
#include "libmmc_config.h"
#include "InstanceVersion.h"
+#include <QStringList>
-class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion
+struct LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion
{
- Q_OBJECT
+ // From InstVersion:
+ /*
+ QString m_descriptor;
+ QString m_name;
+ qint64 m_timestamp;
+ */
-public:
- explicit MinecraftVersion(QString descriptor,
- QString name,
- qint64 timestamp,
- QString dlUrl,
- QString etag,
- InstVersionList *parent = 0);
-
- static InstVersion *mcnVersion(QString rawName, QString niceName);
+ /// The URL that this version will be downloaded from. maybe.
+ QString download_url;
+ /// This version's type. Used internally to identify what kind of version this is.
enum VersionType
{
- OldSnapshot,
- Stable,
- CurrentStable,
- Snapshot,
+ OneSix,
+ Legacy,
Nostalgia
- };
-
- 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);
+ } type;
- virtual QString downloadURL() const;
- virtual QString etag() const;
+ /// is this the latest version?
+ bool is_latest = false;
- virtual InstVersion *copyVersion(InstVersionList *newParent) const;
+ /// is this a snapshot?
+ bool is_snapshot = false;
-private:
- /// The URL that this version will be downloaded from. maybe.
- QString m_dlUrl;
-
- /// ETag/MD5 Used to verify the integrity of the downloaded minecraft.jar.
- QString m_etag;
-
- /// This version's type. Used internally to identify what kind of version this is.
- VersionType m_type;
+ virtual QString typeString() const
+ {
+ QStringList pre_final;
+ if(is_latest == true)
+ {
+ pre_final.append("Latest");
+ }
+ switch (type)
+ {
+ case OneSix:
+ pre_final.append("OneSix");
+ break;
+ case Legacy:
+ pre_final.append("Legacy");
+ break;
+ case Nostalgia:
+ pre_final.append("Nostalgia");
+ break;
+
+ default:
+ pre_final.append(QString("Type(%1)").arg(type));
+ break;
+ }
+ if(is_snapshot == true)
+ {
+ pre_final.append("Snapshot");
+ }
+ return pre_final.join(' ');
+ }
};
diff --git a/backend/NostalgiaInstance.cpp b/backend/NostalgiaInstance.cpp
new file mode 100644
index 00000000..0a7f3c5a
--- /dev/null
+++ b/backend/NostalgiaInstance.cpp
@@ -0,0 +1,12 @@
+#include "NostalgiaInstance.h"
+
+NostalgiaInstance::NostalgiaInstance ( const QString& rootDir, SettingsObject* settings, QObject* parent )
+ : OneSixInstance ( rootDir, settings, parent )
+{
+
+}
+
+/*
+ADD MORE
+ IF REQUIRED
+*/
diff --git a/backend/NostalgiaInstance.h b/backend/NostalgiaInstance.h
new file mode 100644
index 00000000..7c48713b
--- /dev/null
+++ b/backend/NostalgiaInstance.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "OneSixInstance.h"
+
+class LIBMULTIMC_EXPORT NostalgiaInstance : public OneSixInstance
+{
+ Q_OBJECT
+public:
+ explicit NostalgiaInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0);
+};
diff --git a/backend/OneSixUpdate.cpp b/backend/OneSixUpdate.cpp
index db15c923..5506d9aa 100644
--- a/backend/OneSixUpdate.cpp
+++ b/backend/OneSixUpdate.cpp
@@ -39,7 +39,7 @@ void OneSixUpdate::executeTask()
{
QString intendedVersion = m_inst->intendedVersionId();
// Get a pointer to the version object that corresponds to the instance's version.
- targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().findVersion(intendedVersion);
+ targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>();
if(targetVersion == nullptr)
{
// don't do anything if it was invalid
@@ -62,7 +62,7 @@ void OneSixUpdate::versionFileStart()
setStatus("Getting the version files from Mojang.");
QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
- urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json";
+ urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".json";
auto dljob = DownloadJob::create(QUrl(urlstr));
specificVersionDownloadJob.reset(new JobList());
specificVersionDownloadJob->add(dljob);
@@ -77,7 +77,7 @@ void OneSixUpdate::versionFileFinished()
JobPtr firstJob = specificVersionDownloadJob->getFirstJob();
auto DlJob = firstJob.dynamicCast<DownloadJob>();
- QString version_id = targetVersion->descriptor();
+ QString version_id = targetVersion->descriptor;
QString inst_dir = m_inst->rootDir();
// save the version file in $instanceId/version.json
{
diff --git a/backend/OneSixUpdate.h b/backend/OneSixUpdate.h
index 31aed8ba..bab2d335 100644
--- a/backend/OneSixUpdate.h
+++ b/backend/OneSixUpdate.h
@@ -50,7 +50,7 @@ private:
JobListQueue download_queue;
// target version, determined during this task
- MinecraftVersion *targetVersion;
+ QSharedPointer<MinecraftVersion> targetVersion;
};
diff --git a/backend/OneSixVersion.h b/backend/OneSixVersion.h
index 1f8090ab..e4f75542 100644
--- a/backend/OneSixVersion.h
+++ b/backend/OneSixVersion.h
@@ -181,12 +181,6 @@ public:
/// the list of libs - both active and inactive, native and java
QList<QSharedPointer<Library> > libraries;
- /**
- * is this actually a legacy version? if so, none of the other stuff here will be ever used.
- * added by FullVersionFactory
- */
- bool isLegacy;
-
/*
FIXME: add support for those rules here? Looks like a pile of quick hacks to me though.
@@ -211,7 +205,6 @@ public:
FullVersion()
{
minimumLauncherVersion = 0xDEADBEEF;
- isLegacy = false;
}
QList<QSharedPointer<Library> > getActiveNormalLibs();
diff --git a/backend/VersionFactory.cpp b/backend/VersionFactory.cpp
index a431ca26..9eccce26 100644
--- a/backend/VersionFactory.cpp
+++ b/backend/VersionFactory.cpp
@@ -49,10 +49,6 @@ QSharedPointer<FullVersion> FullVersionFactory::parse4(QJsonObject root, QShared
{
fullVersion->id = root.value("id").toString();
- // if it's on our legacy list, it's legacy
- if(legacyWhitelist.contains(fullVersion->id))
- fullVersion->isLegacy = true;
-
fullVersion->mainClass = root.value("mainClass").toString();
auto procArgsValue = root.value("processArguments");
if(procArgsValue.isString())
@@ -62,7 +58,6 @@ QSharedPointer<FullVersion> FullVersionFactory::parse4(QJsonObject root, QShared
if(toCompare == "legacy")
{
fullVersion->minecraftArguments = " ${auth_player_name} ${auth_session}";
- fullVersion->isLegacy = true;
}
else if(toCompare == "username_session")
{
@@ -83,11 +78,7 @@ QSharedPointer<FullVersion> FullVersionFactory::parse4(QJsonObject root, QShared
auto minecraftTypeValue = root.value("type");
if(minecraftTypeValue.isString())
{
- QString copy = fullVersion->type = minecraftTypeValue.toString();
- if(copy == "old_aplha" || copy == "old_beta")
- {
- fullVersion->isLegacy = true;
- }
+ fullVersion->type = minecraftTypeValue.toString();
}
fullVersion->releaseTime = root.value("releaseTime").toString();
@@ -117,7 +108,7 @@ QSharedPointer<FullVersion> FullVersionFactory::parse4(QJsonObject root, QShared
auto urlVal = libObj.value("url");
if(urlVal.isString())
{
- library->setBaseUrl(nameVal.toString());
+ library->setBaseUrl(urlVal.toString());
}
// Extract excludes (if any)
@@ -201,6 +192,4 @@ QSharedPointer<FullVersion> FullVersionFactory::parse(QByteArray data)
FullVersionFactory::FullVersionFactory()
{
m_error = FullVersionFactory::AllOK;
- legacyWhitelist.append("1.5.1");
- legacyWhitelist.append("1.5.2");
}
diff --git a/backend/VersionFactory.h b/backend/VersionFactory.h
index 60e5c983..82c5278a 100644
--- a/backend/VersionFactory.h
+++ b/backend/VersionFactory.h
@@ -21,5 +21,4 @@ public:
private:
QSharedPointer<FullVersion> parse4(QJsonObject root, QSharedPointer<FullVersion> product);
QList<QSharedPointer<Rule> > parse4rules(QJsonObject & baseObj);
- QStringList legacyWhitelist;
}; \ No newline at end of file
diff --git a/backend/lists/InstVersionList.cpp b/backend/lists/InstVersionList.cpp
index c65770a9..855fce45 100644
--- a/backend/lists/InstVersionList.cpp
+++ b/backend/lists/InstVersionList.cpp
@@ -21,20 +21,20 @@ InstVersionList::InstVersionList(QObject *parent) :
{
}
-const InstVersion *InstVersionList::findVersion(const QString &descriptor)
+InstVersionPtr InstVersionList::findVersion( const QString& descriptor )
{
for (int i = 0; i < count(); i++)
{
- if (at(i)->descriptor() == descriptor)
+ if (at(i)->descriptor == descriptor)
return at(i);
}
- return NULL;
+ return InstVersionPtr();
}
-const InstVersion *InstVersionList::getLatestStable() const
+InstVersionPtr InstVersionList::getLatestStable() const
{
if (count() <= 0)
- return NULL;
+ return InstVersionPtr();
else
return at(0);
}
@@ -48,7 +48,7 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
return QVariant();
- const InstVersion *version = at(index.row());
+ InstVersionPtr version = at(index.row());
switch (role)
{
@@ -56,23 +56,23 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
switch (index.column())
{
case NameColumn:
- return version->name();
+ return version->name;
case TypeColumn:
- return version->typeName();
+ return version->typeString();
case TimeColumn:
- return version->timestamp();
+ return version->timestamp;
default:
return QVariant();
}
case Qt::ToolTipRole:
- return version->descriptor();
+ return version->descriptor;
case VersionPointerRole:
- return qVariantFromValue((void *) version);
+ return qVariantFromValue(version);
default:
return QVariant();
diff --git a/backend/lists/InstVersionList.h b/backend/lists/InstVersionList.h
index 57965333..ff6938b4 100644
--- a/backend/lists/InstVersionList.h
+++ b/backend/lists/InstVersionList.h
@@ -18,10 +18,11 @@
#include <QObject>
#include <QVariant>
#include <QAbstractListModel>
+#include <QSharedPointer>
#include "libmmc_config.h"
+#include "InstanceVersion.h"
-class InstVersion;
class Task;
/*!
@@ -71,7 +72,7 @@ public:
virtual bool isLoaded() = 0;
//! Gets the version at the given index.
- virtual const InstVersion *at(int i) const = 0;
+ virtual const InstVersionPtr at(int i) const = 0;
//! Returns the number of versions in the list.
virtual int count() const = 0;
@@ -90,14 +91,14 @@ public:
* \return A const pointer to the version with the given descriptor. NULL if
* one doesn't exist.
*/
- virtual const InstVersion *findVersion(const QString &descriptor);
+ virtual InstVersionPtr findVersion(const QString &descriptor);
/*!
* \brief Gets the latest stable version of this instance type.
* This is the version that will be selected by default.
* By default, this is simply the first version in the list.
*/
- virtual const InstVersion *getLatestStable() const;
+ virtual InstVersionPtr getLatestStable() const;
/*!
* Sorts the version list.
@@ -117,5 +118,5 @@ protected slots:
* then copies the versions and sets their parents correctly.
* \param versions List of versions whose parents should be set.
*/
- virtual void updateListData(QList<InstVersion *> versions) = 0;
+ virtual void updateListData(QList<InstVersionPtr > versions) = 0;
};
diff --git a/backend/lists/MinecraftVersionList.cpp b/backend/lists/MinecraftVersionList.cpp
index ae28c46d..bf0406dc 100644
--- a/backend/lists/MinecraftVersionList.cpp
+++ b/backend/lists/MinecraftVersionList.cpp
@@ -52,7 +52,7 @@ bool MinecraftVersionList::isLoaded()
return m_loaded;
}
-const InstVersion *MinecraftVersionList::at(int i) const
+const InstVersionPtr MinecraftVersionList::at(int i) const
{
return m_vlist.at(i);
}
@@ -62,28 +62,11 @@ int MinecraftVersionList::count() const
return m_vlist.count();
}
-void MinecraftVersionList::printToStdOut() const
+bool cmpVersions(InstVersionPtr first, InstVersionPtr second)
{
- qDebug() << "---------------- Version List ----------------";
-
- for (int i = 0; i < m_vlist.count(); i++)
- {
- MinecraftVersion *version = qobject_cast<MinecraftVersion *>(m_vlist.at(i));
-
- if (!version)
- continue;
-
- qDebug() << "Version " << version->name();
- qDebug() << "\tDownload: " << version->downloadURL();
- qDebug() << "\tTimestamp: " << version->timestamp();
- qDebug() << "\tType: " << version->typeName();
- qDebug() << "----------------------------------------------";
- }
-}
-
-bool cmpVersions(const InstVersion *first, const InstVersion *second)
-{
- return !first->isLessThan(*second);
+ const InstVersion & left = *first;
+ const InstVersion & right = *second;
+ return left > right;
}
void MinecraftVersionList::sort()
@@ -93,16 +76,17 @@ void MinecraftVersionList::sort()
endResetModel();
}
-InstVersion *MinecraftVersionList::getLatestStable() const
+InstVersionPtr MinecraftVersionList::getLatestStable() const
{
for (int i = 0; i < m_vlist.length(); i++)
{
- if (((MinecraftVersion *)m_vlist.at(i))->versionType() == MinecraftVersion::CurrentStable)
+ auto ver = m_vlist.at(i).dynamicCast<MinecraftVersion>();
+ if (ver->is_latest && !ver->is_snapshot)
{
return m_vlist.at(i);
}
}
- return NULL;
+ return InstVersionPtr();
}
MinecraftVersionList &MinecraftVersionList::getMainList()
@@ -110,32 +94,12 @@ MinecraftVersionList &MinecraftVersionList::getMainList()
return mcVList;
}
-void MinecraftVersionList::updateListData(QList<InstVersion *> versions)
+void MinecraftVersionList::updateListData(QList<InstVersionPtr > versions)
{
- // First, we populate a temporary list with the copies of the versions.
- QList<InstVersion *> tempList;
- for (int i = 0; i < versions.length(); i++)
- {
- InstVersion *version = versions[i]->copyVersion(this);
- Q_ASSERT(version != NULL);
- tempList.append(version);
- }
-
- // Now we swap the temporary list into the actual version list.
- // This applies our changes to the version list immediately and still gives us
- // access to the old version list so that we can delete the objects in it and
- // free their memory. By doing this, we cause the version list to update as
- // quickly as possible.
beginResetModel();
- m_vlist.swap(tempList);
+ m_vlist = versions;
m_loaded = true;
endResetModel();
-
- // We called swap, so all the data that was in the version list previously is now in
- // tempList (and vice-versa). Now we just free the memory.
- while (!tempList.isEmpty())
- delete tempList.takeFirst();
-
// NOW SORT!!
sort();
}
@@ -160,6 +124,25 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
m_list = vlist;
m_currentStable = NULL;
vlistReply = nullptr;
+ legacyWhitelist.insert("1.5.2");
+ legacyWhitelist.insert("1.5.1");
+ legacyWhitelist.insert("1.5");
+ legacyWhitelist.insert("1.4.7");
+ legacyWhitelist.insert("1.4.6");
+ legacyWhitelist.insert("1.4.5");
+ legacyWhitelist.insert("1.4.4");
+ legacyWhitelist.insert("1.4.2");
+ legacyWhitelist.insert("1.3.2");
+ legacyWhitelist.insert("1.3.1");
+ legacyWhitelist.insert("1.2.5");
+ legacyWhitelist.insert("1.2.4");
+ legacyWhitelist.insert("1.2.3");
+ legacyWhitelist.insert("1.2.2");
+ legacyWhitelist.insert("1.2.1");
+ legacyWhitelist.insert("1.1");
+ legacyWhitelist.insert("1.0.1");
+ legacyWhitelist.insert("1.0.0");
+ // TODO: consider adding betas here too (whatever the legacy launcher supports)
}
MCVListLoadTask::~MCVListLoadTask()
@@ -232,8 +215,12 @@ void MCVListLoadTask::list_downloaded()
}
QJsonArray versions = root.value("versions").toArray();
+ QList<InstVersionPtr > tempList;
for (int i = 0; i < versions.count(); i++)
{
+ bool is_snapshot = false;
+ bool is_latest = false;
+
// Load the version info.
if(!versions[i].isObject())
{
@@ -257,50 +244,53 @@ void MCVListLoadTask::list_downloaded()
//FIXME: log this somewhere
continue;
}
-
// Parse the type.
MinecraftVersion::VersionType versionType;
+ // OneSix or Legacy. use filter to determine type
if (versionTypeStr == "release")
{
- // Check if this version is the current stable version.
- if (versionID == latestReleaseID)
- versionType = MinecraftVersion::CurrentStable;
- else
- versionType = MinecraftVersion::Stable;
+ versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix;
+ is_latest = (versionID == latestReleaseID);
+ is_snapshot = false;
}
- else if(versionTypeStr == "snapshot")
+ else if(versionTypeStr == "snapshot") // It's a snapshot... yay
{
- versionType = MinecraftVersion::Snapshot;
+ versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix;
+ is_latest = (versionID == latestSnapshotID);
+ is_snapshot = true;
}
- else if(versionTypeStr == "old_beta" || versionTypeStr == "old_alpha")
+ else if(versionTypeStr == "old_alpha")
{
versionType = MinecraftVersion::Nostalgia;
+ is_latest = false;
+ is_snapshot = false;
+ }
+ else if(versionTypeStr == "old_beta")
+ {
+ versionType = MinecraftVersion::Legacy;
+ is_latest = false;
+ is_snapshot = false;
}
else
{
//FIXME: log this somewhere
continue;
}
-
- //FIXME: detect if snapshots are old or not
-
// Get the download URL.
QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/";
// Now, we construct the version object and add it to the list.
- MinecraftVersion *mcVersion = new MinecraftVersion(versionID, versionID, versionTime.toMSecsSinceEpoch(),dlUrl, "");
- mcVersion->setVersionType(versionType);
+ QSharedPointer<MinecraftVersion> mcVersion(new MinecraftVersion());
+ mcVersion->name = mcVersion->descriptor = versionID;
+ mcVersion->timestamp = versionTime.toMSecsSinceEpoch();
+ mcVersion->download_url = dlUrl;
+ mcVersion->is_latest = is_latest;
+ mcVersion->is_snapshot = is_snapshot;
+ mcVersion->type = versionType;
tempList.append(mcVersion);
}
m_list->updateListData(tempList);
- // Once that's finished, we can delete the versions in our temp list.
- while (!tempList.isEmpty())
- delete tempList.takeFirst();
-
-#ifdef PRINT_VERSIONS
- m_list->printToStdOut();
-#endif
emitSucceeded();
return;
}
diff --git a/backend/lists/MinecraftVersionList.h b/backend/lists/MinecraftVersionList.h
index 8707016a..d3b18691 100644
--- a/backend/lists/MinecraftVersionList.h
+++ b/backend/lists/MinecraftVersionList.h
@@ -17,6 +17,8 @@
#include <QObject>
#include <QList>
+#include <QSet>
+#include <QSharedPointer>
#include "InstVersionList.h"
#include "tasks/Task.h"
@@ -36,12 +38,11 @@ public:
virtual Task *getLoadTask();
virtual bool isLoaded();
- virtual const InstVersion *at(int i) const;
+ virtual const InstVersionPtr at(int i) const;
virtual int count() const;
- virtual void printToStdOut() const;
virtual void sort();
- virtual InstVersion *getLatestStable() const;
+ virtual InstVersionPtr getLatestStable() const;
/*!
* Gets the main version list instance.
@@ -50,12 +51,12 @@ public:
protected:
- QList<InstVersion *>m_vlist;
+ QList<InstVersionPtr > m_vlist;
bool m_loaded;
protected slots:
- virtual void updateListData(QList<InstVersion *> versions);
+ virtual void updateListData(QList<InstVersionPtr > versions);
};
class MCVListLoadTask : public Task
@@ -76,10 +77,8 @@ protected:
bool loadFromVList();
QNetworkReply *vlistReply;
-
MinecraftVersionList *m_list;
- QList<InstVersion *> tempList; //! < List of loaded versions
-
MinecraftVersion *m_currentStable;
+ QSet<QString> legacyWhitelist;
};
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index bed2b35f..6187de93 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -534,7 +534,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered()
VersionSelectDialog vselect(inst->versionList(), this);
if (vselect.exec() && vselect.selectedVersion())
{
- inst->setIntendedVersionId(vselect.selectedVersion()->descriptor());
+ inst->setIntendedVersionId(vselect.selectedVersion()->descriptor);
}
}
diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp
index 38fbc2e3..4f19e9a2 100644
--- a/gui/newinstancedialog.cpp
+++ b/gui/newinstancedialog.cpp
@@ -37,8 +37,6 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewInstanceDialog)
{
- m_selectedVersion = NULL;
-
ui->setupUi(this);
resize(minimumSizeHint());
layout()->setSizeConstraint(QLayout::SetFixedSize);
@@ -64,17 +62,16 @@ NewInstanceDialog::~NewInstanceDialog()
void NewInstanceDialog::updateDialogState()
{
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
- !instName().isEmpty() && m_selectedVersion);
+ ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty() && m_selectedVersion);
}
-void NewInstanceDialog::setSelectedVersion(const InstVersion *version)
+void NewInstanceDialog::setSelectedVersion(InstVersionPtr version)
{
m_selectedVersion = version;
if (m_selectedVersion)
{
- ui->versionTextBox->setText(version->name());
+ ui->versionTextBox->setText(version->name);
}
else
{
@@ -94,7 +91,7 @@ QString NewInstanceDialog::iconKey() const
return InstIconKey;
}
-const InstVersion *NewInstanceDialog::selectedVersion() const
+InstVersionPtr NewInstanceDialog::selectedVersion() const
{
return m_selectedVersion;
}
@@ -105,7 +102,7 @@ void NewInstanceDialog::on_btnChangeVersion_clicked()
vselect.exec();
if (vselect.result() == QDialog::Accepted)
{
- const InstVersion *version = vselect.selectedVersion();
+ InstVersionPtr version = vselect.selectedVersion();
if (version)
setSelectedVersion(version);
}
diff --git a/gui/newinstancedialog.h b/gui/newinstancedialog.h
index 3e99c76a..07267e19 100644
--- a/gui/newinstancedialog.h
+++ b/gui/newinstancedialog.h
@@ -17,9 +17,7 @@
#define NEWINSTANCEDIALOG_H
#include <QDialog>
-
-class InstanceTypeInterface;
-class InstVersion;
+#include "InstanceVersion.h"
namespace Ui {
class NewInstanceDialog;
@@ -35,13 +33,13 @@ public:
void updateDialogState();
- void setSelectedVersion(const InstVersion *version);
+ void setSelectedVersion(InstVersionPtr version);
void loadVersionList();
QString instName() const;
QString iconKey() const;
- const InstVersion *selectedVersion() const;
+ InstVersionPtr selectedVersion() const;
private slots:
void on_btnChangeVersion_clicked();
@@ -51,7 +49,7 @@ private slots:
private:
Ui::NewInstanceDialog *ui;
- const InstVersion *m_selectedVersion;
+ InstVersionPtr m_selectedVersion;
QString InstIconKey;
};
diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp
index b3a14db1..33aedc71 100644
--- a/gui/versionselectdialog.cpp
+++ b/gui/versionselectdialog.cpp
@@ -68,13 +68,11 @@ void VersionSelectDialog::loadList()
taskDlg->exec(loadTask);
}
-const InstVersion *VersionSelectDialog::selectedVersion() const
+InstVersionPtr VersionSelectDialog::selectedVersion() const
{
- const InstVersion *versionPtr = (const InstVersion *)
- m_proxyModel->data(ui->listView->selectionModel()->currentIndex(),
- InstVersionList::VersionPointerRole).value<void *>();
-
- return versionPtr;
+ auto currentIndex = ui->listView->selectionModel()->currentIndex();
+ auto variant = m_proxyModel->data(currentIndex, InstVersionList::VersionPointerRole);
+ return variant.value<InstVersionPtr>();
}
void VersionSelectDialog::on_refreshButton_clicked()
diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h
index 0f45d8e5..752c937b 100644
--- a/gui/versionselectdialog.h
+++ b/gui/versionselectdialog.h
@@ -19,9 +19,9 @@
#include <QDialog>
#include <QSortFilterProxyModel>
+#include <InstanceVersion.h>
class InstVersionList;
-class InstVersion;
namespace Ui
{
@@ -41,7 +41,7 @@ public:
//! Starts a task that loads the list.
void loadList();
- const InstVersion *selectedVersion() const;
+ InstVersionPtr selectedVersion() const;
private slots:
void on_refreshButton_clicked();
diff --git a/gui/versionselectdialog.ui b/gui/versionselectdialog.ui
index 5cb0ebad..02937794 100644
--- a/gui/versionselectdialog.ui
+++ b/gui/versionselectdialog.ui
@@ -19,6 +19,9 @@
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>