summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-09-16 00:54:39 +0200
committerPetr Mrázek <peterix@gmail.com>2013-09-16 00:54:39 +0200
commitd38b90530b3ba3a49c4eb072eb344ae2b0836913 (patch)
tree5dd07e59ae1bc8392a773ec8fec6b6a3aa7e4840 /logic
parent7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5 (diff)
downloadMultiMC-d38b90530b3ba3a49c4eb072eb344ae2b0836913.tar
MultiMC-d38b90530b3ba3a49c4eb072eb344ae2b0836913.tar.gz
MultiMC-d38b90530b3ba3a49c4eb072eb344ae2b0836913.tar.lz
MultiMC-d38b90530b3ba3a49c4eb072eb344ae2b0836913.tar.xz
MultiMC-d38b90530b3ba3a49c4eb072eb344ae2b0836913.zip
Forge version list implementation. Needs integration and testing.
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseInstance.cpp5
-rw-r--r--logic/BaseInstance.h4
-rw-r--r--logic/BaseVersion.h (renamed from logic/InstanceVersion.h)43
-rw-r--r--logic/EnabledItemFilter.cpp30
-rw-r--r--logic/EnabledItemFilter.h16
-rw-r--r--logic/InstanceFactory.cpp10
-rw-r--r--logic/InstanceFactory.h6
-rw-r--r--logic/LegacyUpdate.cpp8
-rw-r--r--logic/MinecraftVersion.h29
-rw-r--r--logic/OneSixInstance.cpp21
-rw-r--r--logic/OneSixInstance.h2
-rw-r--r--logic/OneSixLibrary.cpp13
-rw-r--r--logic/OneSixLibrary.h22
-rw-r--r--logic/OneSixUpdate.cpp47
-rw-r--r--logic/OneSixVersion.cpp71
-rw-r--r--logic/OneSixVersion.h11
-rw-r--r--logic/lists/BaseVersionList.cpp (renamed from logic/lists/InstVersionList.cpp)36
-rw-r--r--logic/lists/BaseVersionList.h (renamed from logic/lists/InstVersionList.h)14
-rw-r--r--logic/lists/ForgeVersionList.cpp200
-rw-r--r--logic/lists/ForgeVersionList.h98
-rw-r--r--logic/lists/LwjglVersionList.cpp8
-rw-r--r--logic/lists/LwjglVersionList.h2
-rw-r--r--logic/lists/MinecraftVersionList.cpp34
-rw-r--r--logic/lists/MinecraftVersionList.h21
24 files changed, 597 insertions, 154 deletions
diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp
index e166449f..10bb4573 100644
--- a/logic/BaseInstance.cpp
+++ b/logic/BaseInstance.cpp
@@ -13,6 +13,7 @@
* limitations under the License.
*/
+#include "MultiMC.h"
#include "BaseInstance.h"
#include "BaseInstance_p.h"
@@ -131,9 +132,9 @@ InstanceList *BaseInstance::instList() const
return NULL;
}
-InstVersionList *BaseInstance::versionList() const
+BaseVersionList *BaseInstance::versionList() const
{
- return &MinecraftVersionList::getMainList();
+ return MMC->minecraftlist();
}
SettingsObject &BaseInstance::settings() const
diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h
index cc9422be..fa317ba1 100644
--- a/logic/BaseInstance.h
+++ b/logic/BaseInstance.h
@@ -21,7 +21,7 @@
#include <settingsobject.h>
#include "inifile.h"
-#include "lists/InstVersionList.h"
+#include "lists/BaseVersionList.h"
class QDialog;
class BaseUpdate;
@@ -134,7 +134,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;
+ virtual BaseVersionList *versionList() const;
/*!
* \brief Gets this instance's settings object.
diff --git a/logic/InstanceVersion.h b/logic/BaseVersion.h
index eecd9c4e..be717fee 100644
--- a/logic/InstanceVersion.h
+++ b/logic/BaseVersion.h
@@ -19,50 +19,27 @@
/*!
* An abstract base class for versions.
*/
-struct InstVersion
+struct BaseVersion
{
/*!
- * 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 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 operator>( const InstVersion& rhs ) const
- {
- return timestamp > rhs.timestamp;
- }
-
- /*!
* A string used to identify this version in config files.
* This should be unique within the version list or shenanigans will occur.
*/
- QString descriptor;
+ virtual QString descriptor() = 0;
+
/*!
* The name of this version as it is displayed to the user.
* For example: "1.5.1"
*/
- QString name;
+ virtual QString name() = 0;
+
/*!
- * Gets the version's timestamp.
- * This is primarily used for sorting versions in a list.
+ * This should return a string that describes
+ * the kind of version this is (Stable, Beta, Snapshot, whatever)
*/
- qint64 timestamp;
-
- virtual QString typeString() const
- {
- return "InstVersion";
- }
+ virtual QString typeString() const = 0;
};
-typedef QSharedPointer<InstVersion> InstVersionPtr;
+typedef QSharedPointer<BaseVersion> BaseVersionPtr;
-Q_DECLARE_METATYPE( InstVersionPtr ) \ No newline at end of file
+Q_DECLARE_METATYPE( BaseVersionPtr ) \ No newline at end of file
diff --git a/logic/EnabledItemFilter.cpp b/logic/EnabledItemFilter.cpp
new file mode 100644
index 00000000..6ecd0271
--- /dev/null
+++ b/logic/EnabledItemFilter.cpp
@@ -0,0 +1,30 @@
+#include "EnabledItemFilter.h"
+
+EnabledItemFilter::EnabledItemFilter(QObject* parent)
+ :QSortFilterProxyModel(parent)
+{
+
+}
+
+void EnabledItemFilter::setActive(bool active)
+{
+ m_active = active;
+ invalidateFilter();
+}
+
+bool EnabledItemFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ if(!m_active)
+ return true;
+ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+ if(sourceModel()->flags(index) & Qt::ItemIsEnabled)
+ {
+ return true;
+ }
+ return false;
+}
+
+bool EnabledItemFilter::lessThan(const QModelIndex& left, const QModelIndex& right) const
+{
+ return QSortFilterProxyModel::lessThan(left, right);
+}
diff --git a/logic/EnabledItemFilter.h b/logic/EnabledItemFilter.h
new file mode 100644
index 00000000..cb6d4041
--- /dev/null
+++ b/logic/EnabledItemFilter.h
@@ -0,0 +1,16 @@
+#pragma once
+#include <QSortFilterProxyModel>
+
+class EnabledItemFilter : public QSortFilterProxyModel
+{
+ Q_OBJECT
+public:
+ EnabledItemFilter(QObject *parent = 0);
+ void setActive(bool active);
+
+protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+private:
+ bool m_active = false;
+}; \ No newline at end of file
diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp
index f0630568..b5832ce5 100644
--- a/logic/InstanceFactory.cpp
+++ b/logic/InstanceFactory.cpp
@@ -22,7 +22,7 @@
#include "LegacyInstance.h"
#include "OneSixInstance.h"
#include "NostalgiaInstance.h"
-#include "InstanceVersion.h"
+#include "BaseVersion.h"
#include "MinecraftVersion.h"
#include "inifile.h"
@@ -68,7 +68,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst
}
-InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, InstVersionPtr version, const QString& instDir )
+InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, BaseVersionPtr version, const QString& instDir )
{
QDir rootDir(instDir);
@@ -89,19 +89,19 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*&
case MinecraftVersion::Legacy:
m_settings->set("InstanceType", "Legacy");
inst = new LegacyInstance(instDir, m_settings, this);
- inst->setIntendedVersionId(version->descriptor);
+ inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false);
break;
case MinecraftVersion::OneSix:
m_settings->set("InstanceType", "OneSix");
inst = new OneSixInstance(instDir, m_settings, this);
- inst->setIntendedVersionId(version->descriptor);
+ inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false);
break;
case MinecraftVersion::Nostalgia:
m_settings->set("InstanceType", "Nostalgia");
inst = new NostalgiaInstance(instDir, m_settings, this);
- inst->setIntendedVersionId(version->descriptor);
+ inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false);
break;
default:
diff --git a/logic/InstanceFactory.h b/logic/InstanceFactory.h
index ed54f520..1c527749 100644
--- a/logic/InstanceFactory.h
+++ b/logic/InstanceFactory.h
@@ -19,9 +19,9 @@
#include <QMap>
#include <QList>
-#include "InstanceVersion.h"
+#include "BaseVersion.h"
-class InstVersion;
+class BaseVersion;
class BaseInstance;
/*!
@@ -61,7 +61,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, InstVersionPtr version, const QString &instDir);
+ InstCreateError createInstance(BaseInstance *&inst, BaseVersionPtr version, const QString &instDir);
/*!
* \brief Loads an instance from the given directory.
diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp
index b8e179a5..25be5e7d 100644
--- a/logic/LegacyUpdate.cpp
+++ b/logic/LegacyUpdate.cpp
@@ -34,15 +34,15 @@ void LegacyUpdate::lwjglStart()
return;
}
- auto &list = LWJGLVersionList::get();
- if(!list.isLoaded())
+ auto list = MMC->lwjgllist();
+ if(!list->isLoaded())
{
emitFailed("Too soon! Let the LWJGL list load :)");
return;
}
setStatus("Downloading new LWJGL.");
- auto version = list.getVersion(lwjglVersion);
+ auto version = list->getVersion(lwjglVersion);
if(!version)
{
emitFailed("Game update failed: the selected LWJGL version is invalid.");
@@ -170,7 +170,7 @@ void LegacyUpdate::extractLwjgl()
if (name.contains(nativesDir))
{
int lastSlash = name.lastIndexOf('/');
- int lastBackSlash = name.lastIndexOf('/');
+ int lastBackSlash = name.lastIndexOf('\\');
if(lastSlash != -1)
name = name.mid(lastSlash+1);
else if(lastBackSlash != -1)
diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h
index 27977262..53c2f5ef 100644
--- a/logic/MinecraftVersion.h
+++ b/logic/MinecraftVersion.h
@@ -15,17 +15,16 @@
#pragma once
-#include "InstanceVersion.h"
+#include "BaseVersion.h"
#include <QStringList>
-struct MinecraftVersion : public InstVersion
+struct MinecraftVersion : public BaseVersion
{
- // From InstVersion:
- /*
- QString m_descriptor;
- QString m_name;
- qint64 m_timestamp;
- */
+ /*!
+ * Gets the version's timestamp.
+ * This is primarily used for sorting versions in a list.
+ */
+ qint64 timestamp;
/// The URL that this version will be downloaded from. maybe.
QString download_url;
@@ -44,6 +43,20 @@ struct MinecraftVersion : public InstVersion
/// is this a snapshot?
bool is_snapshot = false;
+ QString m_name;
+
+ QString m_descriptor;
+
+ virtual QString descriptor()
+ {
+ return m_descriptor;
+ }
+
+ virtual QString name()
+ {
+ return m_name;
+ }
+
virtual QString typeString() const
{
QStringList pre_final;
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index c926df60..7b038c46 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -214,6 +214,13 @@ bool OneSixInstance::shouldUpdate() const
return true;
}
+bool OneSixInstance::versionIsCustom()
+{
+ QString verpath_custom = PathCombine(instanceRoot(), "custom.json");
+ QFile versionfile(verpath_custom);
+ return versionfile.exists();
+}
+
QString OneSixInstance::currentVersionId() const
{
return intendedVersionId();
@@ -224,6 +231,13 @@ bool OneSixInstance::reloadFullVersion()
I_D(OneSixInstance);
QString verpath = PathCombine(instanceRoot(), "version.json");
+ {
+ QString verpath_custom = PathCombine(instanceRoot(), "custom.json");
+ QFile versionfile(verpath_custom);
+ if(versionfile.exists())
+ verpath = verpath_custom;
+ }
+
QFile versionfile(verpath);
if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly))
{
@@ -264,7 +278,12 @@ bool OneSixInstance::menuActionEnabled ( QString action_name ) const
QString OneSixInstance::getStatusbarDescription()
{
- return "One Six : " + intendedVersionId();
+ QString descr = "One Six : " + intendedVersionId();
+ if(versionIsCustom())
+ {
+ descr + " (custom)";
+ }
+ return descr;
}
QString OneSixInstance::loaderModsDir() const
diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h
index a4c67ed1..72bde630 100644
--- a/logic/OneSixInstance.h
+++ b/logic/OneSixInstance.h
@@ -41,6 +41,8 @@ public:
bool reloadFullVersion();
/// get the current full version info
QSharedPointer<OneSixVersion> getFullVersion();
+ /// is the current version original, or custom?
+ bool versionIsCustom();
virtual QString defaultBaseJar() const;
virtual QString defaultCustomBaseJar() const;
diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp
index a109a7f0..a45a4aec 100644
--- a/logic/OneSixLibrary.cpp
+++ b/logic/OneSixLibrary.cpp
@@ -1,12 +1,13 @@
#include "OneSixLibrary.h"
#include "OneSixRule.h"
-
+#include "OpSys.h"
void OneSixLibrary::finalize()
{
QStringList parts = m_name.split ( ':' );
QString relative = parts[0];
relative.replace ( '.','/' );
relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2];
+
if ( !m_is_native )
relative += ".jar";
else
@@ -21,9 +22,12 @@ void OneSixLibrary::finalize()
relative += ".jar";
}
}
+
+ m_decentname = parts[1];
+ m_decentversion = parts[2];
m_storage_path = relative;
m_download_path = m_base_url + relative;
-
+
if ( m_rules.empty() )
{
m_is_active = true;
@@ -42,6 +46,11 @@ void OneSixLibrary::finalize()
if ( m_is_native )
{
m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem );
+ m_decenttype = "Native";
+ }
+ else
+ {
+ m_decenttype = "Java";
}
}
diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h
index 856e409c..ac16d3d3 100644
--- a/logic/OneSixLibrary.h
+++ b/logic/OneSixLibrary.h
@@ -16,6 +16,12 @@ private:
QList<QSharedPointer<Rule> > m_rules;
// derived values used for real things
+ /// a decent name fit for display
+ QString m_decentname;
+ /// a decent version fit for display
+ QString m_decentversion;
+ /// a decent type fit for display
+ QString m_decenttype;
/// where to store the lib locally
QString m_storage_path;
/// where to download the lib from
@@ -48,8 +54,24 @@ public:
/// Set the library composite name
void setName(QString name);
+ /// get a decent-looking name
+ QString name()
+ {
+ return m_decentname;
+ }
+ /// get a decent-looking version
+ QString version()
+ {
+ return m_decentversion;
+ }
+ /// what kind of library is it? (for display)
+ QString type()
+ {
+ return m_decenttype;
+ }
/// Set the url base for downloads
void setBaseUrl(QString base_url);
+
/// Call this to mark the library as 'native' (it's a zip archive with DLLs)
void setIsNative();
/// Attach a name suffix to the specified OS native
diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp
index a58a9626..67395818 100644
--- a/logic/OneSixUpdate.cpp
+++ b/logic/OneSixUpdate.cpp
@@ -49,7 +49,7 @@ void OneSixUpdate::executeTask()
}
// Get a pointer to the version object that corresponds to the instance's version.
- targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>();
+ targetVersion = MMC->minecraftlist()->findVersion(intendedVersion).dynamicCast<MinecraftVersion>();
if(targetVersion == nullptr)
{
// don't do anything if it was invalid
@@ -72,7 +72,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 job = new DownloadJob("Version index");
job->add(QUrl(urlstr));
specificVersionDownloadJob.reset(job);
@@ -85,31 +85,46 @@ void OneSixUpdate::versionFileStart()
void OneSixUpdate::versionFileFinished()
{
DownloadPtr DlJob = specificVersionDownloadJob->first();
+ OneSixInstance * inst = (OneSixInstance *) m_inst;
- QString version_id = targetVersion->descriptor;
+ QString version_id = targetVersion->descriptor();
QString inst_dir = m_inst->instanceRoot();
// save the version file in $instanceId/version.json
{
QString version1 = PathCombine(inst_dir, "/version.json");
ensureFilePathExists(version1);
// FIXME: detect errors here, download to a temp file, swap
- QFile vfile1 (version1);
- vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly );
- vfile1.write(DlJob.dynamicCast<ByteArrayDownload>()->m_data);
- vfile1.close();
+ QSaveFile vfile1 (version1);
+ if(!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly ))
+ {
+ emitFailed("Can't open " + version1 + " for writing.");
+ return;
+ }
+ auto data = DlJob.dynamicCast<ByteArrayDownload>()->m_data;
+ qint64 actual = 0;
+ if((actual = vfile1.write(data)) != data.size())
+ {
+ emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " + data.size() + '.');
+ return;
+ }
+ if(!vfile1.commit())
+ {
+ emitFailed("Can't commit changes to " + version1);
+ return;
+ }
}
// the version is downloaded safely. update is 'done' at this point
m_inst->setShouldUpdate(false);
- // save the version file in versions/$version/$version.json
- /*
- //QString version2 = QString("versions/") + version_id + "/" + version_id + ".json";
- //ensurePathExists(version2);
- //QFile vfile2 (version2);
- //vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly );
- //vfile2.write(DlJob->m_data);
- //vfile2.close();
- */
+
+ // delete any custom version inside the instance (it's no longer relevant, we did an update)
+ QString custom = PathCombine(inst_dir, "/custom.json");
+ QFile finfo(custom);
+ if(finfo.exists())
+ {
+ finfo.remove();
+ }
+ inst->reloadFullVersion();
jarlibStart();
}
diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp
index 7ffe9a94..dc1b5d6f 100644
--- a/logic/OneSixVersion.cpp
+++ b/logic/OneSixVersion.cpp
@@ -28,3 +28,74 @@ QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNativeLibs()
}
+QVariant OneSixVersion::data(const QModelIndex& index, int role) const
+{
+ if(!index.isValid())
+ return QVariant();
+
+ int row = index.row();
+ int column = index.column();
+
+ if(row < 0 || row >= libraries.size())
+ return QVariant();
+
+ if(role == Qt::DisplayRole)
+ {
+ switch(column)
+ {
+ case 0:
+ return libraries[row]->name();
+ case 1:
+ return libraries[row]->type();
+ case 2:
+ return libraries[row]->version();
+ default:
+ return QVariant();
+ }
+ }
+ return QVariant();
+}
+
+Qt::ItemFlags OneSixVersion::flags(const QModelIndex& index) const
+{
+ if(!index.isValid())
+ return Qt::NoItemFlags;
+ int row = index.row();
+ if(libraries[row]->isActive())
+ {
+ return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren;
+ }
+ else
+ {
+ return Qt::ItemNeverHasChildren;
+ }
+ //return QAbstractListModel::flags(index);
+}
+
+
+QVariant OneSixVersion::headerData ( int section, Qt::Orientation orientation, int role ) const
+{
+ if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
+ return QVariant();
+ switch (section)
+ {
+ case 0:
+ return QString("Name");
+ case 1:
+ return QString("Type");
+ case 2:
+ return QString("Version");
+ default:
+ return QString();
+ }
+}
+
+int OneSixVersion::rowCount(const QModelIndex& parent) const
+{
+ return libraries.size();
+}
+
+int OneSixVersion::columnCount(const QModelIndex& parent) const
+{
+ return 3;
+}
diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h
index 8f01f82d..6a6a5b4b 100644
--- a/logic/OneSixVersion.h
+++ b/logic/OneSixVersion.h
@@ -2,9 +2,15 @@
#include <QtCore>
class OneSixLibrary;
-class OneSixVersion
+class OneSixVersion : public QAbstractListModel
{
public:
+ virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
+ virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
+ virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
+ virtual int columnCount ( const QModelIndex& parent ) const;
+ virtual Qt::ItemFlags flags(const QModelIndex& index) const;
+public:
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
QString id;
/// Last updated time - as a string
@@ -58,6 +64,7 @@ public:
// QList<Rule> rules;
public:
+
OneSixVersion()
{
minimumLauncherVersion = 0xDEADBEEF;
@@ -65,4 +72,4 @@ public:
QList<QSharedPointer<OneSixLibrary> > getActiveNormalLibs();
QList<QSharedPointer<OneSixLibrary> > getActiveNativeLibs();
-}; \ No newline at end of file
+};
diff --git a/logic/lists/InstVersionList.cpp b/logic/lists/BaseVersionList.cpp
index 7dc67155..61da5eeb 100644
--- a/logic/lists/InstVersionList.cpp
+++ b/logic/lists/BaseVersionList.cpp
@@ -13,33 +13,33 @@
* limitations under the License.
*/
-#include "logic/lists/InstVersionList.h"
-#include "logic/InstanceVersion.h"
+#include "logic/lists/BaseVersionList.h"
+#include "logic/BaseVersion.h"
-InstVersionList::InstVersionList(QObject *parent) :
+BaseVersionList::BaseVersionList(QObject *parent) :
QAbstractListModel(parent)
{
}
-InstVersionPtr InstVersionList::findVersion( const QString& descriptor )
+BaseVersionPtr BaseVersionList::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 InstVersionPtr();
+ return BaseVersionPtr();
}
-InstVersionPtr InstVersionList::getLatestStable() const
+BaseVersionPtr BaseVersionList::getLatestStable() const
{
if (count() <= 0)
- return InstVersionPtr();
+ return BaseVersionPtr();
else
return at(0);
}
-QVariant InstVersionList::data(const QModelIndex &index, int role) const
+QVariant BaseVersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
@@ -48,7 +48,7 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
return QVariant();
- InstVersionPtr version = at(index.row());
+ BaseVersionPtr version = at(index.row());
switch (role)
{
@@ -56,20 +56,17 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
switch (index.column())
{
case NameColumn:
- return version->name;
+ return version->name();
case TypeColumn:
return version->typeString();
- case TimeColumn:
- return version->timestamp;
-
default:
return QVariant();
}
case Qt::ToolTipRole:
- return version->descriptor;
+ return version->descriptor();
case VersionPointerRole:
return qVariantFromValue(version);
@@ -79,7 +76,7 @@ QVariant InstVersionList::data(const QModelIndex &index, int role) const
}
}
-QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, int role) const
+QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, int role) const
{
switch (role)
{
@@ -91,9 +88,6 @@ QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, i
case TypeColumn:
return "Type";
-
- case TimeColumn:
- return "Time";
default:
return QVariant();
@@ -117,13 +111,13 @@ QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, i
}
}
-int InstVersionList::rowCount(const QModelIndex &parent) const
+int BaseVersionList::rowCount(const QModelIndex &parent) const
{
// Return count
return count();
}
-int InstVersionList::columnCount(const QModelIndex &parent) const
+int BaseVersionList::columnCount(const QModelIndex &parent) const
{
return 2;
}
diff --git a/logic/lists/InstVersionList.h b/logic/lists/BaseVersionList.h
index bc6aa5d4..d37431ed 100644
--- a/logic/lists/InstVersionList.h
+++ b/logic/lists/BaseVersionList.h
@@ -20,7 +20,7 @@
#include <QAbstractListModel>
#include <QSharedPointer>
-#include "logic/InstanceVersion.h"
+#include "logic/BaseVersion.h"
class Task;
@@ -36,7 +36,7 @@ class Task;
* all have a default implementation, but they can be overridden by plugins to
* change the behavior of the list.
*/
-class InstVersionList : public QAbstractListModel
+class BaseVersionList : public QAbstractListModel
{
Q_OBJECT
public:
@@ -57,7 +57,7 @@ public:
TimeColumn
};
- explicit InstVersionList(QObject *parent = 0);
+ explicit BaseVersionList(QObject *parent = 0);
/*!
* \brief Gets a task that will reload the version list.
@@ -71,7 +71,7 @@ public:
virtual bool isLoaded() = 0;
//! Gets the version at the given index.
- virtual const InstVersionPtr at(int i) const = 0;
+ virtual const BaseVersionPtr at(int i) const = 0;
//! Returns the number of versions in the list.
virtual int count() const = 0;
@@ -90,14 +90,14 @@ public:
* \return A const pointer to the version with the given descriptor. NULL if
* one doesn't exist.
*/
- virtual InstVersionPtr findVersion(const QString &descriptor);
+ virtual BaseVersionPtr 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 InstVersionPtr getLatestStable() const;
+ virtual BaseVersionPtr getLatestStable() const;
/*!
* Sorts the version list.
@@ -117,5 +117,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<InstVersionPtr > versions) = 0;
+ virtual void updateListData(QList<BaseVersionPtr > versions) = 0;
};
diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp
new file mode 100644
index 00000000..f45b8b6b
--- /dev/null
+++ b/logic/lists/ForgeVersionList.cpp
@@ -0,0 +1,200 @@
+/* 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 "ForgeVersionList.h"
+#include <logic/net/DownloadJob.h>
+#include "MultiMC.h"
+
+#include <QtNetwork>
+
+#include <QtXml>
+
+#include <QRegExp>
+
+#define JSON_URL "http://files.minecraftforge.net/minecraftforge/json"
+
+
+ForgeVersionList::ForgeVersionList(QObject* parent): BaseVersionList(parent)
+{
+
+}
+
+Task *ForgeVersionList::getLoadTask()
+{
+ return new ForgeListLoadTask(this);
+}
+
+bool ForgeVersionList::isLoaded()
+{
+ return m_loaded;
+}
+
+const BaseVersionPtr ForgeVersionList::at(int i) const
+{
+ return m_vlist.at(i);
+}
+
+int ForgeVersionList::count() const
+{
+ return m_vlist.count();
+}
+/*
+bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
+{
+ const BaseVersion & left = *first;
+ const BaseVersion & right = *second;
+ return left > right;
+}
+
+void MinecraftVersionList::sort()
+{
+ beginResetModel();
+ qSort(m_vlist.begin(), m_vlist.end(), cmpVersions);
+ endResetModel();
+}
+*/
+BaseVersionPtr ForgeVersionList::getLatestStable() const
+{
+ return BaseVersionPtr();
+}
+
+void ForgeVersionList::updateListData(QList<BaseVersionPtr > versions)
+{
+ beginResetModel();
+ m_vlist = versions;
+ m_loaded = true;
+ endResetModel();
+ // NOW SORT!!
+ // sort();
+}
+
+void ForgeVersionList::sort()
+{
+ // NO-OP for now
+}
+
+
+ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList* vlist): Task()
+{
+ m_list = vlist;
+}
+
+
+void ForgeListLoadTask::executeTask()
+{
+ auto job = new DownloadJob("Version index");
+ job->add(QUrl(JSON_URL));
+ listJob.reset(job);
+ connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded()));
+ connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
+ connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ listJob->start();
+}
+
+void ForgeListLoadTask::list_downloaded()
+{
+ auto DlJob = listJob->first();
+ auto data = DlJob.dynamicCast<ByteArrayDownload>()->m_data;
+
+
+ QJsonParseError jsonError;
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
+ DlJob.reset();
+
+ if (jsonError.error != QJsonParseError::NoError)
+ {
+ emitFailed("Error parsing version list JSON:" + jsonError.errorString());
+ return;
+ }
+
+ if(!jsonDoc.isObject())
+ {
+ emitFailed("Error parsing version list JSON: jsonDoc is not an object");
+ return;
+ }
+
+ QJsonObject root = jsonDoc.object();
+
+ // Now, get the array of versions.
+ if(!root.value("builds").isArray())
+ {
+ emitFailed("Error parsing version list JSON: version list object is missing 'builds' array");
+ return;
+ }
+ QJsonArray builds = root.value("builds").toArray();
+
+ QList<BaseVersionPtr > tempList;
+ for (int i = 0; i < builds.count(); i++)
+ {
+ // Load the version info.
+ if(!builds[i].isObject())
+ {
+ //FIXME: log this somewhere
+ continue;
+ }
+ QJsonObject obj = builds[i].toObject();
+ int build_nr = obj.value("build").toDouble(0);
+ if(!build_nr)
+ continue;
+ QJsonArray files = root.value("files").toArray();
+ QString url, jobbuildver, mcver, buildtype, filename;
+ QString changelog_url, installer_url;
+ bool valid = false;
+ for(int j = 0; j < files.count(); j++)
+ {
+ if(!files[j].isObject())
+ continue;
+ QJsonObject file = files[j].toObject();
+ buildtype = file.value("buildtype").toString();
+ if((buildtype == "client" || buildtype == "universal") && !valid)
+ {
+ mcver = file.value("mcver").toString();
+ url = file.value("url").toString();
+ jobbuildver = file.value("jobbuildver").toString();
+ int lastSlash = url.lastIndexOf('/');
+ filename = url.mid(lastSlash+1);
+ valid = true;
+ }
+ else if(buildtype == "changelog")
+ {
+ QString ext = file.value("ext").toString();
+ if(ext.isEmpty())
+ continue;
+ changelog_url = file.value("url").toString();
+ }
+ else if(buildtype == "installer")
+ {
+ installer_url = file.value("url").toString();
+ }
+ }
+ if(valid)
+ {
+ // Now, we construct the version object and add it to the list.
+ QSharedPointer<ForgeVersion> fVersion(new ForgeVersion());
+ fVersion->universal_url = url;
+ fVersion->changelog_url = changelog_url;
+ fVersion->installer_url = installer_url;
+ fVersion->jobbuildver = jobbuildver;
+ fVersion->mcver = mcver;
+ fVersion->filename = filename;
+ fVersion->m_buildnr = build_nr;
+ tempList.append(fVersion);
+ }
+ }
+ m_list->updateListData(tempList);
+
+ emitSucceeded();
+ return;
+}
diff --git a/logic/lists/ForgeVersionList.h b/logic/lists/ForgeVersionList.h
new file mode 100644
index 00000000..8d4a2d46
--- /dev/null
+++ b/logic/lists/ForgeVersionList.h
@@ -0,0 +1,98 @@
+/* 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.
+ */
+
+#pragma once
+
+#include <QObject>
+#include <QAbstractListModel>
+#include <QSharedPointer>
+#include <QUrl>
+
+#include <QNetworkReply>
+#include "BaseVersionList.h"
+#include "logic/tasks/Task.h"
+#include "logic/net/DownloadJob.h"
+
+class ForgeVersion;
+typedef QSharedPointer<ForgeVersion> PtrForgeVersion;
+
+struct ForgeVersion : public BaseVersion
+{
+ virtual QString descriptor()
+ {
+ return filename;
+ };
+ virtual QString name()
+ {
+ return "Forge " + jobbuildver + " (" + mcver + ")";
+ };
+ virtual QString typeString() const
+ {
+ if(installer_url.isEmpty())
+ return "Universal";
+ else
+ return "Installer";
+ };
+
+ int m_buildnr = 0;
+ QString universal_url;
+ QString changelog_url;
+ QString installer_url;
+ QString jobbuildver;
+ QString mcver;
+ QString filename;
+};
+
+class ForgeVersionList : public BaseVersionList
+{
+ Q_OBJECT
+public:
+ friend class ForgeListLoadTask;
+
+ explicit ForgeVersionList(QObject *parent = 0);
+
+ virtual Task *getLoadTask();
+ virtual bool isLoaded();
+ virtual const BaseVersionPtr at(int i) const;
+ virtual int count() const;
+ virtual void sort();
+
+ virtual BaseVersionPtr getLatestStable() const;
+
+protected:
+ QList<BaseVersionPtr > m_vlist;
+
+ bool m_loaded;
+
+protected slots:
+ virtual void updateListData(QList<BaseVersionPtr > versions);
+};
+
+class ForgeListLoadTask : public Task
+{
+ Q_OBJECT
+
+public:
+ explicit ForgeListLoadTask(ForgeVersionList *vlist);
+
+ virtual void executeTask();
+
+protected slots:
+ void list_downloaded();
+
+protected:
+ DownloadJobPtr listJob;
+ ForgeVersionList *m_list;
+};
diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp
index d7826a82..b3e2dab4 100644
--- a/logic/lists/LwjglVersionList.cpp
+++ b/logic/lists/LwjglVersionList.cpp
@@ -24,14 +24,6 @@
#define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss"
-LWJGLVersionList mainVersionList;
-
-LWJGLVersionList &LWJGLVersionList::get()
-{
- return mainVersionList;
-}
-
-
LWJGLVersionList::LWJGLVersionList(QObject *parent) :
QAbstractListModel(parent)
{
diff --git a/logic/lists/LwjglVersionList.h b/logic/lists/LwjglVersionList.h
index 638a0b67..23e92a1a 100644
--- a/logic/lists/LwjglVersionList.h
+++ b/logic/lists/LwjglVersionList.h
@@ -53,8 +53,6 @@ class LWJGLVersionList : public QAbstractListModel
public:
explicit LWJGLVersionList(QObject *parent = 0);
- static LWJGLVersionList &get();
-
bool isLoaded() { return m_vlist.length() > 0; }
const PtrLWJGLVersion getVersion(const QString &versionName);
diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp
index 42fb1b50..86ba0792 100644
--- a/logic/lists/MinecraftVersionList.cpp
+++ b/logic/lists/MinecraftVersionList.cpp
@@ -34,10 +34,8 @@
#define ASSETS_URLBASE "http://assets.minecraft.net/"
#define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
-MinecraftVersionList mcVList;
-
MinecraftVersionList::MinecraftVersionList(QObject *parent) :
- InstVersionList(parent)
+ BaseVersionList(parent)
{
}
@@ -52,7 +50,7 @@ bool MinecraftVersionList::isLoaded()
return m_loaded;
}
-const InstVersionPtr MinecraftVersionList::at(int i) const
+const BaseVersionPtr MinecraftVersionList::at(int i) const
{
return m_vlist.at(i);
}
@@ -62,11 +60,11 @@ int MinecraftVersionList::count() const
return m_vlist.count();
}
-bool cmpVersions(InstVersionPtr first, InstVersionPtr second)
+bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
{
- const InstVersion & left = *first;
- const InstVersion & right = *second;
- return left > right;
+ auto left = first.dynamicCast<MinecraftVersion>();
+ auto right = second.dynamicCast<MinecraftVersion>();
+ return left->timestamp > right->timestamp;
}
void MinecraftVersionList::sort()
@@ -76,7 +74,7 @@ void MinecraftVersionList::sort()
endResetModel();
}
-InstVersionPtr MinecraftVersionList::getLatestStable() const
+BaseVersionPtr MinecraftVersionList::getLatestStable() const
{
for (int i = 0; i < m_vlist.length(); i++)
{
@@ -86,15 +84,10 @@ InstVersionPtr MinecraftVersionList::getLatestStable() const
return m_vlist.at(i);
}
}
- return InstVersionPtr();
-}
-
-MinecraftVersionList &MinecraftVersionList::getMainList()
-{
- return mcVList;
+ return BaseVersionPtr();
}
-void MinecraftVersionList::updateListData(QList<InstVersionPtr > versions)
+void MinecraftVersionList::updateListData(QList<BaseVersionPtr > versions)
{
beginResetModel();
m_vlist = versions;
@@ -214,7 +207,7 @@ void MCVListLoadTask::list_downloaded()
}
QJsonArray versions = root.value("versions").toArray();
- QList<InstVersionPtr > tempList;
+ QList<BaseVersionPtr > tempList;
for (int i = 0; i < versions.count(); i++)
{
bool is_snapshot = false;
@@ -280,7 +273,7 @@ void MCVListLoadTask::list_downloaded()
// Now, we construct the version object and add it to the list.
QSharedPointer<MinecraftVersion> mcVersion(new MinecraftVersion());
- mcVersion->name = mcVersion->descriptor = versionID;
+ mcVersion->m_name = mcVersion->m_descriptor = versionID;
mcVersion->timestamp = versionTime.toMSecsSinceEpoch();
mcVersion->download_url = dlUrl;
mcVersion->is_latest = is_latest;
@@ -293,8 +286,3 @@ void MCVListLoadTask::list_downloaded()
emitSucceeded();
return;
}
-
-// FIXME: we should have a local cache of the version list and a local cache of version data
-bool MCVListLoadTask::loadFromVList()
-{
-}
diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h
index 0477379f..8937ba7b 100644
--- a/logic/lists/MinecraftVersionList.h
+++ b/logic/lists/MinecraftVersionList.h
@@ -20,14 +20,14 @@
#include <QSet>
#include <QSharedPointer>
-#include "InstVersionList.h"
+#include "BaseVersionList.h"
#include "logic/tasks/Task.h"
#include "logic/MinecraftVersion.h"
class MCVListLoadTask;
class QNetworkReply;
-class MinecraftVersionList : public InstVersionList
+class MinecraftVersionList : public BaseVersionList
{
Q_OBJECT
public:
@@ -37,25 +37,19 @@ public:
virtual Task *getLoadTask();
virtual bool isLoaded();
- virtual const InstVersionPtr at(int i) const;
+ virtual const BaseVersionPtr at(int i) const;
virtual int count() const;
virtual void sort();
- virtual InstVersionPtr getLatestStable() const;
-
- /*!
- * Gets the main version list instance.
- */
- static MinecraftVersionList &getMainList();
-
+ virtual BaseVersionPtr getLatestStable() const;
protected:
- QList<InstVersionPtr > m_vlist;
+ QList<BaseVersionPtr> m_vlist;
bool m_loaded;
protected slots:
- virtual void updateListData(QList<InstVersionPtr > versions);
+ virtual void updateListData(QList<BaseVersionPtr > versions);
};
class MCVListLoadTask : public Task
@@ -72,9 +66,6 @@ protected slots:
void list_downloaded();
protected:
- //! Loads versions from Mojang's official version list.
- bool loadFromVList();
-
QNetworkReply *vlistReply;
MinecraftVersionList *m_list;
MinecraftVersion *m_currentStable;